C++ 一个程序编写..谢谢 谢谢了!

As the president of a local book club and a software engineer, Michael Luis decides to design a software system to manage each club member’s personal book library. Michael has designed two classes—Book and PersonalLibrary—to store the information of a book and that of a person’s library respectively. The interfaces of the two classes are provided as follows. Now, assume you have been hired by Michael to implement this software system. Your tasks will include the following:
• Implement these two classes using separate compilation
• Use these two classes to manage a personal library. It is assumed that a person has at most 100 books in his or her library.
• Provide an interactive interface to build a personal library. Your program will first prompt the end-user to type in the general information of a person (name, email and number of books). It will then prompt the user to type in a book's title, author and year from the keyboard until all the books have been added to the library. This interface will be kept active until the user decides to quit.

class Book{
public:
Book(); //constructor: “NA”->title, “NA”->author, 1900->year
Book(string t, string a, int yr); //constructor: t->title,
//a->author, yr->year
void set_title(string t); //set the title of a book to tit
void set_author( string a); //set the author of a book to aut
void set_year( int yr); //set the year of a book to yr
string get_title(); //return the title of the book
string get_author(); //return the author of the book
int get_year(); //return the year in which a book was published
void print(); //print out the information of a book: title, author, and year

private:
string title; //title of a book
string author; //the author of a book, only the first author is stored
int year; //the year in which a book is published
};

class PersonalLibrary
{
private:
string name; // name of the person who owns the libarary
string email; //email of the person
int numBks; // #books in a person’s library
Book bkList[100]; //the list of books in the library

public:
PersonalLibrary(); // “NA”name, email; 0numBks;
// (“NA”, “NA”, 1990)bkList[i] (0≤i≤99)
string get_pname(); //return the person’s name
string get_email(); //return the person’s e-mail
string get_title( int i); //return the title of the ith book in the library
void set_pname(string nm); //set a person’s name to nm
void set_email(string eml); //set a person’s email address to eml
int add_book( Book new_book); //add new_book to the person’s
//library and return the total number of books after this
//new addition. If a person already has 100 books,
//replace the last book on the list with this new_book.
void get_numBks(); //return the number of books a person has
void print(); //print out the entire list of books a person has
};

#include<iostream>
#include<string>
using namespace std;
class book{
public:
book(); //constructor: “NA”->title, “NA”->author, 1900->year
book(string t, string a, int yr); //constructor: t->title,
//a->author, yr->year
void set_title(string t); //set the title of a book to tit
void set_author( string a); //set the author of a book to aut
void set_year( int yr); //set the year of a book to yr
string get_title(); //return the title of the book
string get_author(); //return the author of the book
int get_year(); //return the year in which a book was published
void print(); //print out the information of a book: title, author, and year

private:
string title; //title of a book
string author; //the author of a book, only the first author is stored
int year; //the year in which a book is published
};

book::book()
{
title="NA";
author="NA";
year=1900;
}

book::book(string t, string a, int yr)
:title(t),author(a),year(yr){}

void book::set_title(string t)
{
title=t;
}

void book::set_author(string a)
{
author=a;
}

void book::set_year(int yr)
{
year=yr;
}

string book::get_title()
{
return title;
}

string book::get_author()
{
return author;
}

int book::get_year()
{
return year;
}

void book::print()
{
cout<<"Title:"<<title<<endl;
cout<<"Author:"<<author<<endl;
cout<<"Year:"<<year<<endl;
}

//我这里没有编译器,你先看看,出问题再告诉我。
//////////////////////////////////////////
class PersonalLibrary
{
private:
string name; // name of the person who owns the libarary
string email; //email of the person
int numBks; // #books in a person’s library
book bkList[100]; //the list of books in the library

public:
PersonalLibrary(); // “NA”?name, email; 0?numBks;
// (“NA”, “NA”, 1990)?bkList[i] (0≤i≤99)
string get_pname(); //return the person’s name
string get_email(); //return the person’s e-mail
string get_title( int i); //return the title of the ith book in the library
void set_pname(string nm); //set a person’s name to nm
void set_email(string eml); //set a person’s email address to eml
int add_book( book new_book); //add new_book to the person’s
//library and return the total number of books after this
//new addition. If a person already has 100 books,
//replace the last book on the list with this new_book.
int get_numBks(); //return the number of books a person has
void print(); //print out the entire list of books a person has
};

PersonalLibrary::PersonalLibrary():
name("NA"),email("NA"),numBks(0)
{

}
string PersonalLibrary::get_pname(){return name;}
string PersonalLibrary::get_email(){return email;}
string PersonalLibrary::get_title(int i){return bkList[i].get_title();}
void PersonalLibrary::set_pname(string nm){name=nm;}
void PersonalLibrary::set_email(string eml){email=eml;}
int PersonalLibrary::add_book(book new_book)
{

bkList[numBks]=new_book;
if(numBks<98) numBks++;

return numBks;
}
int PersonalLibrary::get_numBks(){return numBks;}
void PersonalLibrary::print()
{
cout<<"The owner is:"<<name<<endl;
cout<<"Email of the person:"<<email<<endl;
cout<<"The total books is:"<<numBks<<endl;

for(int i=0;i<numBks;i++)
{
bkList[i].print();
}
}

