1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Licemer1 [7]
3 years ago
11

Design and implement a class dayType that implements the day of the week in a program. The class dayType should store the day, s

uch as Sun for Sunday.
The program should be able to perform the following operations on an object of type dayType:

a) set the day
b) print the day
c) return the day
d) return the next day
e) return the previous day
f) 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 returned is Friday. similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.
g) add the appropriate constructors.

Write the definitions of the functions to implement the operations for the class dayType. Also write a program to test various operations on this class.
Computers and Technology
1 answer:
Afina-wow [57]3 years ago
4 0

The code is implemented based on the given operations.

Explanation:

#include <iostream>

#include <string>

using namespace std;

class dayType

{ private:

 string day[7];

 string presentDay;

 int numofDays;

public:

 void setDay(string freshDay);

 void printDay() const;

 int showDay(int &day);

 int nextDay(int day);

 int prevDay(int day) const;

 int calcDay(int day, int numofDays);    

 dayType()

 {

  day[0] = "Sunday";

  day[1] = "Monday";

  day[2] = "Tuesday";

  day[3] = "Wednesday";

  day[4] = "Thursday";

  day[5] = "Friday";

  day[6] = "Saturday";

  presentDay = day[0];

  numofDays = 0;

 };

 ~dayType();

};

#endif

#include "dayType.h"

void dayType::setDay(string freshDay)

{

  presentDay = freshDay;

}

void dayType::printDay()

{

  cout << "Day chosen is " << presentDay << endl;

}

int dayType::showDay(int& day)

{

  return day;

}

int dayType::nextDay(int day)

{

day = day++;

if (day > 6)

 day = day % 7;

switch (day)

{

case 0: cout << "The successive day is Sunday";

 break;

case 1: cout << "The successive day is Monday";

 break;

case 2: cout << "The successive day is Tuesday";

 break;

case 3: cout << "The successive day is Wednesday";

 break;

case 4: cout << "The successive day is Thursday";

 break;

case 5: cout << "The successive day is Friday";

 break;

case 6: cout << "The successive day is Saturday";

 break;

}

cout << endl;

return day;

}

 

int dayType::prevDay(int day)

{

day = day--;

switch (day)

{

case -1: cout << "The before day is Saturday.";

 break;

case 0: cout << "The before day is Saturday.";

 break;

case 1: cout << "The before day is Saturday.";

 break;

case 2: cout << "The before day is Saturday.";

 break;

case 3: cout << "The before day is Saturday.";

 break;

case 4: cout << "The before day is Saturday.";

 break;

case 5: cout << "The before day is Saturday.";

 break;

default: cout << "The before day is Saturday.";

}

cout << endl;

return day;

}

int dayType::calcDay(int addDays, int numofDays)

{

addDay = addDays + numofDays;

if (addDay > 6)

 addDay = addDay % 7;

switch(addDay)

{

case 0: cout << "The processed day is Sunday.";

 break;

case 1: cout << "The processedday is Monday.";

 break;

case 2: cout << "The processedday is Tuesday.";

 break;

case 3: cout << "The processedday is Wednesday.";

 break;

case 4: cout << "The processedday is Thursday.";

 break;

case 5: cout << "The processedday is Friday.";

 break;

case 6: cout << "The processedday is Saturday.";

 break;

default: cout << "Not valid choice.";

}

cout << endl;

return addDays;

}

You might be interested in
2. Name the type of product the United States used to<br> first enter the arena of technology.
skelet666 [1.2K]

Answer:

<u><em>please mark brainliest!</em></u>

Explanation:

Benjamin Franklin found and acquainted power (electricity) with the USA. He likewise had numerous different developments such the wood stove. Benjamin Franklin initially stunned himself in 1746, while leading examinations on power with discovered items from around his home. After six years and precisely 261 years back today, the establishing father flew a kite joined to a key and a silk lace in a storm and adequately caught lightning in a jug.

3 0
3 years ago
Samuel was hired to create a program that asks the user questions and, based on the answers, recommend a book to read. What kind
quester [9]

Answer:

I think the answer is C

Explanation:

Selection

3 0
3 years ago
Who do we make games for?(single term)
Ket [755]

Answer:

Gamers

Explanation:

5 0
3 years ago
Read 2 more answers
17. Write a SELECT query for the palateE4 database that produces a result grid listing paintName, and a count of the occurrences
GaryK [48]

Answer:

SELECT paintname, COUNT(paintname) as count_paintname

FROM paint

GROUP BY paintname HAVING COUNT(paintname) > 2

ORDER BY paintname

Explanation:

The structured query language or SQL statement returns two columns of paintname and the count of the distinct paint names in the paint table with rows of grouped paint names greater than two and in the ascending order of the names.

4 0
2 years ago
1.the following code example would print the data type of x, what data type would that be?
natta225 [31]

Answer:

x = 5, the data type is integer( integer data type is for whole numbers)

2. The data type is string

3. The data type is float (float data type is for decimals)

Explanation:

6 0
3 years ago
Other questions:
  • Candace opened an email from a person she didn't know and clicked on a pop-up in the email that installed a virus on her compute
    8·2 answers
  • Think about the five steps to writing an algorithm. Why is each step necessary? Why is it important to be precise when writing c
    15·1 answer
  • What type of program would you use to create a personal budget?
    9·1 answer
  • Why do we need vram​
    6·1 answer
  • For off campus work study positions, students should contact the
    6·1 answer
  • Zoom meeting ID:987 6858 5587 Password:196133
    10·2 answers
  • In java
    6·1 answer
  • Plz hurry it’s timed
    5·1 answer
  • When testing a game, why might you consider throttling the game’s “frames per second”?
    9·1 answer
  • Which of the following is NOT a method for applying the SDLC model?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!