CSE 1002 PPS5
Total time : 600 mins
Challenges : 5
Question-1
College Application (Id-1410)
Note: Syntax to print 'x' decimal places of variable 'a'
include <iomanip>
use
cout<<fixed<<setprecision(x)<<a;
Input Format
Type of application (0 for arts student and 1 for engineering student)Application Number
Name of student
Age
Marks scored in English
Marks scored in Second Language
Marks scored in Maths
Marks scored in Physics
Marks scored in Chemistry
Marks scored in Computer Science
Marks scored in entrance exam (only for engineering student)
Output Format
Name of student
Cut-off marks
Solution
#include<iostream>
#include<iomanip>
using namespace std;
class college_Appln
{
protected:
int appln_No;
char name[30];
int age;
float marks[6];
public:
void get();
void print();
};
class arts_Appln:public college_Appln
{
float entrance;
float cutoff;
public:
void calc_Cutoff();
void print();
};
class engg_Appln:public college_Appln
{
float cutoff;
float entrance;
public:
void get();
void print();
void calc_Cutoff();
};
void college_Appln::get() { cin>>appln_No>>name>>age; for(int i=0;i<6;i++) cin>>marks[i]; } void arts_Appln::calc_Cutoff() { cutoff=0; for(int i=0;i<6;cutoff+=marks[i++]); cutoff/=6; } void arts_Appln::print() { cout<<name<<"\n"<<fixed<<setprecision(2)<<cutoff; } void engg_Appln::print() { cout<<name<<"\n"<<fixed<<setprecision(2)<<cutoff; } void engg_Appln::get() { college_Appln::get(); cin>>entrance; } void engg_Appln::calc_Cutoff() { cutoff=(marks[2]+marks[3]+marks[4])/3+entrance; }
int main()
{
    int ch;
    cin>>ch;
    if(ch==0)
    {
    arts_Appln a;
    a.get();
    a.calc_Cutoff();
    a.print();
    }
    else
    {
    engg_Appln e;
    e.get();
    e.calc_Cutoff();
    e.print();
    }
}
INPUT
INPUT
Type of application (0 for arts student and 1 for engineering student)
Application Number
Name of student
Age          
Marks scored in English     
Marks scored in Second Language
Marks scored in Maths
Marks scored in Physics
Marks scored in Chemistry
Marks scored in Computer Science
Marks scored in entrance exam (only for engineering student)
OUTPUT
Name of student Cut-off marks
Processing
If student is Engineering student
    cut_off=(m3+m4+m5)/3+m7
else    
    cut_off=(m1+m2+m3+m4+m5+m6)/6 
Pseudocode
BEGIN
Read inputs & Type
if Type 1
          input marks in Entrance Exam
         let cut_off=(m3+m4+m5)/3+m7
else    
    cut_off=(m1+m2+m3+m4+m5+m6)/6 
output cut_off
END
else    
    cut_off=(m1+m2+m3+m4+m5+m6)/6 
output cut_off
ENDSample input and output (Verify code )
Question-2
Black Coin in Board game (Id-1411)
Colored
 coin game is a 8X8 board game which has many colored coins. Each coin 
has a weight and power. Power of a coin is defined by the moves that it 
can make. In a move,  a black coin can move one step vertically 
upwards.  A red coin can move one step either horizontally, vertically 
or diagonally. Given the current position of a black coin and list of 
movements made by it, print all possible next positions of the coin. If 
the total number of moves made by a black coin is greater than 6, then 
that coin should be treated as a red coin and the subsequent moves will 
be as that of the red coin. At any point of time, the coin cannot move 
outside the board. The rows and columns of the board are numbered as 1 
to 8. Print the horizontal movement of coin in an increasing order of 
columns and print the vertical movement of coin in increasing order of 
rows. To print, the diagonal movement of the coin refer the sample board
 config given below. If the current position of your coin is 4,4 then 
