I have a problem with this code i don't able to update my dates in admission and date of birth

#include <iostream>
using namespace std;
class date
{
private:
int day{1};
int month{1};
int year{2021};
int days[12]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

public:
date()
{
setday(1);
setmonth(1);
setyear(2000);
}
date(int d, int m, int y)
{
setyear(y);
setmonth(m);
setday(d);
}

bool isleap()
{
if ((((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)))
{
return true;
}
else
return false;
}
void setyear(int y)
{
if (y >= 1930 && y <= 2021)
{
year = y;
}
else
{
year = 2021;
}
}

void setmonth(int m)
{
if (m >= 1 && m <= 12)
{
month = m;
}
else
{
m = 1;
}
}

void setday(int d)
{
if (d >= 1 && d <= days[month - 1] + (month == 2 && isleap()))
{
day = d;
}
else
{
d = 1;
}
}
void displayinfo()
{
cout << day << " - " << month << " - " << year;
}
};
class student
{
private:
date dob;
date doa;
double id, sgpa, height;
string fname, sname;

public:
student()
{
dob.setmonth(1);
dob.setmonth(1);
dob.setyear(2000);
doa.setday(1);
doa.setmonth(1);
doa.setyear(2020);
id = 1;
fname = "Farhan";
sname = "Ansari";
height = 7;
sgpa = 3.43;
}

void setfname(string n)
{
fname = n;
}

void setheight(double h)
{
height = h;
}
void setsgpa(double s)
{
sgpa = s;
}

void setid(double val)
{
id = val;
}
void setsname(string sn)
{
sname = sn;
}
void display()
{
cout << "ID Is : " << id << endl;
cout << "First name Is : " << fname << endl;
cout << "Sure name Is : " << sname << endl;
cout << "Height Is : " << height << endl;
cout << "SGPA Is : " << sgpa << endl;
cout << "Date of birth :";
dob.displayinfo();
cout << "\nDate of admission :";
doa.displayinfo();
}
};

int main()
{
student s1, s2, s3;
date dob;
date doa;
jump:
double choice, c, x, n, i;
string v;
cout << "\n\n ~~~MENU~~~"
"\n=>1. For Student 1"
"\n=>2. For Student 2"
"\n=>3. For Student 3"
"\n=>4. Exit";
cout << "\nEnter your choice :";
cin >> choice;
if (choice == 1)
{
w:
q:
cout << "\n\n ~~~Student 1~~~"
"\n=>1. For Student ID "
"\n=>2. For Student First name "
"\n=>3. For Student Sure name "
"\n=>4. For Student Height "
"\n=>5. For Student SGPA "
"\n=>6. For Student Date of Birth "
"\n=>7. For Student Admission date "
"\n=>8. For detail display "
"\n=>9. For Return ";
while (1)
{
cout << "\nEnter your choice : ";
cin >> c;
cout << "\n";
if (c == 1)
{
cout << "Enter ID : ";
cin >> x;
s1.setid(x);
}
else if (c == 2)
{
cout << "Enter First Name : ";
cin >> v;
s1.setfname(v);
}
else if (c == 3)
{
cout << "Enter Sure Name : ";
cin >> v;
s1.setsname(v);
}
else if (c == 4)
{
cout << "Enter Height : ";
cin >> x;
s1.setheight(x);
}
else if (c == 5)
{
cout << "Enter SGPA : ";
cin >> x;
s1.setsgpa(x);
}
else if (c == 6)
{
while (1)
{
cout << "=> Student Admission date "
"\n=>1. For Enter Day "
"\n=>2. For Enter Month "
"\n=>3. For Enter Year "
"\n=>4. For Return to student menu"
"\nPlease enter you choice :";
cin >> n;
if (n == 1)
{
cout << "Please Enter Admission day : ";
cin >> x;
doa.setday(x);
}
else if (n == 2)
{
cout << "Please Enter Admission month : ";
cin >> x;
doa.setmonth(x);
}
else if (n == 3)
{
cout << "Please Enter Admission year : ";
cin >> x;
doa.setyear(x);
}
else if (n == 4)
{
goto q;
}
else
return 0;
}
}
else if (c == 7)
{
while (1)
{
cout << "=> Student Date of birth "
"\n=>1. For Enter Day "
"\n=>2. For Enter Month "
"\n=>3. For Enter Year "
"\n=>4. For Return to student menu"
"\nPlease enter you choice : ";
cin >> i;
if (i == 1)
{
cout << "Please Enter birth day : ";
cin >> x;
dob.setday(x);
}
else if (i == 2)
{
cout << "Please Enter birth month : ";
cin >> x;
dob.setmonth(x);
}
else if (i == 3)
{
cout << "Please Enter birth year : ";
cin >> x;
dob.setyear(x);
}
else if (i == 4)
{
goto w;
}
else
return 0;
}
}
else if (c == 8)
{
cout << " ~~~Student 1~~~\n";
s1.display();
}
else if (c == 9)
{
goto jump;
}
else
return 0;
}
}
else if (choice == 2)
{
r:
s:
cout << "\n\n ~~~Student 2~~~"
"\n=>1. For Student ID "
"\n=>2. For Student First name "
"\n=>3. For Student Sure name "
"\n=>4. For Student Height "
"\n=>5. For Student SGPA "
"\n=>6. For Student Date of Birth "
"\n=>7. For Student Admission date "
"\n=>8. For detail display "
"\n=>9. For Return ";
while (1)
{
cout << "\nEnter your choice : ";
cin >> c;
if (c == 1)
{
cout << "Enter ID : ";
cin >> x;
s2.setid(x);
}
else if (c == 2)
{
cout << "Enter First Name : ";
cin >> v;
s2.setfname(v);
}
else if (c == 3)
{
cout << "Enter Sure Name : ";
cin >> v;
s2.setsname(v);
}
else if (c == 4)
{
cout << "Enter Height : ";
cin >> x;
s2.setheight(x);
}
else if (c == 5)
{
cout << "Enter SGPA : ";
cin >> x;
s2.setsgpa(x);
}
else if (c == 6)
{
while (1)
{
cout << "\n=> Student Admission date "
"\n=>1. For Enter Day "
"\n=>2. For Enter Month "
"\n=>3. For Enter Year "
"\n=>4. For Return to student menu"
"\nPlease enter you choice : ";
cin >> n;
if (n == 1)
{
cout << "Please Enter Admission day : ";
cin >> x;
doa.setday(x);
}
else if (n == 2)
{
cout << "Please Enter Admission month : ";
cin >> x;
doa.setmonth(x);
}
else if (n == 3)
{
cout << "Please Enter Admission year : ";
cin >> x;
doa.setyear(x);
}
else if (n == 4)
{
goto r;
}
else
return 0;
}
}
else if (c == 7)
{
while (1)
{
cout << "=> Student Date of birth "
"\n=>1. For Enter Day "
"\n=>2. For Enter Month "
"\n=>3. For Enter Year "
"\n=>4. For Return to student menu"
"\nPlease enter you choice :";
cin >> i;
if (i == 1)
{
cout << "Please Enter birth day : ";
cin >> x;
dob.setday(x);
}
else if (i == 2)
{
cout << "Please Enter birth month : ";
cin >> x;
dob.setmonth(x);
}
else if (i == 3)
{
cout << "Please Enter birth year : ";
cin >> x;
dob.setyear(x);
}
else if (i == 4)
{
goto s;
}
else
return 0;
}
}
else if (c == 8)
{
cout << " ~~~Student 2~~~\n";
s2.display();
}
else if (c == 9)
{
goto jump;
}
else
return 0;
}
}
else if (choice == 3)
{
t:
p:
cout << "\n\n ~~~Student 1~~~"
"\n=>1. For Student ID "
"\n=>2. For Student First name "
"\n=>3. For Student Sure name "
"\n=>4. For Student Height "
"\n=>5. For Student SGPA "
"\n=>6. For Student Date of Birth "
"\n=>7. For Student Admission date "
"\n=>8. For detail display "
"\n=>9. For Return ";
while (1)
{
cout << "\nEnter your choice : ";
cin >> c;
if (c == 1)
{
cout << "Enter ID : ";
cin >> x;
s3.setid(x);
}
else if (c == 2)
{
cout << "Enter First Name : ";
cin >> v;
s3.setfname(v);
}
else if (c == 3)
{
cout << "Enter Sure Name : ";
cin >> v;
s3.setsname(v);
}
else if (c == 4)
{
cout << "Enter Height : ";
cin >> x;
s3.setheight(x);
}
else if (c == 5)
{
cout << "Enter SGPA : ";
cin >> x;
s3.setsgpa(x);
}
else if (c == 6)
{
while (1)
cout << "=> Student Admission date "
"\n=>1. For Enter Day "
"\n=>2. For Enter Month "
"\n=>3. For Enter Year "
"\n=>4. For Return to student menu : ";
cin >> n;
if (n == 1)
{
cout << "Please Enter Admission day : ";
cin >> x;
doa.setday(x);
}
else if (n == 2)
{
cout << "Please Enter Admission month : ";
cin >> x;
doa.setmonth(x);
}
else if (n == 3)
{
cout << "Please Enter Admission year : ";
cin >> x;
doa.setyear(x);
}
else if (n == 4)
{
goto t;
}
else
return 0;
}
else if (c == 7)
{
while (1)
cout << "=> Student Date of birth "
"\n=>1. For Enter Day "
"\n=>2. For Enter Month "
"\n=>3. For Enter Year "
"\n=>4. For Return to student menu"
"\nplease enter you choice :";
cin >> i;
if (i == 1)
{
cout << "Please Enter birth day : ";
cin >> x;
dob.setday(x);
}
else if (i == 2)
{
cout << "Please Enter birth month : ";
cin >> x;
dob.setmonth(x);
}
else if (i == 3)
{
cout << "Please Enter birth year : ";
cin >> x;
dob.setyear(x);
}
else if (i == 4)
{
goto p;
}
else
return 0;
}
else if (c == 8)
{
cout << " ~~~Student 3~~~\n";
s3.display();
}
else if (c == 9)
{
goto jump;
}
else
return 0;
}
}
else
return 0;
}
Last edited on
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

I can't comment on specific problems in your code because of the lack of code tags.
Two general comments:

1) Have you never heard of functions? You do the same thing in your code three times. Once for each student. Your code is not scalable. What if there were 10 students? 100 students? Same thing with dates. Write ONE function to input a date. Call it where ever you need a date.

2) Get rid of the gotos. gotos are evil. You program is impossible to follow with all the gotos.

Last edited on
Will you guide me. How to make it best because I'm student
As I said in my previous post, I can't help you until you apply code tags.
Read the link I provided for instructions on editing your post and applying code tags.

It is also nice if you include proper formatting as well. Just copy and paste the code from your IDE, it will usually preserve indenting and other whitespace, which makes it easier to read.
Topic archived. No new replies allowed.