Answer to Question #224828 in C++ for snr

Question #224828

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.


1
Expert's answer
2021-08-12T02:33:27-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS