Program:
#include <iostream> #include <string.h> using namespace std; class Marks { private: int rno; float perc; public: //constructor Marks() {rno = 0; perc = 0.0f;} //input roll numbers and percentage void readMarks(void) { cout<<"Enter roll number: "; cin>>rno; cout<<"Enter percentage: "; cin>>perc; } //print roll number and percentage void printMarks(void) { cout<<"Roll No.: "<<rno<<endl; cout<<"Percentage: "<<perc<<"%"<<endl; } }; class Student { private: //object to Marks class Marks objM; char name[30]; public: //input student details void readStudent(void) { //Input name cout<<"Enter name: "; cin.getline(name, 30); //input Marks objM.readMarks(); } //print student details void printStudent(void) { //print name cout<<"Name: "<<name<<endl; //print marks objM.printMarks(); } }; //main code int main() { //create object to student class Student std; std.readStudent(); std.printStudent(); return 0; }
Output
Enter name: Amit Shukla Enter roll number: 101 Enter percentage: 84.02 Name: Amit Shukla Roll No.: 101 Percentage: 84.02%
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Program:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer