Answer to Question #271351 in C++ for Angelie Suarez

Question #271351

DO THIS PROGRAM AND TAKE PHOTOS OF CODES AND OUTPUT':




1.


Create a Class and initialize attribute of the following:




Class name: Student




Attribute: First Name




Last Name




Sex




Age




2.


From the created class, create 5 objects, and display it using


pretty table.

1
Expert's answer
2021-11-25T07:53:34-0500


#include <iostream>


using namespace std;


class Student{
    private:
        string firstName;
        string lastName;
        string sex;
        int age;
    public:
        Student(string f, string l, string s,int a){
            firstName=f;
            lastName=l;
            sex=s;
            age=a;
        }
        void display(){
            cout<<"\n"<<firstName<<"\t"<<lastName<<"\t"<<sex<<"\t"<<age;
        }
    
};
int main()
{
    Student s1("Mary","Anne","Female",22);
    Student s2("Moses","White","Male",30);
    Student s3("Carol","David","Female",21);
    Student s4("John","Smith","Male",24);
    Student s5("Nana","Vennesa","Female",23);
    
    cout<<"\n"<<"First Name\tLast Name\tSex\tAge";
    s1.display();
    s2.display();
    s3.display();
    s4.display();
    s5.display();


    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