16th mid night is the deadline, I know, excuse the delay, I was in a dilemma, couldn't decide if it was worth putting in the extra effort to shorten the codes as much as possible only to have them stolen and then to bear with some of these cheeky cucks that go "but how do we know YOU weren't the one who stole? huh? lmao rekt" anyway here it is.
Seriously NRR gtfo you unscrupulous scum. Grow a backbone.
For Copy Pasting: copyable codes are at the end of this post, scroll to the bottom.
Grade of a Student
Code:
Input:
Roll numberName
Mark in subject1
Mark in subject2
Mark in subject3
Mark in subject4
Mark in subject5
Output:
Roll number of the student
Name of the student
Grade secured by student
Processing:
Average =sum(marks[])/5if Average >= ’90’ and <= ‘100’
Grade=S
else if Average >= ’80’ and < ‘90’
Grade=A
else if Average >= ’70’ and < ‘80’
Grade=B
else if Average >= ’60’ and < ‘70’
Grade=C
else if Average >= ’50’ and < ‘60’
Grade=D
else if Average >= ’40’ and < ‘50’
Grade=E
else Grade=F
Psuedocode:
start
input roll,name,m[1],m[2],m[3],m[4],m[5]
if m[1 to 5]<0
output NegativeMarkException
else if m[1 to 5]>100
output OutofRangeException
else
let Average =(m1+m2+m3+m4+m5)/5
if Average >= ’90’ and <= ‘100’
Grade=S
else if Average >= ’80’ and < ‘90’
Grade=A
else if Average >= ’70’ and < ‘80’
Grade=B
else if Average >= ’60’ and < ‘70’
Grade=C
else if Average >= ’50’ and < ‘60’
Grade=D
else if Average >= ’40’ and < ‘50’
Grade=E
else Grade=F
end if
output roll,name,grade
end if
stop
____________________________________________________________________________________________________________________
Generic Right Shift
Code:
Input:
Choice of data type
Number of elements
Element1 in the collection
Element2 in the collection
....
Elementn in the collection
'r'
Output:
elements in collection after shiftingProcessing:
to right shift n elements of A by r places:
let B=A
for i=1 till i=n
A[i]=B[(i+n-r)%(n+1)]
end for
Psuedocode:
startinput n
input A[1 to n]
input r
let B=A
for i=1 till i=n
A[i]=B[(i+n-r)%n+1)]
end for
output A[1 to n]
stop
____________________________________________________________________________________________________________________
Check if a Matrix is Sparse or Not
Code:
Input:
r1c1
Element1 in matrix1
Element2 in matrix1
...
Element r1*c1 in matrix1
r2
c2
Element1 in matrix2
Element2 in matrix2
...
Element r2*c2 in matrix2
Output:
exception message ORElement1 in matrix3
Element2 in matrix3
...
Element r*c in matrix3
sparce or not sparce
Processing:
C=A+Bis given by
for i=1 till i=r*c
C[i]=A[i]+B[i]
end for
Psuedocode:
start
input r1,c1 m1[1 to r1*c1]
input r2,c2, m2[1 to r2*c2]
if r1=r2 and c1=c2
output "Dimentions of matrix do not mtch"
else
let zeros=0
for i=1 till i=r1*c1
m3[i]=m1[i]+m2[i]
output m3[i]
if m3[i]=0
let zeros=zeros+1
end if
end for
if zeros>r1*c1/2
output "Matrix is sparce"
else
output "Matrix is not sparce"
end if
end if
stop
____________________________________________________________________________________________________________________
Elements in a generic box
Code:
(fixed,question says capacity=20, but they expected capacity=10. smh) thanks to the anonymous guy in the comments for this info.
Input:
Choice for type of element
Choice for operation in generic box
{1,2,3,4,5,6,7,8,9,10}
element to be inserted (if required)
Output:
"empty"/"not empty""full"/"not full"
elements in the box
Processing:
box is empty if if first=-1box is full if last=capacity-1
insertion at first:
for i= last+1 till i=2
ele[i]=ele[i-1]
end for
ele[1]=data
last=last+1
mid=(first+last)/2
insertion at mid:
for i=last+1 till i=mid+1
ele[i]=ele[i+1]
end for
ele[mid]=data
last=last+1
mid=(first+last}/2
insertion at end:
ele[last+1]=data
last=last+1
deletion at first:
for i=1 till i=last-1
ele[i]=ele[i+1]
end for
last=last-1
mid=(first+last)/2
deletion at mid:
for i=mid till i=last-1
ele[i]=ele[i+1]
end for
last=last-1
mid=(last+first)/2
deletion at end:
end=end-1
mid=(start+end)/2
Psuedocode:
startlet capacity=20
while(1)
input c
if c=1
output "empty" if first=-1
else output "not empty"
if c=2
output "full" if last=capacity-1
else output "not full"
if c=3
input data
for i= last+1 till i=2
ele[i]=ele[i-1]
end for
ele[1]=data
last=last+1
mid=(first+last)/2
if c=5
input data
for i=last+1 till i=mid+1
ele[i]=ele[i+1]
end for
ele[mid]=data
last=last+1
mid=(first+last}/2
if c=4
input data
ele[last+1]=data
last=last+1
mid=(last+first)/2
if c=6
for i=1 till i=last-1
ele[i]=ele[i+1]
end for
last=last-1
mid=(first+last)/2
if c=8
for i=mid till i=last-1
ele[i]=ele[i+1]
end for
last=last-1
mid=(last+first)/2
if c=7
end=end-1
mid=(start+end)/2
if c=9
for i=first till i=last
output ele[i]
end for
if c=10
goto end of while
end while
stop
____________________________________________________________________________________________________________________
Count the Number of Items
Code:
Input:
Choice of type of input (0- int, 1 – char, 2- book)number of elements ‘n’
The next ‘n’ lines contain the details of each element
Element to be searched
Output:
count of elementsProcessing:
count is given bylet count =0
for i=1 till i=n
if a[i]=s
let count=count+1
end if
end for
Psuedocode:
startinput n
input a[1 to n]
input s
let count =0
for i=1 till i=n
if a[i]=s
let count=count+1
end if
end for
output count
stop
-----------------------------------------------------------------------------------------------------------------------------------------
CODES FOR COPY-PASTING
GENERIC BOX: (question says capacity=20, but they expected capacity=10. smh)
#define t template
t<class T>g_Box<T>::g_Box(){first=last=mid=-1;capacity=10;no_Of_Ele=0;ele=new T[20];}
t<class T>bool g_Box<T>::isEmpty(){return !(first+1);}
t<class T>bool g_Box<T>::isFull(){return no_Of_Ele==capacity;}
t<class T>void g_Box<T>::insert_First(T d){if(isFull())return;
for(int i=last+1;i>0;i--)ele[i]=ele[i-1];
ele[0]=d; first=0; mid=++last/2; no_Of_Ele++;}
t<class T>void g_Box<T>::insert_Mid(T d){if(isFull())return;
for(int i=last+1;i>mid;i--)ele[i]=ele[i-1];
ele[mid]=d; first=0; mid=++last/2; no_Of_Ele++;}
t<class T>void g_Box<T>::insert_Last(T d){if(isFull())return;
ele[++last]=d;first=0;mid=last/2; no_Of_Ele++;}
t<class T>void g_Box<T>::delete_First(){if(isEmpty())return;
for(int i=0;i<last;i++)ele[i]=ele[i+1];
mid=--last/2; no_Of_Ele--; if(last==-1)mid=first=-1;}
t<class T>void g_Box<T>::delete_Mid(){if(isEmpty())return;
for(int i=mid;i<last;i++)ele[i]=ele[i+1];
mid=--last/2; no_Of_Ele--; if(last==-1)mid=first=-1;}
t<class T>void g_Box<T>::delete_Last(){if(isEmpty())return;
mid=--last/2;no_Of_Ele--;if(last==-1)mid=first=-1;}
t<class T>void g_Box<T>::print(){if(!no_Of_Ele)cout<<"Box empty\n";
else for(int i=0;i<no_Of_Ele;)cout<<ele[i++]<<"\n";}
grade of student:
#define s student
void s::get(){cin>>rollno>>name;
for(int i=5;i--;){
cin>>marks[5-i];
if(marks[5-i]>100)throw moreException();
if(marks[5-i]<0)throw negException();} }
void s::print(){cout<<rollno<<"\n"<<name<<"\n"<<grade;}
void s::calc_Avg(){avg=0;for(int i=5;i--;avg+=marks[5-i]/5);}
void s::find_Grade(){
grade=avg>90?'S':avg>80?'A':avg>70?'B':avg>60?'C':avg>50?'D':avg>40?'E':'F';}
void negException::error_Msg() const{cout<<"Negative Marks Not Allowed";}
void moreException::error_Msg() const{cout<<"Marks Greater than 100 Not Allowed";}
int main(){
student a;
try{
a.get();a.calc_Avg();a.find_Grade();a.print();
}
catch(negException x){x.error_Msg();}
catch(moreException x){x.error_Msg();}
}
Matrix is sparce or not:
#define t template
#define m mismatchDimension
t<class T>void matrix<T>::get(){
cin>>row>>col;for(int i=0;i<row*col;i++)cin>>ele[i/col][i%col];}
t<class T>bool matrix<T>::check_Sparse(){ int z=0;
for(int i=0;i<row*col;i++)if(!ele[i/col][i%col])z++; return z>row*col/2;}
t<class T> matrix<T> matrix<T>::add(matrix &b){
if(row-b.row||col-b.col) throw m();
matrix a;a.row=row;a.col=col; for(int i=0;i<row*col;i++)
a.ele[i/col][i%col]=ele[i/col][i%col]+b.ele[i/col][i%col];return a;}
t<class T> void matrix<T>::print(){
for(int i=0;i<row*col;i++)cout<<ele[i/col][i%col]<<"\n";}
void m::error_Msg()const{cout<<"Dimension of matrices do not match\n";}
Count number of items:
template<class T,class S>int count(T *data,int size,S search){
int c=0;
for(int i=0;i<size;i++)c+=data[i]==search?1:0; return c;}
void book::get(){cin>>id>>name>>a_Name>>price;}
bool book::operator==(string s){return s==name;}
int main(){
int c,s,i;cin>>c>>s;
if(c==1){int a[s],x;for(i=0;i<s;i++)cin>>a[i]; cin>>x;
cout<<count<int,int>(a,s,x);}
if(c==2){char a[s],x;for(i=0;i<s;i++)cin>>a[i]; cin>>x;
cout<<count<char,char>(a,s,x);}
if(c==3){book a[s];string x;for(i=0;i<s;i++)a[i].get();cin>>x;
cout<<count<book,string>(a,s,x);}
}
Generic right shift:
template<class T>void right_Shift(T *ele,int n,int r){
T z[n];for(int i=0;i<n;i++)z[i]=ele[i];
for(int i=0;i<n;i++)ele[i]=z[(i+n-r)%n];}
GENERIC BOX: (question says capacity=20, but they expected capacity=10. smh)
#define t template
t<class T>g_Box<T>::g_Box(){first=last=mid=-1;capacity=10;no_Of_Ele=0;ele=new T[20];}
t<class T>bool g_Box<T>::isEmpty(){return !(first+1);}
t<class T>bool g_Box<T>::isFull(){return no_Of_Ele==capacity;}
t<class T>void g_Box<T>::insert_First(T d){if(isFull())return;
for(int i=last+1;i>0;i--)ele[i]=ele[i-1];
ele[0]=d; first=0; mid=++last/2; no_Of_Ele++;}
t<class T>void g_Box<T>::insert_Mid(T d){if(isFull())return;
for(int i=last+1;i>mid;i--)ele[i]=ele[i-1];
ele[mid]=d; first=0; mid=++last/2; no_Of_Ele++;}
t<class T>void g_Box<T>::insert_Last(T d){if(isFull())return;
ele[++last]=d;first=0;mid=last/2; no_Of_Ele++;}
t<class T>void g_Box<T>::delete_First(){if(isEmpty())return;
for(int i=0;i<last;i++)ele[i]=ele[i+1];
mid=--last/2; no_Of_Ele--; if(last==-1)mid=first=-1;}
t<class T>void g_Box<T>::delete_Mid(){if(isEmpty())return;
for(int i=mid;i<last;i++)ele[i]=ele[i+1];
mid=--last/2; no_Of_Ele--; if(last==-1)mid=first=-1;}
t<class T>void g_Box<T>::delete_Last(){if(isEmpty())return;
mid=--last/2;no_Of_Ele--;if(last==-1)mid=first=-1;}
t<class T>void g_Box<T>::print(){if(!no_Of_Ele)cout<<"Box empty\n";
else for(int i=0;i<no_Of_Ele;)cout<<ele[i++]<<"\n";}
grade of student:
#define s student
void s::get(){cin>>rollno>>name;
for(int i=5;i--;){
cin>>marks[5-i];
if(marks[5-i]>100)throw moreException();
if(marks[5-i]<0)throw negException();} }
void s::print(){cout<<rollno<<"\n"<<name<<"\n"<<grade;}
void s::calc_Avg(){avg=0;for(int i=5;i--;avg+=marks[5-i]/5);}
void s::find_Grade(){
grade=avg>90?'S':avg>80?'A':avg>70?'B':avg>60?'C':avg>50?'D':avg>40?'E':'F';}
void negException::error_Msg() const{cout<<"Negative Marks Not Allowed";}
void moreException::error_Msg() const{cout<<"Marks Greater than 100 Not Allowed";}
int main(){
student a;
try{
a.get();a.calc_Avg();a.find_Grade();a.print();
}
catch(negException x){x.error_Msg();}
catch(moreException x){x.error_Msg();}
}
Matrix is sparce or not:
#define t template
#define m mismatchDimension
t<class T>void matrix<T>::get(){
cin>>row>>col;for(int i=0;i<row*col;i++)cin>>ele[i/col][i%col];}
t<class T>bool matrix<T>::check_Sparse(){ int z=0;
for(int i=0;i<row*col;i++)if(!ele[i/col][i%col])z++; return z>row*col/2;}
t<class T> matrix<T> matrix<T>::add(matrix &b){
if(row-b.row||col-b.col) throw m();
matrix a;a.row=row;a.col=col; for(int i=0;i<row*col;i++)
a.ele[i/col][i%col]=ele[i/col][i%col]+b.ele[i/col][i%col];return a;}
t<class T> void matrix<T>::print(){
for(int i=0;i<row*col;i++)cout<<ele[i/col][i%col]<<"\n";}
void m::error_Msg()const{cout<<"Dimension of matrices do not match\n";}
Count number of items:
template<class T,class S>int count(T *data,int size,S search){
int c=0;
for(int i=0;i<size;i++)c+=data[i]==search?1:0; return c;}
void book::get(){cin>>id>>name>>a_Name>>price;}
bool book::operator==(string s){return s==name;}
int main(){
int c,s,i;cin>>c>>s;
if(c==1){int a[s],x;for(i=0;i<s;i++)cin>>a[i]; cin>>x;
cout<<count<int,int>(a,s,x);}
if(c==2){char a[s],x;for(i=0;i<s;i++)cin>>a[i]; cin>>x;
cout<<count<char,char>(a,s,x);}
if(c==3){book a[s];string x;for(i=0;i<s;i++)a[i].get();cin>>x;
cout<<count<book,string>(a,s,x);}
}
Generic right shift:
template<class T>void right_Shift(T *ele,int n,int r){
T z[n];for(int i=0;i<n;i++)z[i]=ele[i];
for(int i=0;i<n;i++)ele[i]=z[(i+n-r)%n];}
i need a copy paste code for enter into a genetric box pls upload that
ReplyDeletecopy paste code for enter into a genetric box pls
ReplyDeletegenetric box code is not working
ReplyDeleteinstead of 20 change it to 10 in capacity
ReplyDeleteplease publish the code for the question
ReplyDeleteAmount remaining after shopping
Sherley goes for a shopping to a mall ‘M1’ . She uses credit card of bank ‘ABC’ for her purchases. Account details of each customer of ‘ABC’ contain Account holder name, Account number and Balance. Details of customers of mall ‘M1’ includes customer name and list of items purchased and cost of the items. Given the details of ‘n’ customers of bank ‘ABC’ and the purchase details of ‘m’ customers to mall ‘M1’, design an algorithm and write a C program to print the name of items purchased by Sherley and the balance amount in the account of Sherley in the bank ‘ABC’.
For example, if details (Name, Account number, Balance) of six customers of bank are given as follows:
Raju 12356 1000.00
Sam 12789 980.00
Ram 13457 975.50
Sherley 16789 1500.00
Sheela 17890 1345.50
Kamala 12378 2567.75
Details (Name, number of items purchased, item name1, cost1, item name2, cost2,...) of three customers of mall m1 are given as follows:
Ram 2 Bread 50.00 Jam 25.00
Sherley 3 Milk 20.00 Bread 50.00 Butter 31.50
Mukesh 4 Chocolate 15.00 Chips 12.50 Rice 29.00 Dall 31.25
Assume that the customer of mall has purchased only a maximum of ten items
Input Format
First line contains the number of customers of ABC bane, n
Next ‘n’ lines contain the details of customers of bank such as Account holder name, Account number and Balance in order and separated by space
Next line contains the number of customers to mall M1, m
Next ‘m’ lines contains the details of customers to mall such as name, number of items purchased ‘r’, 2*r detail such as item name and cost. Each detail is separated by a space
Output Format
Print name of the items purchased by Sherley, one item name in a line and balance amount in account of Sherley in the bank