Question

In: Computer Science

CODE must using C++ language. Write the definition of the class dayTye that implements the day...

CODE must using C++ language.

Write the definition of the class dayTye that implements the day of the week in a program. The class dayType should store the day of the week as integer. The program should perform the following operations on an object of type dayType

1. set the day

2. display the day as a string - Sunday, ... Saturday

3. return the day as an integer

4. return the next as an integer

5. return the previous day as an integer

6. calculate and return the day by adding to or subtracting from the current day. For example, if the current day is Monday (1) and we add 4 days the day returned is Friday (5). If today is Tuesday (2) and we subtract 13 days the day returned is Wednesday (3).

7. Add the appropriate constructors, accessors, mutators, and custom methods .

Write a main function to test your class in its own file. Do not put any class file the file that contains the main function.

Write a cpp file and an h file for your class in two files.

Upload the 2 files and the 1 h file.

Solutions

Expert Solution

If you have any doubts, please give me comment...

#ifndef DAYTYPE_H

#define DAYTYPE_H

#include<iostream>

#include<cmath>

using namespace std;

class dayType{

    public:

        dayType();

        dayType(int day);

        void setDay(int d);

        int getDay() const;

        void display();

        int nextDay() const;

        int previousDay() const;

        int calculateDay(int days) const;

    private:

        int day;

};

#endif

dayType.cpp

#include "dayType.h"

dayType::dayType(){

    day = 0;

}

dayType::dayType(int day){

    this->day = day;

}

void dayType::setDay(int d){

    day = d;

}

int dayType::getDay() const{

    return day;

}

void dayType::display(){

    if(day==0)

        cout<<"Sunday";

    else if(day==1)

        cout<<"Monday";

    else if(day==2)

        cout<<"Tuesday";

    else if(day==3)

        cout<<"Wednesday";

    else if(day==4)

        cout<<"Thursday";

    else if(day==5)

        cout<<"Friday";

    else

        cout<<"Saturday";

}

int dayType::nextDay() const{

    return (day+1)%7;

}

int dayType::previousDay() const{

    return (7-day+1)%7;

}

int dayType::calculateDay(int days) const{

    if(days>0)

        return (day+days)%7;

    else{

        return (7-((int)(abs(day+days))%7))%7;

    }

}


main.cpp

#include<iostream>

#include "dayType.h"

using namespace std;

int main(){

    dayType d = dayType(1);

    cout<<"Day 1 :";

    d.display();

    cout<<endl;

    cout<<"Next Day to 1 is: "<<d.nextDay()<<endl;

    cout<<"Previous Day to 1 is: "<<d.previousDay()<<endl;

    cout<<"Calculate adding 4 days to day 1 is: "<<d.calculateDay(4)<<endl;

    cout<<"Setting day to 2"<<endl;

    d.setDay(2);

    cout<<"Today is ";

    d.display();

    cout<<endl;

    cout<<"Subtracting 13 days to day 2 is "<<d.calculateDay(-13)<<endl;

    return 0;

}


Related Solutions

Given the below pseudocode, write the proper code that implements it using MARIE's assembly language:               ...
Given the below pseudocode, write the proper code that implements it using MARIE's assembly language:                    Input a number and store it in X; if X > 1 then    Y := X + X;    X := 0; endif; Y := Y + 1; Output the value of Y; N.B: You should include the MARIE code in your Answer, with an explanation of each instruction in your code beside it. Example:              Subt One         /Subtract 1 from AC Add a...
Solve this Write a C++ class that implements a stack using a linked list. The type...
Solve this Write a C++ class that implements a stack using a linked list. The type of data contained in the stack should be double. The maximum size of the stack is 30. Implement the following methods: . · Constructor and destructor; // 5 pts · void push (double value); // pushes an element with the value into the stack. 5 pts. · double pop (); // pops an element from the stack and returns its value. 5 pts. ·...
Using basic C++( without using <Rectangle.h> ) Write the definition for a class called Rectangle that...
Using basic C++( without using <Rectangle.h> ) Write the definition for a class called Rectangle that has floating point data members length and width. The class has the following member functions: void setlength(float) to set the length data member void setwidth(float) to set the width data member float perimeter() to calculate and return the perimeter of the rectangle float area() to calculate and return the area of the rectangle void show() to display the length and width of the rectangle...
Write a java code for LinkedStack implementation and the code is: public final class LinkedStack<T> implements...
Write a java code for LinkedStack implementation and the code is: public final class LinkedStack<T> implements StackInterface<T> {    private Node topNode; // References the first node in the chain       public LinkedStack()    {        topNode = null;    } // end default constructor       public void push(T newEntry)    { topNode = new Node(newEntry, topNode); //       Node newNode = new Node(newEntry, topNode); //       topNode = newNode;    } // end push    public...
You must write the code in 80x86 assembly language and must attach a screenshot of the...
You must write the code in 80x86 assembly language and must attach a screenshot of the output. # Pennies for Pay Write a program that calculates how much a person earns in a month if the salary is one penny the first day, two pennies the second day, four pennies the third day, and so on with the daily pay doubling each day the employee works. The program should ask the user for the number of days the employee worked...
Using the singly linked list code as a base, create a class that implements a doubly...
Using the singly linked list code as a base, create a class that implements a doubly linked list. A doubly linked list has a Previous link so you can move backwards in the list. Be sure the class is a template class so the user can create a list with any data type. Be sure to test all the member functions in your test program. c++
Must be in C++ (beginners coding class) 8. a. Rewrite the definition of the class complexType...
Must be in C++ (beginners coding class) 8. a. Rewrite the definition of the class complexType so that the arith-metic and relational operators are overloaded as nonmember functions. b. Write the definitions of the member functions of the class complexType as designed in part a. c. Write a test program that tests various operations on the class complexType as designed in parts a and b. Format your answer with two decimal places. (additional info/problem ) does not need to be...
Write a MIPS assembly language program that implements the following pseudo-code operation: result = x +...
Write a MIPS assembly language program that implements the following pseudo-code operation: result = x + y – z + A[j] x and y should be in reserved memory words using the .word directive and labeled as x and y. Initialize x=10 and y=200. Read in z from the console. Input the value -8. This is the value for z, not for –z. Store this value in memory with the label z. To begin, you could just initialize z to...
Code in python: Write a class that implements a struct. In your struct store Student information...
Code in python: Write a class that implements a struct. In your struct store Student information such as name, netid, and gpa. Write a function that can access a student in a list of 5 structs by netid and print their name and gpa. Show that your function works by calling it.
C++ code Write a program to illustrate how to use the temporary class. Your program must...
C++ code Write a program to illustrate how to use the temporary class. Your program must contain statements that would ask the user to enter data of an object and use the setters to initialize the object. Use three header files named main.cpp, temporary.h, and temporaryImp.cpp An example of the program is shown below: Enter object name (rectangle, circle, sphere, or cylinder: circle Enter object's dimensions: rectangle (length and width) circle (radius and 0) sphere (radius and 0) rectangle (base...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT