写补充的地方都要补充程序
【输入】
2
1 john b 16
2 Anna g 15
【输出】
john 16
anna 15
代码补全如下:
如有帮助,请帮忙采纳一下,谢谢。
#include <iostream>
#include <string>
using namespace std;
struct astudent
{
int id;
string sname;
int age;
char sex;
void inc()
{
age++;
}
//输出
void prn()
{
cout << id << ' ' << sname << ' ' << sex << ' ' << age << ' ' << endl;
}
void read()
{
//补充
cout << "请输入学生的学号、姓名、年龄、性别(F/M)" << endl;
cin >> id >> sname >> age >> sex;
}
};
int main()
{
int n;
astudent *istu;
cin >> n;
//创建
//补充
istu = new astudent[n];
for (int i = 0;i<n;i++)
{
istu[i].read();
}
//所有的涨一岁
//补充
for (int i = 0;i<n;i++)
{
istu[i].inc();
}
//输出
for (int i=0;i<n;i++)
{
//补充
cout << istu[i].sname << ' ' << istu[i].age << endl;
}
//销毁动态创建的数组
//补充
delete[] istu;
istu = 0;
return 0;
}
这代码太乱了,
你的题目是什么?
你题目的解答代码如下:(如有帮助,望采纳!谢谢! 点击我这个回答右上方的【采纳】按钮)
#include<bits/stdc++.h>
using namespace std;
struct astudent
{
int id;
string sname;
int age;
char sex;
void inc()
{
age++;
}
//输出
void prn()
{
cout<<id<<' '<<sname<<' '<<sex<<' '<<age<<' '<<endl;
}
void read()
{
cin >> id >> sname >> sex >> age;
//补充
}
};
int main()
{
int n;
cin>>n;
//创建
astudent istu[n];
// 补充
for (int i=0; i<n; i++)
{
istu[i].read();
}
//所有的长一岁
//补充
//输出
for (int i=0; i<n; i++)
{
cout<<istu[i].sname<<' '<<istu[i].age<<endl;
//补充
}
//销毁动态创建的数组
//补充
return 0;
}