mohammad mohammad
classes in c++
1 Answer(s)      a year and 7 months ago
Posted in : Design concepts & design patterns

1- design and implement a class datatype that implement the day of the week in the program.the class datatype should store the day, such as sun for sunday. the programe should be able to perform the following operations on an object of type datatype set the day / print the day /return the day/return the next day /return the previous day/ calculate and return the day by adding certain days to the current day.for example if the current day is monday and we add 4 days .the day to be returnd is friday.similarly, if today is tuesday and we add 13 days, the day to be returned is monday/ add the oppropriate constructors.

2-write the definition of the function to implement the operations for the class datatype. alse write aprogram to test various operations on this class.

View Answers

October 19, 2011 at 4:48 PM


Here is the Java code:

public class DayType{
        final static int SUN = 0;
        final static int MON = 1;
        final static int TUE = 2;
        final static int WED = 3;
        final static int THU = 4;
        final static int FRI= 5;
        final static int SAT = 6;

        private int day;

        public DayType(int day) {
                this.day = day;
        }

        public void setDay(int day){
                this.day = day;
        }

        public int getDay() {
                return day;
        }

        public void print() {
                System.out.println(this.toString());
        }
        public int nextDay(){
                int next;
                next = day + 1;
                return next;
        }
        public int previousDay(){
                int prevDay;
                prevDay = day - 1;
                return prevDay;
        }
        public int addDays(int days) {
                return (day + days) % 7;
        }
                public String toString() {
                switch (this.day) {
                case SUN:
                        return "Sunday";
                case MON:
                        return "Monday";
                case TUE:
                        return "Tuesday";
                case WED:
                        return "Wednesday";
                case THU:
                        return "Thursday";
                case FRI:
                        return "Friday";
                case SAT:
                        return "Saturday";
                }
                return "";
        }       
        public static void main(String[] args) {
                System.out.println("******Test Day******");
                System.out.println();
                System.out.print("Set day: ");
                DayType d = new DayType(SUN);
                d.print();
                System.out.print("Next day: ");
                d.setDay(d.nextDay());
                d.print();
                System.out.print("Previous day: ");
                d.setDay(d.previousDay());
                d.print();
                System.out.print("After 5 days: ");
                d.setDay(d.addDays(5));
                d.print();
        }       
}









