0

we started classes, i need some pointers on my code if you can help
please.

Define a class called Month. Your class will have one attribute of type int to
represent a month (1 for January, 2 for February, and so forth). Include all the
following methods in this class:
(a) a constructor to set the month using the first three letters in the name of
the month as three arguments (‘J’ ‘A’ ‘N’ for January, ‘F’ ‘E’ ‘B’ for
February, and so forth),
( a constructor to set the month using an integer as an argument (1 for
January, 2 for February, and so forth),
a default constructor,
(d) an input function that reads the month as an integer,
(e) an input function that reads the month as the first three letters in the
name of the month,
(f) an output function that outputs the month as an integer,
(g) an output function that outputs the month as the first three letters in the
name of the month,
(h) and a member function that returns the next month as a value of type
Month.

heres my start
[#include<iostream>
#include<string>
using namespace std;

class Month{
public:
int month;
Month(int month);
Month(string& one,string& two,string& three);
Month();
void input1(intgoo month);
void input2(string one,string two,string three);
void output1();
void output2();
};


int main(){
Month month;
int m;
string one,two,three;

month.input1(m);
month.input2(one,two,three);


system("pause");
}

Month::Month(){
//nothing
}


void input1(int month){
cout<<"Enter the month as an integer: ";
cin>>month;
while(month<1||month>12){
cout<<"Wrong number.";
cin>>month;
}

}

void input2(string one,string two,string three){
int count=0;
cout<<"Enter the month as an string(3 letters): ";
while(count<3){
cin>>one;
cin>>two;
cin>>three;
count+=4;
}


}
]

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by VernonDozier
0

Use code tags.

[code]

// code here

[/code]

What's the question?

One thing that jumps out is that you are passing variables by value to a void function, changing those variables inside the function, then exiting the function, which does nothing. You need to either pass by reference instead of value or return something here:

void input1(int month){
cout<<"Enter the month as an integer: ";
cin>>month;
while(month<1||month>12){
cout<<"Wrong number.";
cin>>month;
}

}

Or if month is a class variable and this is a class function, don't pass month, since it will be passed with the class object. But the way you have it doesn't make sense.

Edited by VernonDozier: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.