zoukankan      html  css  js  c++  java
  • C++学习平时作业(1)--链表

     

    #include <iostream>
    
    usingnamespace std;
    
    //要求创建一个学生成绩信息链表,并输出每个学生的成绩信息。
    
    struct structNode
    {
        int num;
        char name[10];
        float English_score;
        float Math_score;
        structNode *next;
    };
    
    structNode *head; //链表的头节点的指针
    structNode *pre;//链尾插入节点时需要的链尾指针
    
    void init()
    {
      head = new structNode;
      if(head!=NULL)
      {
        cout << "OK!" << endl;
        head->next = NULL; //链表头指针初始化
        pre = head;
      }
      else
        cout << "Failed!" << endl;
    }
    
    void add()
    {
        int n;
      cout << "input student number:" << endl;
    
      cin >> n;
    
      structNode *p;//p为工作指针
    
      for(int i=0; i<n; i++)
      {
    
        p = new structNode;
        cout << "please input the No." << i+1 <<"'s number";
        cin >> p->num;
    
        cout << "please input the No." << i+1 <<"'s name";
        cin >> p->name;
    
        cout << "please input the No." << i+1 <<"'s the English's score";
        cin >> p->English_score;
    
        cout << "please input the No." << i+1 <<"'s the Math's score";
        cin >> p->Math_score;
    
        p->next = NULL;
        pre->next = p;
        pre = p;
      }
    }
    
    void putout()
    {
        structNode *s;
    
        s = head;
    
        while(s->next!=NULL)
        {
            s = s->next;
            cout << s->num << "	";
            cout << s->name << "	";
            cout << s->English_score << "	";
            cout << s->Math_score << "	" << endl;
        }
    }
    
    int main()
    {
        init();
        add();
        cout << "--------------------------------------------------------------------------------" << endl;
        putout();
        cout << "--------------------------------------------------------------------------------" << endl;
    
        return0;
    }
  • 相关阅读:
    Vue之常用语法
    Django之crm
    Django项目之客户
    前端、数据库、Django简单的练习
    Django的认证系统
    Django之form表单
    OpneCV 二值图像区域处理
    OpenCV图像处理中常用函数汇总(1)
    OpenCV3编程入门笔记(6)自我验证各函数程序代码
    OpenCV_轮廓的查找、表达、绘制、特性及匹配
  • 原文地址:https://www.cnblogs.com/AlinaL/p/12852204.html
Copyright © 2011-2022 走看看