Create a class for Student with the following attributes: Student ID, Name, CourseID, Gender {male/female} and Phone Number. (Use enumeration data type for Gender) Add constructors to initialize data members. Print the Current details of the Student. Add a behaviour to modify the phone number and display the updated details.
#include <iostream>
using namespace std;
class Student{
private:
int StudentID;
string Name;
int CourseID;
string Gender;
string PhoneNumber;
public:
Student(){
StudentID=111;
Name="John" ;
CourseID=123;
Gender="Male";
PhoneNumber="+123456";
}
void print(){
cout<<"Student ID: "<<StudentID<<"\n";
cout<<"Name: "<<Name<<"\n";
cout<<"CourseID: "<<CourseID<<"\n";
cout<<"Gender: "<<Gender<<"\n";
cout<<"PhoneNumber: "<<PhoneNumber<<"\n";
}
void modify(string p){
PhoneNumber=p;
}
void UpdatedDetails(){
cout<<"Student ID: "<<StudentID<<"\n";
cout<<"Name: "<<Name<<"\n";
cout<<"CourseID: "<<CourseID<<"\n";
cout<<"Gender: "<<Gender<<"\n";
cout<<"PhoneNumber: "<<PhoneNumber<<"\n";
}
};
int main()
{
Student s;
s.print();
s.modify("98765");
s.UpdatedDetails();
return 0;
}
Comments
Leave a comment