0% found this document useful (0 votes)
17 views1 page

Structure

The document contains a C++ program that defines a structure for storing student data, including CMS number, name, and marks. It allows the user to input data for three students and then displays that data. Additionally, it provides functionality to search for a student by their CMS number and display their details if found.

Uploaded by

hashirali12189
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

Structure

The document contains a C++ program that defines a structure for storing student data, including CMS number, name, and marks. It allows the user to input data for three students and then displays that data. Additionally, it provides functionality to search for a student by their CMS number and display their details if found.

Uploaded by

hashirali12189
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include<iostream>

using namespace std;


// define a structure to store student data
struct student {
int cms;
char name[30];
float marks;
void getData(); // get student data from user
void displayData(); // display data
};
void student::getData() {
cout << "\nEnter CMS No. : ";
cin >> cms;
cin.ignore(); // ignore the newline char inserted when you press enter
cout << "Enter Name : ";
cin.getline(name, 30);
cout << "Enter Marks : ";
cin >> marks;
}

void student::displayData() {
cout << "\nCMS No. : " << cms << endl;
cout << "Name : " << name << endl;
cout << "Marks : " << marks << endl;
}
int main() {
student students[3];
int cms;
for (int i = 0; i < 3; i++)
{
students[i].getData();
}
for (int i = 0; i < 3; i++)
{
students[i].displayData();
}
cout << "Enter cms number to search:";
cin >> cms;
for (int i = 0; i < 3; i++)
{
if (students[i].cms == cms)
{
students[i].displayData();
}
}

return 0;
}//end main()

You might also like