- 2

Assign and print the roll number, phone number and address of two students having names "Sam" and "John" respectively by creatin

Assign and print the roll number, phone number and address of two students having names "Sam" and "John" respectively by creating two objects of class 'Student'.

25th Mar 2021, 7:03 AM
NASHON ODERO
NASHON ODERO - avatar
3 Réponses
0
13th Dec 2021, 3:07 PM
Kolli Sumanth
- 1
Kindly help me code this using c++
25th Mar 2021, 7:13 AM
NASHON ODERO
NASHON ODERO - avatar
- 1
#include<iostream> #include<string> using namespace std; class Student { public: Student(string name,string roll,string phone,string address) { setDetails(name,roll,phone,address); } void setDetails(string name,string roll,string phone,string address) { studentName=name; studentRoll=roll; studentPhone=phone; studentAddress=address; } string getDetails() { cout<<studentName<<endl; cout<<studentRoll<<endl; cout<<studentPhone<<endl; cout<<studentAddress<<endl; } private: string studentName; string studentRoll; string studentPhone; string studentAddress; }; int main() { Student student1("Sam","P101/1358G/18","0722925016","P.O BOX 30-2345"); Student student2("John","P108/1234G/18","0734674017","P.O BOX 45-01001"); cout<<student1.getDetails()<<endl; cout<<student2.getDetails()<<endl; return 0; }
25th Mar 2021, 7:24 AM
NASHON ODERO
NASHON ODERO - avatar