-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert and remove in Q and factorial of each..cpp
More file actions
71 lines (70 loc) · 1.2 KB
/
insert and remove in Q and factorial of each..cpp
File metadata and controls
71 lines (70 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<iostream>
using namespace std;
class CLASS{
private:
int F,R,size,Q[];
public:
CLASS();
int Insert(int);
int RemoveAndFactorial();
};
CLASS::CLASS(){
F=R=-1;
cout<<"Enter Size :\n";
cin>>size;
}
int CLASS::Insert(int n){
if(R>=size-1){
cout<<"OVERFLOW\n";
return 0;
}
R++;
Q[R]=n;
if(F==-1){
F=0;
}
return 0;
}
int CLASS::RemoveAndFactorial(){
int deletedItem;
int f=1;
if(F==-1){
cout<<"UNDERFLOW\n";
return 0;
}
deletedItem=Q[F];
cout<<"Value you deleted is :"<<deletedItem;
if(F==R){
F=R=-1;
}
else{
F++;
}
for(;deletedItem>=1; deletedItem--){
f=f*deletedItem;
}
cout<<"Factorial of deleted Value is : "<<f<<endl;
return 0;
}
int main(){
CLASS obj;
int choice;
while(choice!=3){
cout<<"Enter 1 for Insertion :\n";
cout<<"Enter 2 for Deletion and Factorial of deleted Item :";
cout<<"Enter 3 to Exit :";
cin>>choice;
switch(choice){
case 1:
int num;
cout<<"Enter Number :";
cin>>num;
obj.Insert(num);
break;
case 2:
obj.RemoveAndFactorial();
break;
}
}
return 0;
}