Answer to Question #309817 in C++ for Anup

Question #309817

Create a class named 'Student' with a string variable 'name' and an integer variable 

'roll_no'. Assign the value of roll_no as '2' and that of name as "John" by creating an 

object of the class Student.


1
Expert's answer
2022-03-11T07:25:01-0500

#include <iostream>

#include <string>


using namespace std;


class Student {

private:

    std::string _name;

    int _roll_no;


public:

    Student(const std::string& name, int roll_no) {

        _name = name;

        _roll_no = roll_no;

    }

};


int main()

{

    Student s("Dan", 10);


    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