A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C++ Class Exercise - Read and Print Class, Students Details using Two Classes
Q:

C++ Class Exercise - Read and Print Class, Students Details using Two Classes

0

C++ Class Exercise - Read and Print Class, Students Details using Two Classes

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C++ program - Read and print Class, Student details using Two Classes

Let’s consider the following example:

/*C++ Class Exercise - Read and Print Class, Students 
Details using Two Classes*/

#include <iostream>
#include <string.h>

using namespace std;

class student{
	private:
		char name[30];
		int rollNo;
	public:
		void getStudent(){
			strcpy(name,"PIYA KAUSHAL");
			rollNo=101;
		}
		void printStudent(){
			cout<<"Name: "<<name<<",Roll No.: "<<rollNo<<endl;
		}
};

class classDetails{
	private:
		char clsName[30];
		student std; //object
	public:
		void getClassDetails(){
			strcpy(clsName,"Higher Sec.");
			std.getStudent();			
		}
		void printClassDetails(){
			cout<<"Class Name: "<<clsName<<endl;
			std.printStudent();
		}
};

int main()
{
	classDetails CD;
	CD.getClassDetails();
	CD.printClassDetails();
	return 0;
}

Output

    Class Name: Higher Sec.
    Name: PIYA KAUSHAL,Roll No.: 101

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now