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
#include <iostream>
#include <cstring>
using namespace std;
struct RollNumber {
  char department;
  char session;
  char reg_num[2];
  char degree;
  char zero;
};
struct Student {
  char name[20];
  unsigned age;
  RollNumber roll;
};
int main() {
  Student *record = new Student;
  strcpy(record->name, "Alice Brown");
  record->age = 22;
  record->roll.department = '3';
  record->roll.session = '1';
  record->roll.reg_num[0] = '1';
  record->roll.reg_num[1] = '2';
  record->roll.degree = '3';
  record->roll.zero = '\0';
  cout << "Student record" << endl;
  cout << "Name: " << record->name << endl;
  cout << "Age: " << record->age << endl;
  cout << "Roll number: " <<  (char *) &record->roll << endl;
  return 0;
}
Comments
Leave a comment