首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

各位大神麻烦找一下错解决方案

2012-04-02 
各位大神麻烦找一下错三个文件,但我不晓得哪里出错了.//程序9-4 两个Gadgets//文件 Ch9Gadgets.h#ifndef _

各位大神麻烦找一下错
三个文件,但我不晓得哪里出错了.

//程序9-4 两个Gadgets
//文件 Ch9Gadgets.h
#ifndef _GADGETS_H
#define _GADGETS_H

class Gadget //声明类
{
private :
int x,y,z,sum;
bool good; ?
void Validate();
void SumDate(){sum=x+y+z;}

public :
Gadget(void);
~Gadget(void);
bool GetData(void);
void WriteData(void);
};
#endif

//程序 9-4 Gadgets
// 文件 :Ch9Gadgets.cpp
#include<iostream.h>
#include"Ch9Gadegets.h"

Gadgets::Gadeget()
{
cout<<"\n Gadget 构造函数,把所有值设置为0。";
x=y=z=sum;
gool=false;
}

Gadget::~Gadget()
{
cout<<"\nGadget析构函数。";
cout<<"\n无事可做了,再见!\n";
}


bool Gadget::GetData()
{
good=false;
cout<<"\n请输入Gadget的整型数据成员x,y,z=>";
cin>>x>>y>>z;


Validata(); //检查数据的合法性
if(good==true)
{
SumData();
}
return good;
}

void Gadget::Validata()
{
//三个都大于0时数据合法
if(x>0&&y>0&&z>0)
good=true;
else
good=false;
}

void Gadget::WriteData()
{
cout<<"\n Gadget的数据:x="<<x<<"y="<<y<<"z="<<z;
cout<<"和为sum="<<sum<<endl;
}

//程序 9-4 Gadgets
//文件: GadgetsDriver.cpp
#include<iostream.h>
#include"Ch9Gadgets.h"


int main()
{
cout<<"\n\nGadget程序!\n\n";
Gadget red,blue;
bool goodred,goodblue;

cout<<"\n red Gadget:";
goodred=red.GetData();

cout<<"\n blue Gadget:";
goodblue=blue.GetData();


if(goodred==true&&goodblue==true)
{
cout<<"\n 两个Gadget对象中的数据都是合法!";

cout<<"\n red.Gadget:";
red.WriteData();

cout<<"\n bule.Gaget:";
blue.WriteData();
}
else if(goodred && !goodblue)
{
cout<<"\n red的数据合法,但blue的数据不合法!";

cout<<"\n red.Gadget:";
red.WriteData();
}
else if(!goodred && goodblue)
{
cout<<"\n blue的数据合法,但red的数据不合法!";

cout<<"\n blue。Gadget:";
blue.WriteData();
}
else
{
cout<<"\n Gadget的数据都不合法!";
}

cout<<"完毕!";
return 0;
}

[解决办法]

热点排行