标题:[求助]各位能不能帮我看一下这两个程序有什么问题
取消只看楼主
lichee8611
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2007-4-3
 问题点数:0 回复次数:0 
[求助]各位能不能帮我看一下这两个程序有什么问题

各位能不能帮我看一下这两个程序有什么问题,小弟才疏,确实没瞧出个究竟来,有劳了!
第一个
#include<iostream.h>
class Student
{
public:
void scoretotalcount();
static float sum();
static float average();
private:
float score;static float total=0;static int count=0;
};
void Student::scoretotalcount()
{
Student *P;
cout<<"Please input the score of students(end up with -1):\n";
cin>>p->score;
p->total+=p->score;
p->count++;
while(p->score!=-1)
{
cin>>p->score;
p->total+=p->score;
p->count++;
}
cout<<"Have set it.\n";
}
float Student::sum()
{
Student *p;
return p->total;
}
float Student::average()
{
Student *p;
return (p->total)/(p->count);
}
void main()
{
scoretotalcount();
cout<<"The total score is:"<<sum()<<endl;
cout<<"The average score is:"<<average()<<endl;
cout<<"Completed!"<<endl;
}


第二个
#include<iostream.h>
class book
{
public:
void display(char);
void borrow(char);
void restore(char);
book *next;
char bookname;int price,number; (我本来想把这三个定义为private,但出现了好多错误)
};
void main()
{
book *s,*head,*nect;
int i=0,j;char k;
cout<<"Please input some books(name,price)\n";
s=new book;
cin>>s->bookname>>s->price;
i++;
while(s->bookname!='#')
{
s=new book;
cin>>s->bookname>>s->price;
i++;}
cout<<"the number of books:\n"<<i<<endl;
cout<<"please input the name of the book you want:\n";
cin>>k;
cout<<"What do you want to do?(Input 1 to show is it availible;2 to borrow the book;3 to restore the book):\n";
cin>>j;
switch(j)
{
case 1:display(k);break; (编译时说这三个函数没定义)
case 2:borrow(k);break;
case 3:restore(k);break;
}
}
void book::display(char x)
{
book *s;
while(book *head)
{
if(s->bookname==x)cout<<"It's useble\n";
else cout<<"It's unuseble\n";
head=head->next;
}
}
void book::borrow(char x)
{
book *s;
int i;
while(book *head)
{
if(s->bookname==x)i--;
head=head->next;
}
cout<<"Now the number of books is:"<<i<<endl;
}
void book::restore(char x)
{
int i;book *s;
while(book *head)
{
if(s->bookname==x)i++;
head=head->next;
}
cout<<"Now the number of books is:"<<i<<endl;
}

搜索更多相关主题的帖子: 各位 什么 问题 
2007-04-05 18:02



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-129530-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.408414 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved