struct student
{
char IDNumber[10];
char Name[20];
int Age;
char Department[25];
float CGPA;
} ;
Choose your structure name. Include five member variables for your structure. Then do the following questions based on your structure declaration.
a) Define a function that declares array of student and registers 10 students.
b) Define a function that displays full information about those 10 students.
c) Define a function that can be used to update information about the first student.
#include <iostream>
using namespace std;
struct student
{
char IDNumber[10];
char Name[20];
int Age;
char Department[25];
float CGPA;
} ;
//Define a function that declares array of student and registers 10 students.
void registers(student *s){
int n=10;
cout<<"Resister 10 students\n";
for(int i=0;i<10;i++){
cout<<"Enter details for student "<<i<<":\n";
cout<<"\nID number:";
cin>>s[i].IDNumber;
cout<<"\nName:";
cin>>s[i].Name;
cout<<"\nAge:";
cin>>s[i].Age;
cout<<"\nDepartment:";
cin>>s[i].Department;
cout<<"\nCGPA:";
cin>>s[i].CGPA;
}
}
//Define a function that displays full information about those 10 students.
void display(student *s){
for(int i=0;i<10;i++){
cout<<"Details for student "<<i<<":\n";
cout<<"\nID number:"<<s[i].IDNumber;
cout<<"\nName:"<<s[i].Name;
cout<<"\nAge:"<<s[i].Age;
cout<<"\nDepartment:"<<s[i].Department;
cout<<"\nCGPA:"<<s[i].CGPA;
}
}
//Define a function that can be used to update information about the first student.
void update(student *s){
cout<<"Update details for student 1:\n";
cout<<"\nID number:";
cin>>s[0].IDNumber;
cout<<"\nName:";
cin>>s[0].Name;
cout<<"\nAge:";
cin>>s[0].Age;
cout<<"\nDepartment:";
cin>>s[0].Department;
cout<<"\nCGPA:";
cin>>s[0].CGPA;
}
int main()
{
student s1[10];
registers(s1);
display(s1);
update(s1);
return 0;
}
Comments
Respect
Leave a comment