我的学习记录45

2017.11.24李锦浩【第45天】

今天又做了一个关于类与链表的程序,对于一些类的知识又有了进一步的了解。看来对于程序的理解必须在编写程序的过程中实现。

附:

#include<iostream>

using namespace std;

struct score

{

         char name[32];

         int scores;

         score *next;

};

class student

{

public:

         friend class student;

         void scoretotalcount(score *&head);//输入成绩;

         void avaerage(score *head);//求平均值;

         void compare(student &A,double &p);

         static void input();

private:

         static int total, count;

         double average;

         char clas[20];

};

int student::total = 0;

int student::count = 0;

void student::input()

{

         int y;

         cout << "count=";

         cin >> y;

         count = y;

}

void student::scoretotalcount(score *&head)

{

         cout << "请输入成绩";

         score *s, *p;

         p = new score;

         for (int i = 0; i < count; i++)

         {

                  s = new score;

                  cout << "请输入姓名";

                  cin >> s->name;

                  cout << "请输入成绩";

                  cin >> s->scores;

                  if (head == NULL)

                  {

                          head = s;

                          p->next = s;

                          p = p->next;

                  }

                  else

                  {

                          p->next = s;

                          p = p->next;

                  }

         }//使输入的成绩成为一个链表;

         p->next = NULL;

         s = NULL;

         p = NULL;

         delete s;

         delete p;

}

void student::avaerage(score *head)

{

         int y=0;

         while (head->next)

         {

                  y += head->scores;

                  head = head->next;

         }

         average = y / count;

}

void student::compare(student&A, double &p)

{

         if (A.average > p)

                  cout << "class1 is good!";

         else

                  cout << "class2 is good!";

}

int main()

{

         student c1, c2;

         score *head,*head2=NULL;

         head = NULL;

         double j;

         c1.input();

         c1.scoretotalcount(head);

         c1.avaerage(head);

         c2.input();

         c2.scoretotalcount(head2);

         c2.avaerage(head2);

         c1.compare(c2, j);

         system("pause");

         return 0;

}

明日任务:再做一个程序,复习重载运算符。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值