A
Alex
Hi Guys,
The code presented below does not compile. Could you give me a few
suggestions to make it compile?
/*
This program creates a class called "card" that maintains a library
card
catalogue entry. The class stores a book title, author, and number of
copies
on hand. It stores the title and author as strings and the "the number
on hand"
as an integer. Using a public member function called "store()" to store
a book's
information. It uses a public member function called "show()" to
display the
information. It includes a short "main()" function to demonstrate the
class.
*/
#include <iostream>
using namespace std;
class card {
//private to class "card"
char a, b;
int c;
public:
void store_a(char title);
void store_b(char author);
void store_c(int no);
char show_a();
char show_b();
int show_c();
};
//define functions
void card::store_a(char title)
{
a = title;
cout << "Please enter the title of the book: " << "\n";
cin >> a;
return;
}
void card::store_b(char author)
{
b = author;
cout << "Please enter the author of the book: " << "\n";
cin >> b;
return;
}
void card::store_c(int no)
{
c = no;
cout << "Please enter the number of copies the library owns: " <<
"\n";
cin >> c;
return;
}
char card::show_a()
{
return a;
}
char card::show_b()
{
return b;
}
int card::show_c()
{
return c;
}
//Main function
int main()
{
do{
card s1, s2, no1;
s1.store_a();
s2.store_b();
no1.store_c();
s1.show_a();
s2.show_b();
no.show_c();
}while (a|b|c != 'exit');
return 0;
}
Thank you.
The code presented below does not compile. Could you give me a few
suggestions to make it compile?
/*
This program creates a class called "card" that maintains a library
card
catalogue entry. The class stores a book title, author, and number of
copies
on hand. It stores the title and author as strings and the "the number
on hand"
as an integer. Using a public member function called "store()" to store
a book's
information. It uses a public member function called "show()" to
display the
information. It includes a short "main()" function to demonstrate the
class.
*/
#include <iostream>
using namespace std;
class card {
//private to class "card"
char a, b;
int c;
public:
void store_a(char title);
void store_b(char author);
void store_c(int no);
char show_a();
char show_b();
int show_c();
};
//define functions
void card::store_a(char title)
{
a = title;
cout << "Please enter the title of the book: " << "\n";
cin >> a;
return;
}
void card::store_b(char author)
{
b = author;
cout << "Please enter the author of the book: " << "\n";
cin >> b;
return;
}
void card::store_c(int no)
{
c = no;
cout << "Please enter the number of copies the library owns: " <<
"\n";
cin >> c;
return;
}
char card::show_a()
{
return a;
}
char card::show_b()
{
return b;
}
int card::show_c()
{
return c;
}
//Main function
int main()
{
do{
card s1, s2, no1;
s1.store_a();
s2.store_b();
no1.store_c();
s1.show_a();
s2.show_b();
no.show_c();
}while (a|b|c != 'exit');
return 0;
}
Thank you.