Friday, May 22, 2020

CS301 Assignment 1 solution 2020 with Download file and code



you can copy code as well.


==================
#include <iostream>
using namespace std;
class Books{
private:
int current;
int books;
int size;
int *stack;
public:
Books(int s, int b){
size = s;
stack = new int[size];
books = b;
current = -1;
}
void push(int x){
stack[++current] = x;
}
int pop(){
return stack[current--];
}
int top(){
return stack[current];
}
int isEmpty(){
return (current==-1);
}
int isFull(){
return (current == size-1);
}
};

main(){
int s, b, id;
int s_books = 0;
int h_books = 0;
int o_books = 0;
cout << "Set the size of stack: " <<endl;
cin >> s;
cout << "How many books you want to add in stack" <<endl;
cin >> b;
Books book(s,b);
for(int i = 0; i < b; i++){
if(!book.isFull()){
cout << "Enter book identity number that you want to insert into stack" <<endl;
cin >> id;
book.push(id);
}
}
for(int i = 0; i < b; i++){
if(!book.isEmpty()){
int idd = book.pop();
if(idd%8==0){
s_books++;
}
else if(idd%5==0){
h_books++;
}
else{
o_books++;
}
}
}
if(b > 0){
cout << "total software book/books " << s_books <<endl;
cout << "total hardware book/books " << h_books <<endl;
cout << "total other book/books" <<o_books <<endl;
}else{
cout << "books not found";
}
}

No comments:

Post a Comment