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
Who still plays old Nintendo 64 games?
Lesechka [4]

Answer:

I play Nintendo 64 games when I was young. I use to love playing Mario 64 as well.

8 0
2 years ago
Read 2 more answers
What US agency originally started ARPANET?
RUDIKE [14]
<span>c. Department of Advanced Research Projects Agency</span>
8 0
3 years ago
What is Communication​
iVinArrow [24]
Computer communications describes a process in which two or more computers or devices transfer data, instructions, and information. ... A sending device that initiates an instruction to transmit data, instructions, or information. A communications device that connects the sending device to a communications channel.
3 0
3 years ago
How many times can a simulation be repeated?
Vinvika [58]

Answer:

Explanation:

A general idea is that you should repeat the simulation until the results converge. An easy but illustrative example of this is that we want to see if the R function rbinom is accurate in simulating a coin toss with a given probability. We will simulate one coin toss 10000 times, and plot the percentage of heads against the number of coin tosses:

set.seed(1)

n <- 10000

result <- NULL

percent <- NULL

for (i in 1:n) {

 result[i] <- rbinom(1,1,0.5)

 percent[i] <- sum(result)/i

}

plot(seq(1:10000),percent, type="l")

abline(0.5, 0, lty=2)

5 0
3 years ago
Which of the following is an open-source program that implements MapReduce?
Ivahew [28]

Answer:

Apache Hadoop.

Explanation:

Apache Hadoop is a open source program that uses map reduce programming process to allocate storage and processing of big data computation. It uses a network of computers, distributing and processing large data, for parallel computation.

The Apache Hadoop has two main parts, the Hadoop distributed file system and the MapReduce model. The Hadoop distributed file system divides large chunks of data into clusters and pass them to the MapReduce model, where they are separated to similar data types.

3 0
3 years ago
Read 2 more answers
Other questions:
  • When molten igneous material intrudes into rock _____ metamorphism can occur.
    7·1 answer
  • Which of the following is a reason why the comments tool within PDF documents could be helpful? (Select all that apply.)
    5·1 answer
  • Jason is creating a web page for his school's basketball team. He just finished creating his storyboard. Which tool should he us
    6·2 answers
  • Given a String variable named sentence that has been initialized, write an expression whose value is the number of characters in
    13·1 answer
  • I have to write this in Java, but i've never even learned it before and i'm completely lost
    12·1 answer
  • Create the code that will find
    11·1 answer
  • The gene form of a trait is called a(n) ​
    10·1 answer
  • Which cable would you check if you can't access any web pages?
    12·1 answer
  • Translation of a file into a coded Format that occupies less space than the original file is called
    6·1 answer
  • Why the internet is not considered a mass medium in Africa​
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!