Ask Question
26 June, 18:12

Assign courseStudent's name with Smith, age with 20, and ID with 9999. Use the PrintAll member function and a separate cout statement to output courseStudents's data. End with a newline. Sample output from the given program: Name: Smith, Age: 20, ID: 9999

+2
Answers (2)
  1. 26 June, 21:10
    0
    Following are the program in c++

    ; #include / / header file

    #include

    using namespace std;

    class student / / class

    {

    public:

    int ID, age; / / variables

    string courseStudentsname;

    student () / / constructor initialize the member

    {

    courseStudentsname="Smith";

    age=20;

    ID=9999;

    }

    void PrintAll () / /PrintAll () function

    {

    cout << "Name: " <
    cout << ", Age: " << age;

    cout << ", ID: " << ID;

    }

    };

    int main () / / main function

    {

    student e; / / create object and call default constructor

    e. PrintAll (); / / call the PrintAll () function

    return 0;

    }

    Explanation:

    In the given program we create a three variable inside the class student and declared three variable ID, age of int type and courseStudentsname of string type after that we create a constructor and initialize them as value is given in question and finally create a PrintAll member function which separate cout statement to output. In the main function create a object class student and call the PrintAll function.

    Output:

    Name: Smith, Age: 20, ID: 9999
  2. 26 June, 21:52
    0
    Following are the program in the C+ + Programming Language:

    #include / /header file

    using namespace std; / /namespace

    class Students / /define class

    {public: / /access modifier

    int id, a; / /set variables

    string courseStudentsname; / /set variables

    Students () / /set constructor

    {

    courseStudentsname="Smith"; / /initialize the value

    a=20; / /initialize the value

    id=9999; / /initialize the value

    cout<
    }

    void PrintAll () / /define function

    {

    cout << "Name: " <
    cout << "Age: " << a<
    cout << "ID: " << id; / /print output

    }

    };

    int main () / /define main function

    {

    Students obj; / /set object and call constructor

    obj. PrintAll (); / / call function through object

    return 0;

    }

    Output:

    Name: smith

    Age: 20

    ID: 9999

    Explanation:

    Here, we define class "Students" inside it.

    we define two integer type variable "a" for age of the students and "id" for the id of the students and then we set a string type variable "courseStudentsname" for name of the students. we set the constructor in which we assign the value to the variables. we set the function 'PrintAll () ' in which we print all the variables.

    Finally, we define the "main () " Function in which we create the object of the class "obj" and call the the "PrintAll () " through the object of the class.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Assign courseStudent's name with Smith, age with 20, and ID with 9999. Use the PrintAll member function and a separate cout statement to ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers