College application-
Question1-A student may apply for an arts college or an engineering college after his school. Admission to arts college or engineering college, is based on the marks obtained in the six subjects : English, Second language, Maths, Physics, Chemistry and Computer Science. Both the applications have the following details : application number, name, age, marks in all six subjects and cut-off for the eligibility. For Arts college, cut-off is the average of marks in all the subjects and whereas for engineering colleges cut-off is the average of marks in maths, physics, chemistry plus the marks scored in the entrance exam. Given all the required details, Design an OOP model to compute the cut-off marks and implement it using C++.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)
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
c++ code-
void college_Appln::get()
{
cin>>appln_No>>name>>age;
for(int i=0;i<6;i++)
{cin>>marks[i];}
}
void college_Appln::print()
{
cout<<name;
}
void arts_Appln::calc_Cutoff()
{
for(int i=0;i<6;i++)
cutoff=(cutoff+marks[i]);
cutoff=cutoff/6;
}
void arts_Appln::print()
{
cout<<name<<"\n";
cout<<fixed<<setprecision(2)<<cutoff;
}
void engg_Appln::get()
{
cin>>appln_No>>name>>age;
for(int i=0;i<6;i++)
{cin>>marks[i];}
cin>>entrance;
}
void engg_Appln::calc_Cutoff()
{
for(int i=2;i<=4;i++)
{
cutoff=(cutoff+marks[i]);
}
cutoff=cutoff/3;
cutoff=cutoff+entrance;
}
void engg_Appln::print()
{
cout<<name<<"\n";
cout<<fixed<<setprecision(2)<<cutoff;
}
Cost of pizza
Description 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
Precode
#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
type this-
void circle :: get_C(){
cin>>radius;
}
float circle :: area()
{
return(3.14*radius*radius);
}
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)==0)
return(ing_Cost[i].price);
}
void cookeditem :: get_CI()
{
cin>>num;
for(int i=0;i < num;i++)
cin>>ing_Qty[i].name>>ing_Qty[i].qty;
}
class pizza : public circle,cookeditem
{
protected :
float p_cost;
void get()
{
get_C();
get_CI();
}
void cost(kitchen k)
{
p_cost=0;
for(int i=0;i < num;i++)
p_cost+=ing_Qty[i].qty*k.get_Cost(ing_Qty[i].name)*0.01*area();
}
};
class veg_Pizza : public pizza
{
public :
void get_P()
{
get();
}
void compute_Cost(kitchen k)
{
cost(k);
}
void print_P()
{
cout<<fixed<<setprecision(2)<<p_cost+50;
}
};
class chik_Pizza : public pizza
{
public :
void get_P()
{
get();
}
void compute_Cost(kitchen k)
{
cost(k);
}
void print_P()
{
cout<<fixed<<setprecision(2)<<p_cost+100;
}
};
Postcode
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();
}
}
}
customer discount
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:
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
Type this-
#include < iostream >using namespace std;
class details
{
protected :
char name[20],mob[20],add[20],id[10];
int num,bills[20];
void get_details()
{
cin>>name>>mob>>add>>id>>num;
for(int i=0;i < num;i++)
cin>>bills[i];
}
};
class customer : public details
{
public :
void get()
{
get_details();
}
float calc_Total()
{
float total=0;
for(int i=0;i < num;i++)
total+=bills[i];
return(total);
}
};
class preferred_Customer : public details
{
public :
void get()
{
get_details();
}
float calc_Total()
{
float total=0,spent=0;
for(int i=0;i < num;i++)
{
spent+=bills[i];
if(spent > =20000)
total+=bills[i]*0.96;
else if(spent > =15000)
total+=bills[i]*0.97;
else if(spent > =10000)
total+=bills[i]*0.98;
else if(spent > =5000)
total+=bills[i]*0.99;
else
total+=bills[i];
}
return(total);
}
};
Postcode
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();
}
}
polygon in 2d space
Description 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 quadrilateral
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
#include<iostream>
using namespace std;
#include<math.h>
#include<iomanip>
#include<exception>
//Declaration of classes
struct point
{
double x;
double y;
point();
void get();
friend ostream& operator<<(ostream&,point);
};
class outofrange:public exception
{
public:
void what();
};
class polygon
{
protected:
int num_Of_Ver;
point* vertices;
public:
//initialize num_Of_Ver to 'n'
//allocate memory to store points of 'n' vertices
polygon(int n);
~polygon();
//get function cannot be defined here instead define in the derived class
void get();
//we return reference of the point so that assignment can be made
point& operator[](int idx);
double area();
};
class triangle : public polygon
{
public:
triangle():polygon(3){}
};
class quadrilateral : public polygon
{
public:
quadrilateral():polygon(4){}
};
type this-
point :: point(){}
void point :: get()
{
cin>>x>>y;
}
ostream& operator << (ostream& output,point poi)
{
output<<poi.x<<"\t"<<poi.y;
return(output);
}
void outofrange :: what()
{
cout<<"Out of range";
}
polygon :: polygon(int n)
{
num_Of_Ver=n;
vertices=new point[n];
}
void polygon :: get()
{
for(int i=0;i < num_Of_Ver;i++)
vertices[i].get();
}
point& polygon :: operator [](int idx)
{
if(idx < num_Of_Ver)
return(vertices[idx]);
else
{
outofrange o;
throw(o);
}
}
double polygon :: area()
{
double a=0;
for(int i=0;i < num_Of_Ver-1;i++)
a+=vertices[i].x*vertices[i+1].y-vertices[i+1].x*vertices[i].y;
a+=vertices[num_Of_Ver-1].x*vertices[0].y-vertices[num_Of_Ver-1].y*vertices[0].x;
if(a/2<0)
return(-a/2);
return(a/2);
}
polygon :: ~polygon(){}
Postcode already typed content
int main(){
triangle t;
int index;
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();
}
}
black coin in a board game
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 current position of your coin is 4,4 then print P1, P2 ... P8 in order.
Assume that the current row position and column position are between 2 and 7.
Input Format
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 position
One position in a line with row and column separated by a comma
Precode
#include<iostream>
using namespace std;
class coin
{
protected:
int weight;
int curr_X;
int curr_Y;
public:
void get();
void print();
//return the current row position
int get_Curr_X();
//return the current col position
int get_Curr_Y();
//return weight of the coin
int get_Weight();
//pure virtual function that the derived classes must implement
virtual void move()=0;
};
//Define two more classes black_Coin and red_Coin
type this
void coin :: get()
{
cin>>weight>>curr_Y>>curr_X;
}
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);
}
void coin :: move(){}
class black_Coin : public coin
{
public :
int moves;
void get()
{
coin :: get();
cin>>moves;
}
bool gained_Power()
{
if(moves > =5)
return(true);
return(false);
}
void move()
{
cout<<curr_Y<<","<<curr_X+1;
}
};
class red_Coin : public coin
{
public :
void set_Curr_Pos_Wt(black_Coin b)
{
weight=b.get_Weight();
curr_X=b.get_Curr_X();
curr_Y=b.get_Curr_Y();
}
void move()
{
cout<<curr_Y-1<<","<<curr_X<<"\n";
cout<<curr_Y+1<<","<<curr_X<<"\n";
cout<<curr_Y<<","<<curr_X-1<<"\n";
cout<<curr_Y<<","<<curr_X+1<<"\n";
cout<<curr_Y-1<<","<<curr_X-1<<"\n";
cout<<curr_Y+1<<","<<curr_X-1<<"\n";
cout<<curr_Y-1<<","<<curr_X+1<<"\n";
cout<<curr_Y+1<<","<<curr_X+1<<"\n";
}
};
Postcode
int main()
{
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();
}
}