Answer to Question #237033 in C++ for c++

Question #237033

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 name as "john" by creating an object of the class student.


1
Expert's answer
2021-09-15T17:44:36-0400
#include <iostream>
#include <string>
using namespace std;

class student {
public:
    string name;
    int roll_no;
};

int main() {
    student st1;

    st1.name = "john";
    st1.roll_no = 2;

    cout << "Name: " << st1.name << endl;
    cout << "roll: " << st1.roll_no << endl;
}

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