各位能不能帮我看一下这两个程序有什么问题,小弟才疏,确实没瞧出个究竟来,有劳了!
第一个
#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;
}