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; 0numBks;
// (“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
};
用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(...