📅  最后修改于: 2020-09-25 06:10:55             🧑  作者: Mango
在此程序中,将创建一个student
结构。
该结构具有三个成员: name
(字符串), roll
(整数)和marks
(浮点数)。
然后,我们创建了一个大小为10的结构数组,以存储10个学生的信息。
该程序使用for循环,从用户那里获取10名学生的信息,并将其显示在屏幕上。
#include
using namespace std;
struct student
{
char name[50];
int roll;
float marks;
} s[10];
int main()
{
cout << "Enter information of students: " << endl;
// storing information
for(int i = 0; i < 10; ++i)
{
s[i].roll = i+1;
cout << "For roll number" << s[i].roll << "," << endl;
cout << "Enter name: ";
cin >> s[i].name;
cout << "Enter marks: ";
cin >> s[i].marks;
cout << endl;
}
cout << "Displaying Information: " << endl;
// Displaying information
for(int i = 0; i < 10; ++i)
{
cout << "\nRoll number: " << i+1 << endl;
cout << "Name: " << s[i].name << endl;
cout << "Marks: " << s[i].marks << endl;
}
return 0;
}
输出
Enter information of students:
For roll number1,
Enter name: Tom
Enter marks: 98
For roll number2,
Enter name: Jerry
Enter marks: 89
.
.
.
Displaying Information:
Roll number: 1
Name: Tom
Marks: 98
.
.
.