帮我改一下C++程序

来源:百度知道 编辑:UC知道 时间:2024/05/13 23:50:04
我做的跟书上的一模一样,但出现错误。

#include<iostream>
#include<cstdlib>
using namespace std;

struct Student
{
int id; //学号
float gpe; //平均分
};

template<class T>
class Store
{
private :
T item;
int haveValue;

public:
Store(void); //默认构造函数

T GetElem(void); //提取数据函数
void PutElem(T x); //存入数据函数

};

template<class T>
Store<T>::Store(void):haveValue(0) // ?
{}
template<class T>
T Store<T>::GetElem(void)
{
if(haveValue==0)
{
cout<<"NO item present !"<<endl;
exit(1); //使程序完全退出,返回到操作系统
//参数可以用来表示程序终止的原因,可以被操作系统接收
}
return item
}
template<class T>
void Store<T>::PutElem(T x)
{
haveValue++; //
item=x;
}

有三种错误:
1.main后面丢失圆括号
应为: main()

2.有一个分号不是英文状态下的,还丢了一个分号
template<class T>
class Store
{
private :
T item;
int haveValue;

public:
Store(void); //默认构造函数

T GetElem(void); //提取数据函数
void PutElem(T x); //存入数据函数

}; //就是这个分号
template<class T>
T Store<T>::GetElem(void)
{
if(haveValue==0)
{
cout<<"NO item present !"<<endl;
exit(1); //使程序完全退出,返回到操作系统
//参数可以用来表示程序终止的原因,可以被操作系统接收
}
return item //丢分号了!!!!!!!!
}
3.函数的名字.大小写都没分清楚,例如 cout<<D.GeTElem()<<endl;

错误不少..现在给出正确的:

#include<iostream>
#include<cstdlib>
using namespace std;

struct Student
{
int id; //学号
float gpe; //平均分
};

template<class T>
class Store
{
private :
T item;
int haveValue; <