Professional Documents
Culture Documents
PSCPP_Friend_PH
Attempt : 1
Total Mark : 50
Marks Obtained : 47.5
Section 1 : Coding
Answer
// You are using GCC
#include <bits/stdc++.h>
using namespace std;
class minmum{
int n1,n2,min;
public:
void mi(int a,int b){
n1=a;
n2=b;
if(n1<n2)
cout<<n1;
else
cout<<n2;
}
};
int main(){
minmum m;
int n1,n2;
cin>>n1>>n2;
m.mi(n1,n2);
}
2. Problem statement :
Student structure
Create a structure student with the following members
Roll Number
Five subject marks
Average
Grade
Given the five subject marks, Calculate the average and grade.
GRADE CALCULATION:
1)if avg>70 the grade will be 1
2)if avg 50 to 70 the grade will be 2
3)if avg is below 50 the grade will be 3 (Note: rn- Roll Number, s-Subjects,
avg- Average)
Answer
// You are using GCC
#include <bits/stdc++.h>
using namespace std;
struct student{
int roll,m1,m2,m3,m4,m5;
};
int main(){
int num;
cin>>num;
struct student s[num];
for(int i=0;i<num;i++){
cin>>s[i].roll>>s[i].m1>>s[i].m2>>s[i].m3>>s[i].m4>>s[i].m5;
float ava=s[i].m1+s[i].m2+s[i].m3+s[i].m4+s[i].m5;
ava/=5;
cout<<s[i].roll<<" "<<s[i].m1<<" "<<s[i].m2<<" "<<s[i].m3<<" "<<s[i].m4<<"
"<<s[i].m5<<" "<<int(ava)<<" ";
switch (int(ava/10)){
case 10:
case 9:
case 8:
case 7:
cout<<"1";
break;
case 6:
case 5:
cout<<"2";
break;
default:
cout<<"3";
}
cout<<endl;
}
3. Problem Statements:
Write a program to find the difference between two time periods using
structures.
Answer
// You are using GCC
#include<bits/stdc++.h>
using namespace std;
struct time{
int h,min,sec;
};
int main(){
struct time t1,t2;
cin>>t1.h>>t1.min>>t1.sec;
cin>>t2.h>>t2.min>>t2.sec;
if((t1.h>=0)&&(t1.h<24)&&(t1.min>=0)&&(t1.min<60)&&(t1.sec>=0)&&(t1.sec<6
0)&&(t2.h>=0)&&(t2.h<24)&&(t2.min>=0)&&(t2.min<60)&&(t2.sec>=0)&&(t2.sec<6
0)){
cout<<"Difference: "<<t1.h<<":"<<t1.min<<":"<<t1.sec<<" -
"<<t2.h<<":"<<t2.min<<":"<<t2.sec<<" = ";
int hr,mi,se;
hr=t1.h-t2.h;
mi=t1.min-t2.min;
se=t1.sec-t2.sec;
if(mi<0){
mi+=60;
hr--;
}
if(se<0){
se+=60;
mi--;
}
cout<<hr<<":"<<mi<<":"<<se;
}
else{
cout<<"-1";
}
}
4. Problem Statement:
In an online grocery shop, customers want to purchase multiple items.
Create a structure to store the Item code, Brand name, Item Name,
Quantity, Price of the product. Generate the Bill number, Display the
purchased product, name, amount and quantity, and the total bill amount.
a. Write a function MESSAGE() to alert the customer with the product
name if the rate of a product is more than Rs.1000.
b. Write a function VOUCHER() to generate the voucher for Rs.200 if the bill
amount is greater than Rs.10000.
Answer
// You are using GCC
#include <bits/stdc++.h>
using namespace std;
struct shop{
int ic;
string bn,in;
int q,p;
};
int main(){
int sum=0;
int n;
cin>>n;
string gt1000;
int k=0;
struct shop s[n];
for(int i=0;i<n;i++){
cin>>s[i].ic>>s[i].bn>>s[i].in>>s[i].q>>s[i].p;
int mul;
mul=s[i].q*s[i].p;
if(mul>1000)
{
gt1000=s[i].in;
k++;
}
sum+=mul;
}
if(k>0)
cout<<gt1000<<" costs more than 1000\n";
if(sum>10000)
cout<<sum<<"\nYou have won a voucher of Rs.200";
else
cout<<sum<<"\nNo voucher";
}
5. Problem Statement:
Write a program to add two distances (in inch-feet) system using
structures.
Answer
// You are using GCC
#include <bits/stdc++.h>
using namespace std;
struct str{
int f1,f2;
float i1,i2;
};
int main(){
struct str s;
cin>>s.f1>>s.i1;
cin>>s.f2>>s.i2;
int t,fe;
float ss;
fe=s.f1+s.f2;
ss=s.i1+s.i2;
if(ss>=12){
fe++;
ss-=12;
}
cout<<"Sum: "<<fe<<" feet"<<", "<<ss<<" inches.";
}