void main()
{
string title_1("Ma");
string name_1("Tom");
int year_1=1993;
book b1(title_1,name_1,year_1);
//b1.print();
string title_2("Ma2");
string name_2("Tom2");
int year_2=1994;
book b2(title_2,name_2,year_2);

string pn("ahau");
string em("ahaubit@163.com");

PersonalLibrary pl;
pl.set_pname(pn);
pl.set_email(em);

pl.add_book(b1);
pl.add_book(b2);

pl.print();

}
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-09-30
我可以很负责任地告诉你,这个问题不难,但是要花相当的时间,起码半个小时到一个小时甚至要到两个小时才能搞定,作为这个百度知道的问题。。我看我没有这么多时间帮你。。如果有需要我可以给你提供点思路。。
第2个回答  2009-09-30
#include <iostream>
#include <string>
using namespace std;

class Book{
public:
Book(); //constructor: “NA”->title, “NA”->author, 1900->year
Book(string t, string a, int yr); //constructor: t->title,
//a->author, yr->year
void set_title(string t); //set the title of a book to tit
void set_author( string a); //set the author of a book to aut
void set_year( int yr); //set the year of a book to yr
string get_title(); //return the title of the book
string get_author(); //return the author of the book
int get_year(); //return the year in which a book was published
void print(); //print out the information of a book: title, author, and year

private:
string title; //title of a book
string author; //the author of a book, only the first author is stored
int year; //the year in which a book is published
};
Book::Book() //constructor: “NA”->title, “NA”->author, 1900->year
{
title="";
author="";
year=1990;
}
Book::Book(string t, string a, int yr) //constructor: t->title,
{
title=t;
author=a;
year=yr;
}
//a->author, yr->year
void Book::set_title(string t) //set the title of a book to tit
{
title=t;
}
void Book::set_author( string a) //set the author of a book to aut
{
author=a;
}
void Book::set_year( int yr) //set the year of a book to yr
{
year=yr;
}
string Book::get_title() //return the title of the book
{
return title;
}
string Book::get_author() //return the author of the book
{
return author;
}
int Book::get_year() //return the year in which a book was published
{
return year;
}
void Book::print() //print out the information of a book: title, author, and year
{
cout<<"title :"<<title<<endl;
cout<<"author :"<<author<<endl;
cout<<"year :"<<year<<endl;
}
class PersonalLibrary
{
private:
string name; // name of the person who owns the libarary
string email; //email of the person
int numBks; // #books in a person’s library
Book bkList[100]; //the list of books in the library

public:
PersonalLibrary(); // “NA”?name, email; 0?numBks;
// (“NA”, “NA”, 1990)?bkList[i] (0≤i≤99)
string get_pname(); //return the person’s name
string get_email(); //return the person’s e-mail
string get_title( int i); //return the title of the ith book in the library
void set_pname(string nm); //set a person’s name to nm
void set_email(string eml); //set a person’s email address to eml
int add_book( Book new_book); //add new_book to the person’s
//library and return the total number of books after this
//new addition. If a person already has 100 books,
//replace the last book on the list with this new_book.
int get_numBks(); //return the number of books a person has
void print(); //print out the entire list of books a person has
};
PersonalLibrary::PersonalLibrary() // “NA”?name, email; 0?numBks;
{
name="";
email="";
numBks=0;
for(int i=0;i<100;i++)
{
bkList[i]=Book();
}
}
// (“NA”, “NA”, 1990)?bkList[i] (0≤i≤99)
string PersonalLibrary::get_pname() //return the person’s name
{
return name;
}
string PersonalLibrary::get_email() //return the person’s e-mail
{
return email;
}
string PersonalLibrary::get_title( int i) //return the title of the ith book in the library
{
if(i>99||i<0) return "";
return bkList[i].get_title();
}
void PersonalLibrary::set_pname(string nm) //set a person’s name to nm
{
name=nm;
}
void PersonalLibrary::set_email(string eml) //set a person’s email address to eml
{
email=eml;
}
int PersonalLibrary::add_book( Book new_book) //add new_book to the person’s
{
if(numBks>=0 && numBks<=99)
{
bkList[numBks++]=new_book;
}
else
{
bkList[numBks-1]=new_book;
}
return numBks;
}
//library and return the total number of books after this
//new addition. If a person already has 100 books,
//replace the last book on the list with this new_book.
int PersonalLibrary::get_numBks() //return the number of books a person has
{
return numBks;
}
void PersonalLibrary::print() //print out the entire list of books a person has
{
cout<<"name :"<<name<<endl;
cout<<"email :"<<email<<endl;
cout<<"book_num :"<<numBks<<endl;
for(int i=0;i<numBks;i++)
{
bkList[i].print();
}
}

