我想编一个图书管理系统:

kurt8276 2004-05-05 07:25:50
我想编一个图书管理系统:
我设计里一个基类:object
book类:public object
可是编译为马说从定义类:object??
程序如下:
//object.h
/////////////////////////////////////////////////////////////////////////////////////

/////////////
/////// this is base class ! book class,reader class and librarian class from

lllllobject!!
///////Attribute: index,name!
///////operator: Getname,Setname!
///////
///////2004.5.7 zk
///////
/////////////////////////////////////////////////////////////////////////////////////

/////////////
#include<iostream>
#include<string>
using namespace std;

class object
{
private:
int index;
string name;
public:
object();
object(int,string);
// ~object();i can not write code !!so bad!!dont forget it!!
virtual string Getname();
virtual int Getindex();
virtual const object& Getobject();
virtual void Setname(string);
virtual void Setindex(int);
void Setobject(const object);
const object& operator=(const object& );
};
//object.cpp
#include<iostream>
#include<string>
#include"object.h"
using namespace std;

object::object()
{
index=-1;
name ="无";
}
object::object(int i,string n):index(i),name(n)
{}
int object::Getindex()
{return index;}
string object::Getname()
{return name;}
const object& object::Getobject()
{return *this;}
void object::Setindex(int i)
{index=i;}
void object::Setname(string n)
{name=n;}
void object::Setobject(const object o)
{*this=o;}
const object& object::operator=(const object& o)
{
index=o.index;
name=o.name;
return *this;
}
//book.h
/////////////////////////////////////////////////////////////////////////////////////

////////////
//////this is book class! public:object!
//////Attribute:index,bookname,writername,publishing company ,state

(borrow),remark,CDROM,Filename
//////operator:Checkout,ShowData,Setbookname,Setindex,Set..
//////Getbookename.........Get..
//////2004.5.7 zk
/////////////////////////////////////////////////////////////////////////////////////

////////////
#include<iostream>
#include<string>
#include"object.h"
using namespace std;
class book :public object
{
private:
// int index;
// string bname;
string wname;
string pubcomname;
bool state;
string remark;
bool CDROM;
//static const char FileName[15];
public:
book();
book(int i,string bookname,string writername,string publishcompany,bool

s,bool CDROM,string r);
book(int i,string bookname,string writername,string publishcompany,bool s,bool

CDROM);
//~book();
void Setindex(int);
void Setbookname(string);
void Setwritername(string);
void Setpublishcompany(string);
void Setstate(bool);
void SetCDROM(bool);
void Setremark(string);

int Getindex(void);
string Getbookname(void);
string Getwritername(void);
string Getpublishcompany(void);
bool Getstate(void);
bool GetCDROM(void);
string Getremark(void);

void CheckOut();
};
//const char book::FileName[15]="Book.txt";
//const char *book::GetFileName();
//book.cpp
#include<iostream>
#include<string>
#include"object.h"
#include"book.h"
using namespace std;
book::book()
{
object() ;
// index=-1;
// bname="无";
wname="无";
pubcomname="无";
state=0;
remark="三无";
CDROM=0;
}
book::book(int i,string bookname,
string writername,string publishcompany,
bool s,bool c,string r)
{
object(i,bookname) ;
//index=i;
// bname=bookname;
wname=writername;
pubcomname=publishcompany;
state=s;
remark=r;
CDROM=c;
}
book::book(int i,string bookname,string writername,string publishcompany,bool s,bool

c)
{
object(i,bookname) ;
// index=i;
// bname=bookname;
wname=writername;
pubcomname=publishcompany;
state=s;
remark="";
CDROM=c;
}
void book::Setindex(int i)
{object::Setindex(i);}
void book::Setbookname(string n)
{object::Setname(n);}
void book::Setwritername(string w)
{wname=w;}
void book::Setpublishcompany(string pc)
{pubcomname=pc;}
void book::Setstate(bool s)
{state=s;}
void book::SetCDROM(bool CD)
{CDROM=CD;}
void book::Setremark(string r)
{remark=r;}
int book::Getindex(void)
{return object::Getindex();}
string book::Getbookname(void)
{
//return bname;
return object::Getname();
}
string book::Getwritername(void)
{return wname;}
string book::Getpublishcompany(void)
{return pubcomname;}
bool book::Getstate(void)
{return state;}
bool book::GetCDROM(void)
{return CDROM;}
string book::Getremark(void)
{return remark;}
void book::CheckOut()
{
if (state==0)
throw("Book is not in library!");
state=0;
}
...全文
75 14 点赞 打赏 收藏 举报
写回复
14 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
wangyangcheng 2004-06-10
楼主的东东做完了吗?
可否交流一下,我也想做一个。
  • 打赏
  • 举报
