Answer to Question #321592 in C++ for nutra

Question #321592

Write a C++ program to make a structure of a student consisting of integer age, char name and


structure roll number that further divides into department, session, registration number and


degree. Set and display all the values from main function and display the record on screen to


present the access of structure within structure. You have to by access structure using pointer


type variable of structure.



1
Expert's answer
2022-06-20T08:36:13-0400
#include <iostream>

struct RollNumber
{
	const char* department;
	const char* session;
	int registrationNumber;
	const char* degree;
};

struct Student
{
	const char* name;
	int age;
	RollNumber* rollNumber;
};

int main()
{
	RollNumber* rollNumber = new RollNumber;
	rollNumber->department = "Mathematics";
	rollNumber->session = "Spring 2022";
	rollNumber->registrationNumber = 284735;
	rollNumber->degree = "Bachelor";
	Student* student = new Student;
	student->age = 22;
	student->name = "John Wales";
	student->rollNumber = rollNumber;
	std::cout << "Name: " << student->name << std::endl;
	std::cout << "Age: " << student->age << std::endl;
	std::cout << "Roll number: " << std::endl;
	std::cout << "* Department: " << student->rollNumber->department << std::endl;
	std::cout << "* Session: " << student->rollNumber->session << std::endl;
	std::cout << "* Registration number: " << student->rollNumber->registrationNumber << std::endl;
	std::cout << "* Degree: " << student->rollNumber->degree << std::endl;
	delete student;
	delete rollNumber;
	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

LATEST TUTORIALS
New on Blog