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
Anna007 [38]
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 Sunday for Sunday. The program should be able to perform the following operations on an object of type dayType: Step a: Set the day. Step b: Print the day. Step c: Return the day. Step d: Return the next day. Step e: Return the previous day. Step 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. Step g: Add the appropriate constructors. Write the definitions of the functions to implement the operations for the class dayType.
Computers and Technology
1 answer:
olya-2409 [2.1K]3 years ago
8 0

#include<iostream>

#include<string>

usingnamespace std;

void menu(); //declartion of function to show the menu

classdayType//creating the class

{

      string Wdays[7];

      int i;

      string day;

      string prDay;

      string NxtDay;

      string AddDays;

public:

      dayType(string);//constructor with one parameter

      string setday(); //declartion of function to set the day

      string preday(); // declartion of function to find privious day

      void Nextday(); // declartion of function to find Next day

      string add(int n); // declartion of function to find after addingthenumber of days given by the user

      void print(); // declartion of function to print the result

};

int main()

{

      int n;

      string d;

      menu(); //displaying menu

      cout <<"Enter the day :";

      getline(cin, d); //Takes the day from the user

      dayType Da(d); //creating an object of a class

      Da.setday();

      Da.preday();

      Da.Nextday();

      cout <<"Enter the No. of days to add :";

      while (!(cin >> n) ||n<0) { //validation checking

                    cin.clear();

                    cin.ignore(999, '\n');

                    cout <<"Invalid data type! \nPlease enter No. of daysto add again :";

             

      }

      Da.add(n);

      Da.print();

      system("pause");

      return 0;

}

dayType::dayType(stringi) :day(i){ //Defintion of a constructor with one parameter

      Wdays[0] = "Mon";

      Wdays[1] = "Tues";

      Wdays[2] = "Wednes";

      Wdays[3] = "Thurs";

      Wdays[4] = "Fri";

      Wdays[5] = "Satur";

      Wdays[6] = "Sun";

}

stringdayType::setday() //Function to set the day

{

      if (day == Wdays[0])

      {

             i = 0;

      }

      elseif (day == Wdays[1])

      {

             i = 1;

      }

      elseif (day == Wdays[2])

      {

             i = 2;

      }

      elseif (day == Wdays[3])

      {

             i = 3;

      }

      elseif (day == Wdays[4])

      {

             i = 4;

      }

      elseif (day == Wdays[5])

      {

             i = 5;

      }

      elseif (day == Wdays[6])

             i = 6;

      else

      {

             day = "Invalid Input";

             i = 7;

      }

      return day;

}

stringdayType::preday() //Function to find the preivous day

{

      if (i == 0)

             prDay = Wdays[6];

      elseif (i == 7)

             prDay = "Invalid Input";

      else

             prDay = Wdays[i - 1];

      return prDay;

}

voiddayType::Nextday() //Function to find Next day

{

      if (i == 6)

             NxtDay = Wdays[0];

      elseif (i == 7)

             prDay = "Invalid Input";

      else

             NxtDay = Wdays[i + 1];

}

stringdayType::add(intn) // function to find after adding the number of days given by the user

{

      n = n + i;

      while (n>= 7)

      {

             n = n - 7;

      }

      if (i == 7)

             Wdays[n] = "Invalid Input ";

      return AddDays = Wdays[n];

}

voiddayType::print()

{

      cout << endl <<"\tDay="<< day <<"day"<< endl;

      cout <<"\tPrevious day :"<< prDay <<"day"<< endl;

      cout <<"\tNext day :"<< NxtDay <<"day"<< endl;

      cout <<"\tAfter Adding Days :"<< AddDays <<"day"<< endl;

}

void menu() //Function to display menu

