| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 506 人关注过本帖
标题:[求助]各位能不能帮我看一下这两个程序有什么问题
取消只看楼主 加入收藏
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
快速回复:[求助]各位能不能帮我看一下这两个程序有什么问题
数据加载中...
 
   



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

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