string problem

This question is about a class and I did good but my problem is when I am giving information from keyboard it is working fine when I put my gpa, it does not ask for date of birth instead it goes to next instruction.

Constructors works fine.


I think something is wrong in here.
[void Student:: input()
{
cout << "Please give me your lastname:";
getline(cin,lastname);
cout << "Please give me your firstname:";
getline(cin,lastname);
cout << "Enter number of credits you earned:";
cin >> credits;
cout << "What is your GPA:";
cin >> gpa;
if(gpa < 0.0 || gpa > 4.0) // limiting the gpa
{
cout << "Not a valid GPA , program aborted";
exit(1);
}
cout << "Enter you date of birth:";
getline(cin,date_of_birth);
cout << "Enter you matriculation date:";
getline(cin,date_of_matriculation);
}code]

here is my complete code
//Student_class.cpp
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>
using namespace std;

class Student
{
private: //access specifier
string lastname;
string firstname;
string standing;
int credits; //member variables
double gpa;
string date_of_birth;
string date_of_matriculation;
public://access specifier


Student(); // default constructor
//constructor
Student(string newlastname,string newfirstname, int newcredits,
double newgpa,string newdate_of_birth,string newdate_of_matriculation);

void input();
void output();

//accessors
string getlastname();
string getfirstname();
string getstanding();
int getcredits();
double getgpa();
string getdate_of_birth();
string getdate_of_matriculation();


//mutators
void setlastname(string LASTNAME);
void setfirstname(string FIRSTNAME );
void setstanding(string STANDING);
void setcredits(int CREDITS );
void setgpa(double GPA);
void setdate_of_birth(string DATE_OF_BIRTH);
void setdate_of_matriculation(string DATE_OF_MATRICULATION);

};

int main ()
{
// call to the constructor when we declare object(implicit call)
Student s1("Mohammed","Ahmar" ,19,3.5,"July 24 1993","August 12 2012");
s1.output();
cout << "\n\n";
s1.input(); //call to input function
cout << endl;
s1.output();// call to output function
return 0;

}

//defining default constructor
Student:: Student(): lastname("--"),firstname("--"),credits(0),
gpa(0.0),date_of_birth("--"), date_of_matriculation("--")

{
}
//defining constructor
Student:: Student(string newlastname,string newfirstname, int newcredits,
double newgpa,string newdate_of_birth,string newdate_of_matriculation):

lastname(newlastname),
firstname(newfirstname),
credits(newcredits),
gpa(newgpa),
date_of_birth(newdate_of_birth),
date_of_matriculation(newdate_of_matriculation)
{
if(gpa < 0.0 || gpa > 4.0)
{
cout << "Not a valid GPA,program aborted";
exit(1);
}


}
//defining mutators
void Student:: setlastname(string LASTNAME)
{
lastname = LASTNAME;
}
void Student:: setfirstname(string FIRSTNAME)
{
firstname = FIRSTNAME;
}
void Student:: setcredits(int CREDITS)
{
credits = CREDITS;
}
void Student:: setgpa(double GPA)
{
gpa = GPA;
}
void Student:: setdate_of_birth(string DATE_OF_BIRTH)
{
date_of_birth = DATE_OF_BIRTH;
}
void Student:: setdate_of_matriculation(string DATE_OF_MATRICULATION)
{
date_of_matriculation = DATE_OF_MATRICULATION;
}
//defining accessors
string Student:: getlastname()
{
return lastname;
}
string Student:: getfirstname()
{
return firstname;
}
string Student:: getstanding()
{
if (credits <= 15)
return "lower freshman";
else if (credits >= 16 && credits <= 30)
return "upper freshman";
else if (credits >= 31 && credits <= 45)
return "lower sophmore";
else if (credits >= 46 && credits <= 60)
return "upper sophmore";
else if (credits >= 61 && credits <= 75)
return "lower junior";
else if (credits >= 76 && credits <= 90)
return "upper junior";
else if (credits >= 91 && credits <= 105)
return "lower senior";
else
return "upper senior";
}
int Student:: getcredits()
{
return credits;
}
double Student::getgpa()
{
return gpa;
}
string Student::getdate_of_birth()
{
return date_of_birth;
}
string Student:: getdate_of_matriculation()
{
return date_of_matriculation;
}
//defining input and output functions
void Student:: input()
{
cout << "Please give me your lastname:";
getline(cin,lastname);
cout << "Please give me your firstname:";
getline(cin,lastname);
cout << "Enter number of credits you earned:";
cin >> credits;
cout << "What is your GPA:";
cin >> gpa;
if(gpa < 0.0 || gpa > 4.0) // limiting the gpa
{
cout << "Not a valid GPA , program aborted";
exit(1);
}
cout << "Enter you date of birth:";
getline(cin,date_of_birth);
cout << "Enter you matriculation date:";
getline(cin,date_of_matriculation);
}
void Student:: output()
{

cout<< "Student's name is : " << firstname << " " << lastname << endl;
cout<< "Number of credits earned : " << credits << endl;
cout<< "Student's GPA is : " << gpa << endl;
cout<< "Student's standing is: " << getstanding() << endl;
cout<< "Student's date of birth is: " << date_of_birth << endl;
cout<< "Student's matriculation date is: "<< date_of_matriculation << endl;
}
Topic archived. No new replies allowed.