{

      cout <<"******************MENU********************"<< endl;

      cout <<"\tEnter 'Sun' for 'Sunday'"<< endl;

      cout <<"\tEnter 'Mon' for 'Monday'"<< endl;

      cout <<"\tEnter 'Tues' for 'Tuesday'"<< endl;

      cout <<"\tEnter 'Wednes' for 'Wednesday'"<< endl;

      cout <<"\tEnter 'Thurs' for 'Thursday'"<< endl;

      cout <<"\tEnter 'Fri' for 'Friday'"<< endl;

      cout <<"\tEnter 'Satur' for 'Saturday'"<< endl;

You might be interested in
3 ᴍᴜʟᴛɪᴘʟᴇ-ᴄʜᴏɪᴄᴇ Qᴜᴇꜱᴛɪᴏɴꜱ
Damm [24]
4, 1, and 3

The last one I am going to say three because I know that friends show other friends so I wouldn’t call that “private”
6 0
2 years ago
1. Write a function that will ask the user to enter a value in dollars. The function should calculate and display the equivalent
julia-pushkina [17]

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

   

    valueInDollars();

}

   public static void valueInDollars() {

       double currentMoney, quarters, dimes, nickels, pennies;

       Scanner input = new Scanner(System.in);

       

       System.out.print("Enter a value in dollars: ");

       currentMoney = input.nextDouble();

       currentMoney *= 100;

       quarters = (int)currentMoney / 25;

       currentMoney = currentMoney % 25;

       

       dimes = (int)currentMoney / 10;

       currentMoney = currentMoney % 10;

       

       nickels = (int)currentMoney / 5;

       currentMoney = currentMoney % 5;

       

       pennies = currentMoney;

       

       System.out.print("Quarters: " + quarters + "\n" + "Dimes: " + dimes + "\n" + "Nickels: " + nickels + "\n" + "Pennies: " + pennies);

   }

}

Explanation:

<u>Inside the function:</u>

- Declare the variables

- Ask the user for a value in dollars

- Multiply that value by 100

- Find the amount of quarters, dimes, nickels, and pennies

- Print the values

<u>Inside the main:</u>

- Call the function

3 0
3 years ago
Which statements are true about making formatting changes to cells in Excel? (Select all that apply)
scoundrel [369]
I agree that it should have been and was a and b.
6 0
2 years ago
Well this isn't school related, but how do i watch dubbed and subbed anime for free on my computer?
Shtirlitz [24]
Crunchyroll or my anime list. Both of these work.

Hope this helps you

3 0
3 years ago
Read 2 more answers
Give a recursive version of the algorithm Insertion-Sort (refer to page 18 in the textbook) that works as follows: To sort A[1..
Inga [223]

Answer:

see explaination

Explanation:

void insertion( int e,int *x, int start, int end)

{

if (e >= x[end])

x[end+1] = e;

else if (start < end)

{

x[end+1] = x[end];

insertion(e, x, start, end-1);

}

else

{

x[end+1] = x[end];

x[end] = e;

}

}

void insertion_recurssion(int *b, int start, int end)

{

if(start < end)

{

insertion_sort_recur(b, start, end-1);

insertion(b[end], b, start, end-1);

}

}

void main()

{

insertion_recurssion(x,0,5);

}

3 0
2 years ago
Other questions:
  • How useful do you find the creation of folders in your computer?
    8·2 answers
  • A(n) ________ signal is a discrete, binary waveform that transmits data coded into two discrete states such as 1-bits and 0-bits
    12·1 answer
  • Amanda needs to create an informative print brochure for her local library’s fundraiser dinner. What critical detail must she ha
    14·2 answers
  • What type of font color should Kim select if she chooses a dark-colored design theme for her presentation?
    14·2 answers
  • You are running an art museum. There is a long hallway with k paintings on the wall. The locations of the paintings are l1, ...,
    13·1 answer
  • Select two netiquette guidelines. In three to five sentences, explain why these guidelines make professional online communicatio
    15·2 answers
  • How do you make the "Colorize" feature in GIMP consistent if you cannot connect the different places? Brainliest if you also exp
    12·2 answers
  • CORRECT ANSWER GETS BRAINLIEST
    8·2 answers
  • If you misspell a word in your Java program it may be true that I. the program will not compile II. the program may compile, but
    6·1 answer
  • What is output by the following code?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!