#include<iostream>
#include<fstream>
using namespace std;
class C
{
public:
C();
void setDate(int&);
int getDate();
private:
int day;
};
// Default constructor
C::C()
{
// Initialise the variables
day = 0;
}
void C::setDate(int& newDay)
{
day = newDay;
}
int C::getDate()
{
return day;
}
const void printMenu();
const void newDate(C&);
const void getDate(C);
const void dateMenu();
int main()
{
printMenu();
cout << endl;
system("pause");
return 0;
}
const void printMenu()
{
cout << "********* My Date Utility Menu *********" << endl << endl;
cout << "a) Set date" << endl;
cout << "b) Return date" << endl;
cout << "q) Quit" << endl;
dateMenu();
}
const void dateMenu()
{
char confirm, select;
C date;
cout << endl<< "Enter option: ";
cin >> select;
while(1)
{
switch (tolower(select))
{
case 'a': newDate(date);
break;
case 'b': getDate(date);
break;
case 'q': cout << endl << "Confirm to quit? (y = Yes, n = No): ";
cin >> confirm;
if (tolower(confirm) == 'y')
{
exit(0);
}
else if (tolower(confirm) == 'n')
{
cout << endl;
printMenu();
}
else
{
cout << endl << "Invalid input!!" << endl <<endl;
system("pause");
cout << endl;
printMenu();
}
break;
default : cout << endl << "Invalid input!!" << endl << endl;
system("pause");
exit(0);
}
}
}
const void newDate(C& date)
{
int d=0;
int toYear = 0;
//string y = date.getYear();
string m;
string y;
cout << endl << "Enter day (between 1 & 31): ";
cin >> d;
date.setDate(d);
printMenu();
system("pause");
}
const void getDate(C date)
{
cout << date.getDate();
system("pause");
cout << endl;
printMenu();
}
need help to troubleshoot
Started by debug, Nov 13 2008 04:45 AM
2 replies to this topic
#1
Posted 13 November 2008 - 04:45 AM
hi below is the code which i have come up with. when i enter a date in option a, the set function of the class should change the value of variable day to my input value. however, when i enter option b to return the date, the date remain the same as in the default constructor. can any one help me to check where the problem lies? thks
|
|
|
#2
Posted 13 November 2008 - 08:30 AM
You're doing pass-by-value with your functions.
#3
Posted 13 November 2008 - 05:49 PM
u mean the class function or the function for the main?


Sign In
Create Account


Back to top