回复
kurt8276 2004-05-06
//////////////////////////////////////////////////////////////////////////////////////////////////
/////// this is base class ! book class,reader class and librarian class from lllllobject!!
///////Attribute: index,name!
///////operator: Getname,Setname!
///////
///////2004.5.7 zk
///////
//////////////////////////////////////////////////////////////////////////////////////////////////
/*#include<iostream>
#include<string>
using namespace std;
class object
{
private:
int index;
string name;
public:
object();
object(int,string);
// ~object();i can not write code !!so bad!!dont forget it!!
string Getname();
int Getindex();
const object& Getobject();
void Setname(string);
void Setindex(int);
void Setobject(const object);
const object& operator=(const object& );
};
*/
//把头文件改成这样试试

#ifndef _OBJECT_H
#define _OBJECT_H

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

class object
{
private:
int index;
string name;
public:
object();
object(int,string);
// ~object();i can not write code !!so bad!!dont forget it!!
string GetName(void);
int GetIndex(void);
const object & Getobject(void);
void SetName(string n);
void SetIndex(int);
void Setobject(const object);
const object& operator=(const object& );
};

#endif
#include<iostream>
#include<string>
#include"object.h"
using namespace std;

object::object()
{
index=-1;
name ="无";
}
object::object(int i,string n):index(i),name(n)
{}
int object::GetIndex(void)
{return index;}
string object::GetName(void)
{return name;}
const object& object::Getobject(void)
{return *this;}
void object::SetIndex(int i)
{index=i;}
void object::SetName(string n)
{name=n;}
void object::Setobject(const object o)
{*this=o;}
const object& object::operator=(const object& o)
{
index=o.index;
name=o.name;
return *this;
}
  • 打赏
  • 举报
回复
kurt8276 2004-05-06
//////////////////////////////////////////////////////////////////////////////////////////////////
/////this is a reader class! public:object
/////attribute:index,name,sex,age,phone,remark,address,..
/////options:borrowbook,give back book,show data,and set........Get..........
/////
/////2004.5.7 zk
//////////////////////////////////////////////////////////////////////////////////////////////////
#include<iostream>
#include<string>
#include "object.h"
using namespace std;


class reader:public object
{
private:
string sex;
int age;
string adpartment;
string phone;
string profession;
string address;
string remark;
static const char FileName[15];
public:
reader();
reader(int i,string name,string s,int ag,string a,string ph,string pr,string ad="",string remark="");

void SetIndex(int i);
void SetName(string n);
void Setsex(string s);
void Setage(int a);
void Setadpartment(string a);
void Setphone(string p);
void Setprofession(string p);
void Setaddress(string a);
void Setremark(string r);

int GetIndex();
string GetName();
string Getsex();
int Getage();
string Getadapartment();
string Getphone();
string Getprofession();
string Getaddress();
string Getremark();

// void showdata();
void Borrowbook(int i);
void giveback(int i);
////
static const char *GetFileName(){return FileName;}
};
#include<iostream>
#include<string>
#include"object.h"
#include"reader.h"
using namespace std;
reader::reader():object()
{
sex="";
age=0;
adpartment="";
phone="";
profession="";
address="";
remark=" ";
}
reader::reader(int i,string name,string s,
int ag,string a,string ph,string pr,
string ad,string r):object(i,name)
{
sex=s;
age=ag;
adpartment=a;
phone=ph;
profession=pr;
address=ad;
remark=r;
}

void reader::SetIndex(int i)
{object::SetIndex(i);}
void SetName(string n)
{object::SetName(n);}
void reader::Setsex(string s)
{sex=s;}
void reader::Setage(int a)
{age=a;}
void reader::Setadpartment(string a)
{adpartment=a;}
void reader::Setphone(string p)
{phone=p;}
void reader::Setprofession(string p)
{profession=p;}
void reader::Setaddress(string a)
{address=a;}
void reader::Setremark(string r)
{remark=r;}

