Answer to Question #323091 in C++ for User12345

Question #323091

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-04-03T18:31:19-0400
#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;
}

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
APPROVED BY CLIENTS