Get premium membership and access questions with answers, video lessons as well as revision papers.

1. Create a class called card that maintains a library catalog entry.Have the class store a book's tittle,author,and number of copies on hand.Store the tittle and...

      

1. Create a class called card that maintains a library catalog entry. Have the class store a book's tittle,author,and number of copies on hand.Store the tittle and author as string and the number on hand as an integer.Use a public member function called show() to display the information. Include a short main() function to demonstrate the class.

2.Create a queue class that maintains a circular queue of integers.Make the queue size 100 long.Include a short main() function that demonstrates its operation.

  

Answers


Davis
1.#include
#include
using namespace std;
class card {
char tittle[80]; //book title
char author [40]; //author
int number // number in library
public:
void store (char *t, char *name, int num) ;
void show ();
};
void card::store(char *t, char *name, int num)
{
strcpy (title, t);
strcpy (author, name);
number = num;
}
void card::show(){
cout << "Title: "<cout <<"Author: " <cout << "Number on hand: " << number << "\n";
}
int main()
{
card book 1, book2, book3;
book1.store("Dune", "Frank Herbert", 2);
book2.store("The Foundation Trilogy", "Isaac Asimov", 2);
book3.store("The Rainbow", "D.H.Lawrence", 1);
book1.show();
book2.show();
book3.show();
return 0;
}


2.#include
using namespace std;
define SIZE 100
class q_type {
int queue [SIZE]; //holds the queue
int head, tail; //indices of head and tail.
public:
void init(); //initialize
void q(int num); //store
int deq(); //retrieve
};
//Initialize
void q_type::init()
{
head = tail=0;
}
//put value on a queue.
void q_type::q(int num)
{
if (tail+1==|| (tail + 1==SIZE && !head)) {
cout << "Queue is full \n";
return;
}
tail++;
if(tail==SIZE) tail= 0 //cycle round
queue[tail] = num;
}
//Remove a value from a queue.
int q_type::deq()
{
if(head == tail) {
cout << "Queue is empty\n";
return 0; //or some other error indicator
}
head++;
if(head==SIZE) head =0; //cycle around
return queue[head];
}
int main()
{
q_type q1, q2;
int i;
q1.init();
q2.init();
for(i=1; i<=10; i++){
q1.q(i);
q2.q(i*i);
}
for(i=1; i<=10; i++) {
cout <<"Dequeue 1: "<cout <<"Dequeue 1: "<}
return 0;
}
Githiari answered the question on May 2, 2018 at 19:18


Next: Explain factors that makes it difficult for Kenyans to purchase houses through building societies
Previous: Name a town in Kenya where the following industries are found 1. Textiles 2. Cement manufacturing

View More Computer Studies Questions and Answers | Return to Questions Index


Learn High School English on YouTube

Related Questions