Sponsored
cs301 assignment solutio 2020
#include<iostream>
using namespace std;
class MYBooks
{
private :
int current;
int books;
int size;
int *stack;
public :
MYBooks(int s, int b)
{size=s;
stack= new int[size];
books=b;
current=-1;
}
void push(int x)
{
// -1 +1=0
stack[++current]=x;
}
int pop()
{
return stack[current--];
}
int top()
{
return stack[current];
}
int isEmpty()
{
return (current==-1);
}
int isFull()
{
//5 4
return (current==size-1);
}

};

main()
{

int s, b, id;
int s_books=0, h_books=0, o_books=0;
cout<<"set the size of stack : ";
cin>>s;
cout<<endl;
cout<<"Number of books you want to add in stack : ";
cin>>b;
MYBooks book(s,b);
//b =5
for(int i=0; i<b; i++)
{
if(!book.isFull())
{
cout<<endl;
cout<<"Enter book id number that you want to insert into stack :";
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<<endl;
cout<<"Total Software Books : "<<s_books;
cout<<endl;
cout<<"Total Hardware Books : "<<h_books;
cout<<endl;
cout<<"Total Other Books : "<<o_books;
}
else
{
cout<<endl;
cout<<"Books not found";
}
}
cs301 assignment solutio 2020 #include<iostream> using namespace std; class MYBooks { private : int current; int books; int size; int *stack; public : MYBooks(int s, int b) {size=s; stack= new int[size]; books=b; current=-1; } void push(int x) { // -1 +1=0 stack[++current]=x; } int pop() { return stack[current--]; } int top() { return stack[current]; } int isEmpty() { return (current==-1); } int isFull() { //5 4 return (current==size-1); } }; main() { int s, b, id; int s_books=0, h_books=0, o_books=0; cout<<"set the size of stack : "; cin>>s; cout<<endl; cout<<"Number of books you want to add in stack : "; cin>>b; MYBooks book(s,b); //b =5 for(int i=0; i<b; i++) { if(!book.isFull()) { cout<<endl; cout<<"Enter book id number that you want to insert into stack :"; 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<<endl; cout<<"Total Software Books : "<<s_books; cout<<endl; cout<<"Total Hardware Books : "<<h_books; cout<<endl; cout<<"Total Other Books : "<<o_books; } else { cout<<endl; cout<<"Books not found"; } }
Love
1
0 Comments 0 Shares 18 Views 0 Reviews
Sponsored
Sponsored
Virtual Friends

VU Friends

We are dispersed but we are together. We don't know each other face to face But we all know each other by Virtulians We have no classmates But after all we are all classmates. We can't do anything physically for each other  But we are doing everything for each other. That why we are Virtualians.