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

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;
}
...全文
93 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
工作量大啊,祝你好运!
??
怎样减少??
为什么??
  • 打赏
  • 举报
回复
工作量大啊,祝你好运!
  • 打赏
  • 举报
回复
相关推荐
private void button3_Click(object sender, EventArgs e) { string number = textBox2.Text; string bookname = textBox3.Text; string press = textBox4.Text; string name = textBox6.Text; string price = textBox5.Text; DateTime dt= dateTimePicker1.Value; string bookid = dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); MessageBox.Show(bookid); string sql1 = "update book set number='{0}',bookname ='{1}',press='{2}',price='{3}',dt='{4}'where bookid ='{5}' "; sql1 = string.Format(sql1,number, bookname,press,price,dt,bookid); string sql2 = "update categorybook set name='{0}'where categoryid in(select categoryid from book where bookid='{1}')"; sql2 = string.Format(sql2, name, bookid); SqlConnection conn = new SqlConnection(); conn.ConnectionString="server=20110810-1559\\SQLEXPRESS;database=stums;integrated security=true"; //conn.ConnectionString = "server=XP-201108091130\\SQLEXPRESS;database=stums;uid=sa;pwd=0"; conn.Open(); SqlTransaction st = conn.BeginTransaction(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; try { cmd.CommandText = sql1; cmd.ExecuteNonQuery(); cmd.CommandText = sql2; cmd.ExecuteNonQuery(); st.Commit(); Showmsg(); MessageBox.Show("修改成功"); } catch { MessageBox.Show("修改失败"); } } private void button9_Click(object sender, EventArgs e) { if (dataGridView1.RowCount > 0) { dataGridView1.SelectAll(); } } private void button10_Click(object sender, EventArgs e) { while(dataGridView1.SelectedRows.Count > 0) { DataGridViewRow dv = dataGridView1.SelectedRows[0]; dv.Selected = false; } } private void button11_Click(object sender, EventArgs e) { string sql = "select * from book "; SqlConnection conn = new SqlConnection("server=20110810-1559\\SQLEXPRESS;database=stums;integrated security=true"); //SqlConnection conn = new SqlConnection("server=XP-201108091130\\SQLEXPRESS;database=stums;uid=sa;pwd=0"); conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { ListViewItem lvi = new ListViewItem(); lvi.Text = sdr["number"].ToString(); lvi.SubItems.Add(sdr["bookname"].ToString()); lvi.SubItems.Add(sdr["price"].ToString()); listView1.Items.Add(lvi); } sdr.Close(); conn.Close(); }
#include //#include"book.h" #include "string" using namespace std; #define Null 0 #define MAX 5 //图书结构体 typedef struct Book { char Bookname[20];//图书名称 char BookID[10]; //图书号 float Price; //图书价格 char Author[5]; //作者 int Number; //图书数量 struct Book * struct Book *next; }Book; //会员结构体 typedef struct VIP { char VIPname[10]; char Sex[2]; char Xuehao[5]; char BookID[MAX][10]; struct VIP *next; }VIP; //book *Cusrear; //Replace *Reprear; void BookInsert(Book *head)//录入图书基本信息 { Book *p; int i=0; while (i!=1) { p=new Book; cout<<"请输入图书名称:"<>p->Bookname; cout<<"请输入图书号:"<>p->BookID; cout<<"请输入价格:"<>p->Price; cout<<"请输入作者名称:"<>p->Author; cout<<"请输入图书数量:"<>p->Number; p->next=head->next; head->next=p; cout<<"1、返回主菜单 2、继续"<>i; //rear->next=p;// 利用尾指针便于图书的添加 //rear=p; //rear->next=Null; } } void BookSearch(Book *head)//查询图书 { Book *p; char Bookname[20]; int i=0; while (i!=1) {cout<<"请输入需要查询的图书名称:"<>Bookname; p=head; while(p&&strcmp(p->Bookname,Bookname)) { p=p->next; } if(p==Null) {cout<<"对不起不存在该图书"<图书名称:"<Bookname; cout<<" 图书号:"<BookID; cout<<" 价格:"<Price; cout<<" 作者名称:"<Author; cout<<" 图书数量:"<Number<>i; } } void BookDelete(Book *head) //利用表头指针定位要删除的图书信息 { Book *p,*q; char Bookname[20]; int i=0; while(i!=1) {cout<<"请输入需要删除的图书信息:"<>Bookname; p=head; while(p->next&&strcmp(p->next->Bookname,Bookname)) {p=p->next;} q=p->next; if(q!=Null) { // if(q->next==Null) // {rear=p;} p->next=p->next->next; delete q;} else {cout<<"你所要删除的图书不存在"<>i; } } void NEWVIP(VIP *head) { VIP *p; int i=0; while (i!=1) { p=new VIP; cout<<"请输入您的会员名称:"<>p->VIPname; cout<<"请输入您的会员性别:"<>p->Sex; cout<<"请输入您的会员学号:"<>p->Xuehao; cout<<"恭喜您注册成功!"<next=head->next; head->next=p; cout<<"1、返回主菜单 "<>i; } } void BBook(Book *head)//借书函数 { int Book_Amount; Book *p; char Bookname[10]; int i=2; while(i!=1) {cout<<"请输入图书名称:"<>Bookname; p=head; while(p&&strcmp(p->Bookname,Bookname)) {p=p->next; } if (p==Null) {cout<<"对不起不存在此图书"<>Book_Amount; while(Book_Amount==0) { cout<<"请输入一个非零数"<>Book_Amount; } if(Book_Amount<=p->Number) {cout<<"借书成功!"<>i; } } } } void Borrowbook(VIP *head)//借书 { VIP *p; char VIPname[10],Bookname[20]; int i=0; while(i!=1) {cout<<"请输入会员名称:"<>VIPname; p=head; while(p&&strcmp(p->VIPname,VIPname)) { p=p->next; } if (p!=Null) { void BBook(Book *head); } else { cout<<" 对不起您不是会员"<>VIPname; p=head; while(p&&strcmp(p->VIPname,VIPname)) { p=p->next; } if(p==NULL) {cout<<"请输入正确的会员名!!"<>Bookname; q=head; while(q&&strcmp(q->Bookname,Bookname)) {q=q->next;} { q->Number+=Number; } } void main() { Book *head,*rear; VIP *L; L=new VIP; L->next=Null; head=rear=new Book; head->next=Null; rear->next=Null; char i='0'; while(i!='7') { cout<<"********图书管理系统*********"<图书基本信息 5、还书"<图书基本信息查询 6、统计图书库存和已借图书数量"<图书基本信息 7、退出系统"<图书借阅"<>i; switch(i) {case '1': BookInsert(head );break; case '2': BookSearch(head);break; case '3': BookDelete(head);break; case '4': Borrowbook(L);break; case '5': Returnbook(head);break; case '6': FlightCancelTicket(head);break; case '7':break; default:cout<<"error\n";break; } } }
发帖
VC/MFC

1.6w+

社区成员

VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
帖子事件
创建了帖子
2004-05-05 07:25
社区公告

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