Question:
how can I Write a program in C++ named nameOfDay() that returns one of the strings,?
Richard Komlah
2009-11-02 03:45:31 UTC
Write a C++ named nameOfDay() that returns one of the strings, Sunday, Mondays, Tuesday, Wednesday, Thursday, Friday, or Saturday depending on the integer value passed into the method. The corresponding is that if a 1 is passed into the method, the method returns Sunday, a 2 causes the string Monday to be returned, and so on. The header line for this method is

Your program should request for m, n and r. r cannot be 0
Four answers:
2009-11-02 07:48:49 UTC
Hm....



















string nameOfDay() {return "tomorrow";}

string nameOfDay(int n) {

string day[7] ={"Sunday",

"Mondays",

"Tuesday",

"Wednesday",

"Thursday",

"Friday",

"Saturday" };

return (n>0 ? day[(n-1) % 7] : nameOfDay()); }



and whois m, n, & r != 0
2009-11-02 05:12:57 UTC
What are m, n, and r?



I'm guessing since r cannot be 0 that that is the int that you are corresponding to the day?



You could make a vector of strings day_of_week size 7



pseudo code:



day_of_week.at(0) = "sunday";

day_of_week.at(1) = "monday";

day_of_week.at(2) = "tuesday";

day_of_week.at(3) = "wednesday";

day_of_week.at(4) = "thursday";

day_of_week.at(5) = "friday";

day_of_week.at(6) = "saturday";

if(r=0) throw exception

else

return day_of_week.at(r-1);
no1home2day
2009-11-02 03:52:06 UTC
You asked "How can I write a program ... "



To write a program - this, or any other, you first need to break your problem down into simpler steps, and continue breaking these simpler steps into even more simple steps, until you are able to convert the steps into the language, whether C, Visual Basic, or Java - it's all the same methodology.



So, what is it you're trying to do? How would you do it manually (with pen and paper)? Break that down into simpler steps. Keep going with it, and then start using C++ instruction codes to accomplish these simplified tasks.
?
2016-12-14 09:31:27 UTC
only upload a scanf assertion for the 'call' variable and you will desire to be ok. #contain #contain #contain #contain //This software helps a internet reservation //for for the Montana lodge int important() { char call[c0c7c76d30bd3dcaefc96f40275bdcac0c7c76d30bd3dcaefc96f40275bdca]; // an array of chars int lodging = a million; printf("Welcome to the worldwide widespread lodge Montana!!n"); printf("inspect our warm summer season costs commencing at then"); printf("following expenditures, in accordance with room classification: n"); printf("$119 Weekday,$139 Weekend...OneBR Deluxe n"); printf("$139 Weekday,$1c0c7c76d30bd3dcaefc96f40275bdca9 Weekend...OneBR more advantageous n"); printf("$189 Weekday,$2c0c7c76d30bd3dcaefc96f40275bdca9 Weekend...OneBR Grande n"); printf("$1c0c7c76d30bd3dcaefc96f40275bdca9 Weekday,$179 Weekend...TwoBR Deluxe n"); printf("$179 Weekday,$199 Weekend...TwoBR more advantageous n"); printf("$229 Weekday,$249 Weekend...TwoBR Grande n"); printf("$199 Weekday,$219 Weekend...ThreeBR Deluxe n"); printf("$219 Weekday,$239 Weekend...ThreeBR more advantageous n"); printf("All expenditures are such as taxes n"); //declare style of weekdays and nunber of weekends int num_of_weekdays,num_of_weekends; printf("Please enter your call: n",call); scanf("%s", call); printf("How long do you propose to stay: n"); printf("Please enter the kind of weekdays: n"); scanf("%d",&num_of_weekdays); printf("Please enter the kind of weekends: n"); scanf("%d",&num_of_weekends); //ask the centred visitor to go into the needed lodging printf("Please enter the huge style to your needed lodging(a million:OneBRDel,2:OneBRSup,3:On... scanf("%d", &lodging); change (lodging) { case a million: printf("you chosen the OneBRDel n"); ruin; case 2: printf("you chosen the OneBRSup n"); ruin; case 3: printf("you chosen the OneBRGr n"); ruin; case 4: printf ("you chosen the TwoBRDel n"); ruin ; case 50 : printf("you chosen the TwoBRSup n"); ruin; case 6 : printf("you chosen the TwoBRGr n"); ruin; case 7 : printf("you chosen the ThreeBRDel n"); ruin; case 8: printf("you chosen the ThreeBRSup n"); ruin; default: printf("Sorry, you entered a incorrect huge style.Please attempt back. n"); } return 50; //declare style of weekdays and nunber of weekends //Ask the customer to go into the lenght of his/her stay printf("How long do you propose to stay: n",(num_of_weekdays,num_of_weekends)); printf("Please enter the kind of weekdays: n"); scanf("%d",&num_of_weekdays); printf("Please enter the kind of weekends: n"); scanf("%d",&num_of_weekends); getchar(); }


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...