print P1, P2 ... P8 in order..
Weight of black coin
Current row position of coin
Current column position of coin
Number of moves made by black coin
Output Format
Weight of black coin
List of possible next positions
One position in a line with row and column separated by a comma
Solution:
| #include<iostream>using namespace std;classcoin{    protected:    intweight;    intcurr_X;    intcurr_Y;    public:    voidget();    voidprint();    //return the current row position    intget_Curr_X();    //return the current col position    intget_Curr_Y();    //return weight of the coin    intget_Weight();    //pure virtual function that the derived classes must implement    virtual voidmove()=0;};//Define two more classes black_Coin and red_Coin | 
void coin::get()
{
    cin>>weight>>curr_X>>curr_Y;
}
void coin::print()
{
    cout<<weight<<"\n";
}
int coin::get_Curr_X()
{
    return curr_X;
}
int coin::get_Curr_Y()
{
    return curr_Y;
}
int coin::get_Weight()
{
    return weight;
}
class black_Coin:public coin
{
    public:int gained_Power()
    {
        int m;
        cin>>m;
        return (m>5)?1:0;
    }
    virtual void move()
    {
        cout<<curr_X<<","<<curr_Y+1<<"\n";
    }
};
class red_Coin:public coin
{
    public:
    void set_Curr_Pos_Wt(black_Coin b)
    {
        weight=b.get_Weight();
        curr_Y=b.get_Curr_Y();
        curr_X=b.get_Curr_X();
    }
    virtual void move()
    {
        int x=curr_X;
        int y=curr_Y;
        cout<<x-1<<","<<y<<"\n"<<x+1<<","<<y<<"\n"<<x<<","<<y-1<<"\n"<<x<<","<<y+1<<"\n";
        cout<<x-1<<","<<y-1<<"\n"<<x+1<<","<<y-1<<"\n"<<x-1<<","<<y+1<<"\n"<<x+1<<","<<y+1<<"\n";
    }
};
| intmain(){    coin *c;    black_Coin b;    b.get();    red_Coin r;       //Function to check if the black coin has gained power       // It gains power when the number of movements made is greater than or equal to 5    if(b.gained_Power())    {    //Make the black coin as red coin        //set weight and current position of black coin to a red coin     r.set_Curr_Pos_Wt(b);     c = &r;             //Print only weight of the coiin     c->print();        //Print all possible moves     c->move();    }    else    {        c = &b;            //Print only weight of the coiin           c->print();               //Print all possible moves           c->move();    }    }
 | 
OUTPUT
b.w; Weight of black coin
List of possible next positions
Processing
if m=>5
  then convert black coin to red coin
if coin is black
   possible move is b.r+1,b.c
if coin is red 
   possible moves is given by
   r.r-1,r.c; r.r+1,r.c;r.r,r.c-1; r.r,r.c+1;
   r.r-1,r.c-1; r.r+1,r.c-1;r.r-1,r.c+1;r.r+1,r.c+1
END
Pseudocode
BEGIN
Read inputs
if m>=5
        r.r=b.r,r.c=b.c, r.w=b.w;
        output r.w; r.r-1,r.c; r.r,r.c-1; r.r,r.c+1; r.r-1, r.c-1;r.r-1,r.c+1; r.r+1,r.c+1
else
     output b.w; b.r+1,b.c;
END
Sample input and output (Verify code )
Question 3:
Custormer discount(Id-1413)
A retail store is maintaining their customer details such as customer id and name, mobile number and address. They have decided to introduce a preferred customer plan for the existing customer. Any customer is given the status of preferred customer if they have made purchases more than 10 times. Preferred customers earn discounts based on their cumulative purchase amount as follows:| Cumulative Purchase Amount | Discount (%) | 
| >= Rs. 5000 | 1 | 
| >= Rs 10,000 | 2 | 
| >= Rs 15000 | 3 | 
| >= Rs 20000 | 4 | 
Design an OOP model and implement it using
 C++ program. Refer the declaration of classes and application program 
to do the design. The program must get the details, compute bill amount 
and print details both for ordinary and preferred customers.
For example, if a preferred customer makes
 three purchases of amounts 3000, 7000, 8000 then the amount to be paid 
for each bill is 3000, 6860 and 7760 and the total amount to be paid is 
17620
Input Format
Type of customer (0 for ordinary customer and 1 for preferred customer)
Name
Mobile number
Address
Customer id
Number of bills
Total Cost of products in bill1
....
Total Cost of products in bill-n
Output Format
Total amount to be paid by the customer for 'n' bills
Solution:
#include <iostream>
using namespace std;
class customer
{
    protected:
    char na[30],add[50],no[12],id[10];
    int b[50],n,sum;
    public:
    void get()
    {
        cin>>na>>no>>add>>id>>n;
        sum=0;
        for(int i=0;i<n;sum+=b[i++])
        cin>>b[i];
    }
    int calc_Total()
    {
        return sum;
    }
};
class preferred_Customer:public customer
{
    public:
    int calc_Total()
    {
        for(int i=0,s=b[0];i<n;s+=b[++i])
        sum-=b[i]*(s>=20000?4:s>15000?3:s>=10000?2:s>=5000?1:0)/100;
        return sum;
    }
};
int main()
{
int ch;
//get choice of customer
cin>>ch;
if(ch==0)
{
customer c1;
//get the details of customer
c1.get();
//calculate total amount to be paid
//develop a function in customer class that will calculate
// the total amount and return it
cout<<c1.calc_Total();
}
else
{
//preferred customer
preferred_Customer pc;
//get details
pc.get();
//function should calculate and return total amount
cout<<pc.calc_Total();
}
}
INPUT
Type of customer (0 for ordinary customer and 1 for preferred customer)NameMobile numberAddressCustomer idNumber of billsTotal Cost of products in bill1....Total Cost of products in bill-n
OUTPUT
Total amount to be paid by the customer for 'n' bills
Processing
if customer is ordinary discount is 0% else discount is as determined by given table based on the initial cost
Pseudocode
BEGIN
Read input
let sum=0
for i=1 till i=n 
        input b[i]
        let sum=sum+b[i]
end for
if type=1
        let c=0
    for i=0 till i=n
    c=c+b[i]
        if c>=20000
             sum=sum-b[i]*0.04
       else        if c>=15000
             sum=sum-b[i]*0.03
       else        if c>=10000
             sum=sum-b[i]*0.02
       else        if c>=5000
              sum=sum-b[i]*0.99
        end if
end if
output sum
END
Sample input and output (Verify code )
Question 4:
Polygon in a Two Dimensional Space (Id-1535)
Design a class polygon to represent a polygon in a two dimensional space. Provide member functions to get the details of the polygon and compute area. Area of a polygon with 'n' vertices is given by the following formula:Here the vertices are numbered from 1 to n either clockwise or anticlockwise. The sign of the value changes when numbering is done in the other way. So absolute value is considered.
Derive two classes: triangle and quadrilateral, from the class polygon. Overload the operator [] to get the 'i-th' point of the polygon if 'i' is less than or equal to the number of vertices 'n' and raise an user defined exception outofrange when 'i' is greater than 'n'. Catch the exception in main and print 'outofrange'.
Input Format
Next six entries are Vertices of a triangle
value of X- coordinate of point1
value of Y- coordinate of point1
....
value of X- coordinate of point6
value of Y- coordinate of point6
Next eight entries are Vertices of a triangle
value of X- coordinate of point1
value of Y- coordinate of point1
....
value of X- coordinate of point8
value of Y- coordinate of point8
index of the vertex of the polygon, whose coordinate has to be printed.
Output Format
Area of triangle
Area of quadrilateral
Value of X- coordinate and Y- coordinate of point-n separated by tab or print Out of range if index is not in range
Solution:
| #include<iostream>using namespace std;#include<math.h>#include<iomanip>#include<exception>//Declaration of classesstruct point{doublex;doubley;point();voidget();friend ostream& operator<<(ostream&,point);};classoutofrange:publicexception{public:voidwhat();};classpolygon{protected:intnum_Of_Ver;point* vertices;public://initialize num_Of_Ver to 'n'//allocate memory to store points of 'n' verticespolygon(intn);~polygon();//get function cannot be defined here instead define in the derived classvoidget();//we return reference of the point so that assignment can be madepoint& operator[](intidx);doublearea();};classtriangle : publicpolygon{public:triangle():polygon(3){}};classquadrilateral : publicpolygon{public:    quadrilateral():polygon(4){}}; | 
ostream& operator<<(ostream& o,point p)
{
    o<<p.x<<"\n"<<p.y<<"\n";
    return o;
}
point::point(){}
polygon::polygon(int n)
{
    num_Of_Ver=n;
    vertices=new point[n];
}
polygon::~polygon()
{
    delete vertices;
}
void polygon::get()
{
    for(int i=0;i<num_Of_Ver;i++)
    cin>>vertices[i].x>>vertices[i].y;
}
point& polygon::operator[](int idx)
{
    if(idx>num_Of_Ver)
    throw(outofrange());
    return vertices[idx];
}
double polygon::area()
{
    double a=0;
    for(int i=0;i<num_Of_Ver;i++)
    a+=vertices[i].x*vertices[(i+1)%num_Of_Ver].y-vertices[i].y*vertices[(i+1)%num_Of_Ver].x;
    return a<0?-a/2:a/2;
}
void outofrange::what()
{
    cout<<"Out of range";
}
| intmain(){    triangle t;    intindex;        t.get();    cout<<fixed<<setprecision(2)<<t.area()<<endl;    quadrilateral r;    r.get();    cout<<fixed<<setprecision(2)<<r.area()<<endl;    cin>>index;    try    {    cout<<r[index];    }catch(outofrange o)    {    o.what();    }}
 | 
Sample input and output (Verify code )
Question 5:
Cost of Pizza (Id-1412)
Pizza
 is a delicious circular food item that is a favorite for many people. 
Given the radius of the pizza, ingredients required for the preparation 
of the pizza, per square cm (cm2) area of the pizza and cost 
of its ingredients per 100 grams, design an OOP model and write a C++ 
program to calculate the cost of the pizza. Add Rs 50 for veg pizza and 
Rs 100 for chicken pizza. Use 3.14 for pi. Your program should  get all 
the ingredients available in the kitchen with their cost per 100 grams, 
as an input.  Assume that all the ingredients required for the 
preparation of the pizza is available in the kitchen.
Note: Syntax to print 'x' decimal places of variable 'a'include <iomanip>
use
cout<<fixed<<setprecision(x)<<a;
Input Format
Give 0 for veg pizza and 1 for chicken pizza
Radius of pizza
Number of ingredients required for the preparation of the pizza
Name of ingredient1
Quantity of ingredient1 required (in grams)
Name of ingredient2
Quantity of ingredient2 required
....
Name of ingredient-n
Quantity of ingredient-n required
Number of ingredients available in the kitchen.
Name of ingredient-1 available in the kitchen
Cost of 100 gm of ingredient1 available in kitchen
Name of ingredient-2 in kitchen
Cost of 100 gm of ingredient2 in kitchen
....
Name of ingredient-n in kitchen
Cost of 100 gm of ingredient-n in kitchen
Output Format
Cost of pizza
Solution:
#include<iostream>
using namespace std;
#include<string.h>
#include<iomanip>
class circle
{
    protected:
    float radius;
    public:
    void get_C();
    void print_C();
    float area();
};
struct ingre_Cost
{
    char name[30];
    float price;
};
class kitchen
{
    protected:
    int num1;
    //ingredients in the kitchen and their cost
    ingre_Cost ing_Cost[20];
    public:
    void get_K();
    void print_K();
    //Given name of ingredients
    //return cost of 100gm of it
    float get_Cost(char*);
};
struct ingre_Qty
{
    char name[30];
    float qty;
};
class cookeditem
{
    protected:
    //number of ingredients
    int num;
    // names of ingredients and their quantity in
    // Pizza
    ingre_Qty ing_Qty[20];
    public:
    void get_CI();
    void print_CI();
};
//Create a class pizza that inherits circle and cookeditem
//Create another class veg_Pizza inherited that inherits pizza
//Create another class chik_Pizza inherited that inherits pizza
#include<iostream>using namespace std;#include<string.h>#include<iomanip>class circle{    protected:    float radius;    public:    void get_C();    void print_C();    float area();};struct ingre_Cost{    char name[30];    float price;};class kitchen{    protected:    int num1;    //ingredients in the kitchen and their cost    ingre_Cost ing_Cost[20];    public:    void get_K();    void print_K();    //Given name of ingredients    //return cost of 100gm of it    float get_Cost(char*);};struct ingre_Qty{    char name[30];    float qty;};class cookeditem{    protected:    //number of ingredients    int num;    // names of ingredients and their quantity in    // Pizza    ingre_Qty ing_Qty[20];    public:    void get_CI();    void print_CI();};//Create a class pizza that inherits circle and cookeditem//Create another class veg_Pizza inherited that inherits pizza//Create another class chik_Pizza inherited that inherits pizzaclass pizza:public circle,public cookeditem
{
    public:
    float c;
void get_P()
{
    cin>>radius>>num;
    for(int i=0;i<num;i++)
    cin>>ing_Qty[i].name>>ing_Qty[i].qty;
}
float compute_Cost(kitchen k)
{
    c=50;
    for(int i=0;i<num;i++)
    c+=ing_Qty[i].qty*k.get_Cost(ing_Qty[i].name)*3.14*radius*radius/100;
}
void print_P()
{
    cout<<fixed<<setprecision(2)<<c;
}
};
void kitchen::get_K()
{
    cin>>num1;
    for(int i=0;i<num1;i++)
    cin>>ing_Cost[i].name>>ing_Cost[i].price;
}
float kitchen::get_Cost(char* n)
{
    for(int i=0;i<num1;i++)
    {
    if(!strcmp(n,ing_Cost[i].name))
    return ing_Cost[i].price;
}
}
class veg_Pizza:public pizza{int x;};
class chik_Pizza:public pizza 
{
    public:
    float compute_Cost(kitchen k)
    {
        pizza::compute_Cost(k);
        c+=50;
    }
};
int main(){    int ch;    cin>>ch;    if (ch==0)    {    //Create an oject for veg pizza    veg_Pizza p;    //get radius of circle(pizza)    // get ingredients and quantity required for 1 square centimeter    p.get_P();    //get items in kitchen and their cost    kitchen k;    k.get_K();    //compute cost    p.compute_Cost(k);    p.print_P();    }    else    {    if (ch==1)    {    chik_Pizza c;    c.get_P();    kitchen k1;    k1.get_K();    c.compute_Cost(k1);    c.print_P();    }    }}
INPUT
Give 0 for veg pizza and 1 for chicken pizza
Radius of pizza
Number of ingredients required for the preparation of the pizza
Name of ingredient1
Quantity of ingredient1 required (in grams)
Name of ingredient2
Quantity of ingredient2 required...
Name of ingredient-n
Quantity of ingredient-n required
Number of ingredients available in the kitchen.
Name of ingredient-1 available in the kitchen
Cost of 100 gm of ingredient1 available in kitchen
Name of ingredient-2 in kitchen
Cost of 100 gm of ingredient2 in kitchen...
Name of ingredient-n in kitchen
Cost of 100 gm of ingredient-n in kitchen
OUTPUT
Cost Of pizza
Processing
for i=1 till i=num
       cost =cost +qty[i]*price of ing[i] *pi*radius^2
end for
cost=cost +50
if chicken pizza 
         cost =cost +50
Pseudocode
BEGIN Read inputs for i=1 till i=n input ing[i],qty[i] end for input n1 for i=1 till i=n input ing1[i],price[i] end for let cost=50 for i=1 till i=num cost =cost +qty[i]*price of ing[i](from ing1,price table) *pi*radius^2 end for if type=1 cost =cost +50 output cost END
click here
About Unknown
                            This blog is exclusively for VITIAN'S TO fulfill their needs. Also you can tell our team your need and we will assist you as soon as possible. For any quaries send your emails to "everything4vitians@gmail.com".
Thank you 
                          
0 comments:
Post a Comment