一道C++编程的基础题,求解

建立一个简单链表,在下程序的基础上进行修改,将该程序用new运算符修改成能够按照输入的n值,动态生成和输入包含n个学生信息的链表(包含地址)。
(n的值可以在程序里面自己事先定义好,只要运用到New运算符就行了)
程序:#include
#include
using namespace std;
struct address
{
int n;
string name;
};
struct student
{
int num;
float score;
address dorm;
struct student* next;
};
int main()
{
student a, b, c, * head, * p;
a.num = 31001; a.score = 89.5; a.dorm.n = 1; a.dorm.name = "25舍";
b.num = 31003; b.score = 90; b.dorm.n = 2; b.dorm.name = "26舍";
c.num = 31007; c.score = 85; c.dorm.n = 3; c.dorm.name = "27舍";
head = &a;
a.next = &b;
b.next = &c;
c.next = NULL;
p = head;
do {
cout << p->num << " " << p->score << " " << p->dorm.n << " " << p->dorm.name << endl;
p = p->next;
} while (p != NULL);
return 0;
}
跪求大佬解决,谢谢!

c++
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问