Related Pages:
classes in c++
classes in c++  1- design and implement a class datatype that implement the day of the week in the program.the class datatype should store the day, such as sun for sunday. the programe should be able to perform the following
C# question
Create a Solution by name Bank with Classes Account.cs, SavingsAccount.cs and savingsTest.cs to Demonstrate Abstract Classes in C#  1st question... and savingsTest.cs to Demonstrate Abstract Classes in C
Disassembling Java Classes - Java Tutorials
Disassembling Java Classes To Disassemble a class file in Java there is a tool... y) { return x * y; } } Now Compile the aboove class using javac C:\Java Test>javac DisassesmleExample.java Now run it using javap as C:\Java
C++Tutorials
C++ Tutorials              C++ Tutorial Namespaces are a relatively new C++ feature just now starting to appear in C
executing java program with 2 classes
containing more than one class....ex of program is given below.... class C { int x; int y; } class D { public static void main(String args[]) { C c1,c2; c1 = new C(); c2 = new C(); c1.x = 10; c1.y = 20; c2.x = 6; c2.y = 7
C++GraphicsTutorials
C++ Graphics Tutorials     ... in this document is correct. C/C++ Windows programmers who want to learn... MFC.      OpenIL in Dev-C++ OpenIL
Inner Nested Classes
Inner Nested Classes       Non-static nested classes are slightly different from static nested classes, a non-static nested class is actually associated
C and C++ books-page2
C and C++ books-page2       The Advice & Warning for C Tutorials  C and C++ are widely promoted as ideal portable, fast, and - in the case of C++ - "object
classes and data abstraction - Java Beginners
classes and data abstraction  Create a java program for a class named...); System.out.println("Please enter convert amount!"); int c = Integer.parseInt(buff.readLine()); ex.setConvert(c); System.out.println("doller type currency
C and C++ books-page3
a prototype language called ``C With Classes.'' In C++, one uses classes... C and C++ books-page3       C for C++ programmers Before there was C++ there was C
C and C++ books-page10
C and C++ books-page10       The programming language C As a programming language, C is rather.... Of the three languages, C allows the most precise control of input and output. C
Java Get classes In Package
Java Get classes In Package   ... the classes from the package by providing the path of the jar file and the package....   Following code adds all the classes of the package getting from the jar
C/C++ Programming Books
C/C++ Programming Books         Visual C++ 6 Unleashed Visual C++ 6 Unleashed provides comprehensive coverage of the core topics
c++ program of inheritance
c++ program of inheritance   Assume that a bank maintains two kinds.... From this derive the classes curacct and savacct to make them more specific.... (b) Display the balance (c) Compute and deposit interest. (d) Permit
Pattern,Matcher,Formatter and Scanner classes
. Character classes [abc] a, b, or c (simple class) [^abc...Pattern,Matcher,Formatter and Scanner classes This section Describes : 1... to format or parse strings or streams. 2. Uses of the Pattern and Matcher classes
C++ Question 2
C++ Triangle and Rectangle - calculate area of Triangle and rectangle using... (Data Type: Double). Create two derived classes Triangle and Rectangle ; calculate... "Shape" to represent two different derived classes Triangle and Rectangle. Each
C++
C++  How can i write this in dev c
C++
C++  How can i write this in dev c
NSString in objective c
NSString in objective c In this series of Iphone application development tutorials, we going to introduce you with some of the iphone basic classes and objects...that are used in objective C. NSString is one of them. Brief Introduction
Many Public Classes in One File - Java Tutorials
. Next we show the first approach of how we could now use classes A,B,C,etc...Many Public Classes in One File 2003-10-13 The Java Specialists' Newsletter [Issue 080] - Many Public Classes in One File Author: Dr. Heinz M. Kabutz
c++
c++  use a prgrm as an example to xplain-: a)class b)object c)message d)cope resolution operator
c++
c++  write a programme that calculates the area and circumference of a rectangle
c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used
c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used
c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used
C++
C++  dear sir How to create windows form application for login screen using C++? USER Name -TESTADMIN Password -testuser
c++
c++  differenciate btw.-a)local & public variables b)pre-defined & user defined functions c)fnctn prototype,defination & fnctn code.use code examples
c++
c++  differenciate btw.-a)local & public variables b)pre-defined & user defined functions c)fnctn prototype,defination & fnctn code.use code examples
C++
C++  differenciate btw.-a)local & public variables b)pre-defined & user defined functions c)fnctn prototype,defination & fnctn code.use code examples
c++
c++  write a prgrm tht accepts 3 integer values,then with a function to swap the values
C++
C++  Describe the principle advantages of deploying a linked list versus a static array when implementing a Queue or a Stack
C++
C++  I have been asked to write a programme that gets five values,gets the sum,average and product please help me
C#
C#  i need a code that will make program perform the basic operations upon the data Listview save, update and cancel
Java vs. C
the basis for Object Oriented Programming (OOP). Java classes are like C++ class... Java: Java vs. C Is Java easier or harder than C? Java is harder because ... Java is more powerful and can do much more than C. For example
c++
c++  write a program that gets a key or character from the keyboard and displays it ASII code in decimal, hexadecimal and binary form.It must also give a description of the key pressed
c++
c++  write a prgrm tht calculates the surface area of a cylinder.the prgrm shld find the circumfrance and have a function that calculates the fadius and another to calculate the surface area
C++
C++  write a prgrm tht gets five values,gets the sum,average &...; #include <conio.h> void main() { clrscr(); int a,b,c,d,e,sum; float average...;>b>>c>>d>>e; sum=a+b+c+d+e; average=sum/5; product=a*b*c*d
c++
c++  .write a program that accepts 5 subjects of a student,it should have a function to calculate the average & another function to grade.grade should be as follows-<40=E,40-49=D,50-59=C,60-69=B & >70
c++
c++  Consider the following function: int funcExercise7(int list[], int size) { int sum = 0; for (int index = 0; index < size; index++) sum = sum + list[index]; return sum
c++
c++  Consider the following declarations: class xClass { public: void... private members does class xClass have? c. How many constructors does class xClass.... Write a C++ statement that prints the values of the data members of the object
C#
C# register form  i want to generate a user id automatically after filling their register form and i want to show their id to their email? please reply me soon
c++
c++  Consider the following declarations: class xClass { public: void func(); void print() const; xClass (); xClass (int, double); private: int u... private members does class xClass have? c. How many constructors does class xClass
c++
c++  Write a console based C++ program that reads student information from a text file, build an array of objects of type class StudentInfo... name with the minimum GPA 7) Display Student GPAs as Letter Grades (A, B, C, D
c++
c++  Characterize the following algorithm in terms of Big-O notation. for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) for (int k = 1; k <= n; k++) cout << i + j + k
C++
C++  . Consider the definition of the following class: class CC { public: CC(); //Line 1 CC(int); //Line 2 CC(int, int); //Line 3 CC(double, int); //Line 4 . . . private: int u; double v
c++
c++  .write a prgrm tht accepts 5 subjects of a student,it shld hv a function to calculate the average & another function to grade.grade shld be as follows-<40=E,40-49=D,50-59=C,60-69=B & >70
c++
c++  Characterize the following algorithm in terms of Big-O notation. Also find the exact number of additions executed by the loop. (Assume that all variables are properly declared.) for (int i = 1; i <= n; i++) sum = sum + i
c++
c++  Write the definition of the class dayType that implements the day of the week in a program. The class dayType should store the day... on an object of type dayType: a. Set the day. b. Print the day. c. Return the day

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.