Home > Back-end >  Rookie again... O bosses solve, thank!!!!! It is quite urgent, thank you!
Rookie again... O bosses solve, thank!!!!! It is quite urgent, thank you!

Time:10-04

In 2, define a used to represent a class called the Month, specific requirements are as follows:
(1) private data members:
Int mon: used to represent in value (in February said in January 1, 2, and so on)
(2) public member functions:
In the Month (string Mon) : use English name (the first three letters) to set the value in the
The Month (int n) : with the integer n to set the value in the
Void the show () : output function, according to the data members mon output value (integer) in the English words
The Month next () : returns the next Month
(3) in the main function in the validation of all the members of the class function,
And (the related. H file. CPP file into ex2 folder)
Thank you very much!

CodePudding user response:

Fundamental questions yourself

Have a problem after writing the code to post questions

CodePudding user response:

Fun
reference 1 floor response:
basic problem yourself

Have a problem after writing the code to post questions

Ok, the problem was the Month next () function

CodePudding user response:

Fun
reference 1 floor response:
basic problem yourself

Have a problem after writing the code to post questions

#include #include using namespace std; The class the Month {private: int mon; Public: the Month (string Mon); The Month (int n); Void the show (); The Month next (); }; #include #include # include "class h" using namespace STD. The Month: the Month (string STR) {do {the if (STR=="Jan") {mon=1; break; } the if (STR=="Feb") {mon=2; break; } the if (STR=="Mar") {mon=3; break; } the if (STR=="Apr") {mon=4; break; } the if (STR=="May") {mon=5; break; } the if (STR=="Jun") {mon=6; break; } the if (STR=="Jul") {mon=7; break; } the if (STR=="Aug") {mon=8; break; } the if (STR=="Sep") {mon=9; break; } the if (STR=="Oct") {mon=10; break; } the if (STR=="Nov") {mon=11; break; } the if (STR=="Dec") {mon=12; break; } cout & lt; <"Input error! Please input again: "& lt; STR; } the while (1); {} the Month: the Month (int n) do {if (n & gt;=1 & amp; & n <12)={mon=n; break; } else {cout & lt; <"Input error! Please input again: "& lt; N; }} while

CodePudding user response:

Fun
reference 1 floor response:
basic problem yourself

Have a problem after writing the code to post questions

#include
#include
using namespace std;
The class the Month {
Private: int mon;
Public: the Month (string Mon);
The Month (int n);
Void the show ();
The Month next ();
};
#include
#include
H # include "class."
using namespace std;
The Month: the Month (string STR) {
Do {
If (STR=="Jan") {mon=1; break; }
If (STR=="Feb") {mon=2; break; }
If (STR=="Mar") {mon=3; break; }
If (STR=="Apr") {mon=4; break; }
If (STR=="May") {mon=5; break; }
If (STR=="Jun") {mon=6; break; }
If (STR=="Jul") {mon=7; break; }
If (STR=="Aug") {mon=8; break; }
If (STR=="Sep") {mon=9; break; }
If (STR=="Oct") {mon=10; break; }
If (STR=="Nov") {mon=11; break; }
If (STR=="Dec") {mon=12; break; } cout & lt; <"Input error! Please input again: "& lt; STR; }
while (1); }
The Month: the Month (int n) {
Do {
If (n & gt;=1 & amp; & n <12)={
Mon=n; break; }
The else {
cout <"Input error! Please input again: "& lt; N; }
} the while (1);
}
Void the Month: : show ()
{{the while (1)
If (mon==1) {cout & lt; <"January" & lt; If (mon==2) {cout & lt; <"February" & lt; If (mon==3) {cout & lt; <"March" & lt; If (mon==5) {cout & lt; <"May" & lt; If (mon==6) {cout & lt; <"June" & lt; If (mon==7) {cout & lt; <"Out" & lt; If (mon==8) {cout & lt; <"August" & lt; If (mon==9) {cout & lt; <"September" & lt; If (mon==10) {cout & lt; <"October" & lt; If (mon==11) {cout & lt; <"November" & lt; If (mon==12) {cout & lt; <"Another awarding" & lt; }
}
The Month Month: : next () {
If (mon<12) mon=mon + 1;
The else mon=1;
Return the Month (mon);
}
#include
#include
H # include "class."
using namespace std;
Int main () {
The Month mon1 (" Aug ");
Mon1. The show ();
Mon1. Next ();
The Month mon2 (9);
Mon2. The show ();
Mon2. Next ();
system("pause");
return 0;
}

CodePudding user response:

The Month Month: : next () {
Int m=mon + 1;
If (m> 12) m=1;
Return the Month (m);
}
Can't directly to mon, otherwise itself is changed,

Also, changing between integer and string, a writing is easy to appear problem, should make a an array to do
String up [12]={" Jan ", "Feb",... }.//short
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related