void main()
{
Book bk1,bk2,bk3,bk4;
bk1.set_title("terrywang");
bk2.set_title("asfsf");
bk3.set_title("aaaaaaaaaaaaaaa");
bk4.set_title("nononono");
PersonalLibrary per;
per.add_book(bk1);
per.add_book(bk2);
per.add_book(bk3);
per.add_book(bk4);
per.print();
}

花了30分钟编码,20分钟调试。
直接贴到编辑器上就能编译通过了,我已经调试过

用c++编写一个程序,要求创建一个类,输入若干个学生的数据,包括学号,姓名...
s[i].total = 0;for (int j = 0; j < 3; j++){cout << "输入第" << j + 1 << "门课的成绩:";cin >> s[i].subject[j];s[i].total += s[i].subject[j];}cout << endl;} void Student::sort(Student s[], int n){for (int i = 0; i < n-1; i++){f...

用C++编写一个程序,统计字母个数。??
1、连接运算 concat(s1,s2,s3…sn) 相当于s1+s2+s3+…+sn.例:concat(‘11’,'aa’)='11aa’;2、求子串。 Copy(s,I,I) 从字符串s中截取第I个字符开始后的长度为l的子串。例:copy(‘abdag’,2,3)=’bda’3、删除子串。过程 Delete(s,I,l) 从字符串s中删除第I个字符开始后的长...

题目描述如下,请用C++语言编写,谢谢!!!
include<iostream>#include<cstdio>\/\/#include<algorithm>using namespace std;void my_sort(char s[][128],int n){ int i,j; char temp[128]; for (i=0; i<n-1; i++) { for (j=0; j<n-1-i; j++) { if(strcmp(s[j],s[j+1])<0) { strcpy(temp,s[j])...

c++ 编写一个程序,要求输入两个数a和b,计算出a和b的和,差,积,并输出...
int main(void){int a, b;printf("请输入第一个整数\\n");scanf("%d", &a);printf("请输入第二个整数(注意!这个数不能为零)\\n");scanf("%d", &b);while (b==0){printf("你输入了零!请重新输入!\\n");scanf("%d", &b);if (b!=0) break;}printf("%d+%d=%d\\n", a...

c++如何编写一个程序
第一步:打开终端,随便进入一个文件夹,用于存放你编写的程序。在终端中,输入命令"vi Hello.cpp",其中Hello.cpp是你的源文件名。第二步:进入vi编辑器,按“i”键开始输入代码。输入你的C++代码后,按“Esc”键退出编辑模式。第三步:保存并退出vi编辑器。在命令行中输入“:wq”,然后按“Enter...

C++编写一个程序,从键盘上输入5个整数,输出最大值
帮你写了一个如下:include <stdio.h>int main(){ int a[5]; for(int i=0;i<5;i++) { printf("请输入第%d个整数:",i+1); scanf("%d",&a[i]); } int max=a[0],min=a[0]; for(i=0;i<5;i++) { if(maxa[i]) min = a[i]; } printf("这组数中最大...

C语言(最好C++)编一下这个程序
若女利用Fp链接进以 printf("Pls enter the information of teacher:\\n注意中间一空格间隔,性别只可为大写的F或M,Ex:张三 187 M\\n");for (int i = 0; i < n; i++){ cin >> teacher->name >> teacher->weight >> teacher->sex;if (teacher->sex == 'M')...

如何使用DEV C++软件编写一个简单的程序?
1、首先打开我们的DEV C++软件,点击“新建源代码”。在编辑页面输入以下源代码:include <stdio.h> int main( ){ int *p;int i,a[5];float sum=0,average;p=a;printf("please input 5 numbers:");for(i=0;i<5;i++)scanf("%d",&a[i]);for(p=a;p<(a+5);p++)sum=sum+*p;a...

帮忙解决一下这个程序设计题,用C++写.谢谢
include <string.h> char * copy(char *a, int m, int n){ static char tmp[255];strncpy(tmp, a+m, n);return tmp;} int main(){ char a[255];int m, n;printf("输入字符串:\\n");gets(a);printf("输入m n:\\n");scanf("%d %d", &m, &n);puts(copy(a, m, n));...

大佬,能帮忙用devc++编个c语言程序,输入年月日,天数n,输出n天后的年月...
\/**程序描述:输入年月日,天数n,输出n天后的年月日。*\/#include <stdio.h>typedef struct Date{int year;int month;int day;}Date;int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};int IsLeapYear(int year);void ListDate(Date now, int diff);void main(...

相似回答