int reader::GetIndex()
{return object::GetIndex();}
string reader::GetName()
{return object::GetName(); }
string reader::Getsex()
{return sex;}
int reader::Getage()
{return age;}
string reader::Getadapartment()
{return adpartment;}
string reader::Getphone()
{return phone;}
string reader::Getprofession()
{return profession;}
string reader::Getaddress()
{return address;}
string reader::Getremark()
{return remark;}


void reader::Borrowbook(int i)
{
// for
}

void reader::giveback(int i)
{}
  • 打赏
  • 举报
回复
kurt8276 2004-05-06
有问题了??
SetName(string)??
--------------------Configuration: library - Win32 Debug--------------------
Compiling...
reader.cpp
D:\MyProjects\library\reader.cpp(33) : error C2352: 'object::SetName' : illegal call of non-static member function
d:\myprojects\library\object.h(51) : see declaration of 'SetName'
Error executing cl.exe.

reader.obj - 1 error(s), 0 warning(s)

  • 打赏
  • 举报
回复
只有改类名了哈,对C++不熟,不知道用namespace能不能结决。
  • 打赏
  • 举报
回复
lxwq 2004-05-05
object 是你写的吗?

你是不可以重定义的:(
  • 打赏
  • 举报
回复
kurt8276 2004-05-05
郁闷

  • 打赏
  • 举报
回复
kurt8276 2004-05-05
//////////////////////////////////////////////////////////////////////////////////////////////////
/////// this is base class ! book class,reader class and librarian class from lllllobject!!
///////Attribute: index,name!
///////operator: Getname,Setname!
///////
///////2004.5.7 zk
///////
//////////////////////////////////////////////////////////////////////////////////////////////////
#include<iostream>
#include<string>
using namespace std;
class libraryobject
{
private:
int index;
string name;
public:
libraryobject();
libraryobject(int,string);
// ~libraryobject();i can not write code !!so bad!!dont forget it!!
string Getname();
int Getindex();
const libraryobject& Getobject();
void Setname(string);
void Setindex(int);
void Setobject(const libraryobject);
const libraryobject& operator=(const libraryobject& );
};
#include<iostream>
#include<string>
#include"libraryobject.h"
using namespace std;

libraryobject::libraryobject()
{
index=-1;
name ="无";
}
libraryobject::libraryobject(int i,string n):index(i),name(n)
{}
int libraryobject::Getindex()
{return index;}
string libraryobject::Getname()
{return name;}
const libraryobject& libraryobject::Getobject()
{return *this;}
void libraryobject::Setindex(int i)
{index=i;}
void libraryobject::Setname(string n)
{name=n;}
void libraryobject::Setobject(const libraryobject o)
{*this=o;}
const libraryobject& libraryobject::operator=(const libraryobject& o)
{
index=o.index;
name=o.name;
return *this;
}
  • 打赏
  • 举报
回复
kurt8276 2004-05-05
该类好像也不行
我在实施!!
爱!
  • 打赏
  • 举报
回复
countryboy 2004-05-05
你重定义了object类~~!!!
object类是你自己写的?????
C++本来自己就有一个object类,如果object类是你自己写的话,那把object的名字改一下吧~~!!

  • 打赏
  • 举报
回复
kurt8276 2004-05-05

--------------------Configuration: library - Win32 Debug--------------------
Compiling...
book.cpp
g:\program files\microsoft visual studio\myprojects\library\object.h(13) : error C2011: 'object' : 'class' type redefinition
Error executing cl.exe.

book.obj - 1 error(s), 0 warning(s)
  • 打赏
  • 举报
回复
看错了,以为要用pure c++做信息管理系统。
看看具体的提示啊
  • 打赏
  • 举报
回复
kurt8276 2004-05-05
工作量大啊,祝你好运!
??
怎样减少??
为什么??
  • 打赏
  • 举报
回复
工作量大啊,祝你好运!
  • 打赏
  • 举报
回复
相关推荐
发帖
VC/MFC
加入

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2004-05-05 07:25
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……