Store information in a structure

#include <iostream>

using namespace std;

struct student{
    string name;
    string rollno;
    string subject[3];
    int marks[3];
    float cgpa;
};

void display(struct student s){
    cout<<"Student Information"<<endl;
    cout<<"Name of student : "<<s.name<<endl;
    cout<<"Student Roll Number : "<<s.rollno<<endl;
    int len_S = sizeof(s.subject)/sizeof(s.subject[0]);
    for(int i = 0; i < len_S; i++){
        cout<<"Subject "<<i+1<<" : "<<s.subject[i]<<endl;
    }
    int len_M = sizeof(s.marks)/sizeof(s.marks[0]);
    for(int i = 0; i < len_M; i++){
        cout<<"Subject "<<i+1<<" Marks is :"<<s.marks[i]<<endl;
    }

    cout<<"Student CGPA : "<<s.cgpa<<endl;
}
int main(){
    struct student s1 = {"waqar","2023",{"oops","dsa","math"},{24,15,36},8.9};

    display(s1);
    return 0;



}

    Leave a Reply

    Your email address will not be published.

    Need Help?