01-用链式结构打印学生成绩单

用链式结构打印学生成绩单

 

#include <iostream>

using namespace std;

 

struct StScore

{

    std::string id;

    int math;

    int english;

    int computer;

    struct StScore* next;

};

 

int main()

{

    StScore first;

    first.id = "C";

    first.math = 80;

    first.english = 85;

    first.computer = 83;

    first.next = nullptr;

 

    StScore second;

    second.id = "A";

    second.math = 75;

    second.english = 91;

    second.computer = 88;

    second.next = nullptr;

    first.next = &second;

    cout<<"id\tmath\tenglish\tcomputer"<<endl;

    StScore* pNode = &first;

    while (pNode != nullptr)

    {

        cout<<pNode->id<<"\t"

            <<pNode->math<<"\t"

            <<pNode->english<<"\t"

            <<pNode->computer

            <<endl;

        pNode = pNode->next;

    }

    return 0;

}

 

结果:

id math english computer

C 80 85 83

A 75 91 88

Program ended with exit code: 0

 

 

 

posted @ 2016-01-19 13:21  sharpfeng  阅读(271)  评论(0编辑  收藏  举报