You are on page 1of 11

1)

#include <iostream>
using namespace std;

int main() //DO NOT change the 'main' signature


{ int e;
char c;
cout<<"Enter the character:";
cin>>c;
if(c>=97 && c<=122)
{e=c;
cout<<c<<"-"<<e;
}
else if(c>=65 && c<=90)
{e=c;
cout<<c<<"-"<<e;
}
else cout<<"Invalid";
return 0;
}

2)
#include <iostream>
using namespace std;

int main() //DO NOT change the 'main' signature


{
//Fill code here
int min=100, temp, no_of_sem, no_of_sub, marks;
int i;
cout<<"Enter number of semester:";
cin>>no_of_sem;
for(i=1;i<=no_of_sem;i++){
cout<<"Enter number of subject in "<<i<<" semester:";
cin>>no_of_sub;
for(int j=1;j<=no_of_sub;j++){
cout<<"Marks obtained in semester "<<i<<":";
cin>>marks;
if(marks>100 || marks<0){
cout<<"You have entered invalid mark";
break;
}
if(marks<min){
min=marks;
}
}
cout<<"Minimum mark in "<<i<<" semester:"<<min;
min=100;
}
}

3)
#include <iostream>
using namespace std;

int main() //DO NOT change the 'main' signature


{
//Fill code here
int n,first,last,sum;
cout << "\n\n Find the sum of first and last digit of a number:\n";
cout << "------------------------------------------------------\n";
cout << " Input any number: ";
cin >> n;
first = n;
last=n % 10;
for(first=n;first>=10;first=first/10);
cout<<" The first digit of "<<n<<" is: "<<first<<endl;
cout<<" The last digit of "<<n<<" is: "<<last<<endl;
cout<<"Result:"<<n<<" is: "<<first*last<<endl;
}

4)
#include <iostream>
using namespace std;

int DivideNumbers(int num){


//Divide the numbers and return
float a,b;
cout<<"Enter the number: \n";
//cin>>num;
a=num/10;
b=num%10;
num=a/b;
cout << num;
return num;
}

int main()
{
//Call the function and print the result
int num;
DivideNumbers(num);
return 0;
}

5)
#include <iostream>
using namespace std;

class Shop {

private:
//Declare the attributes
string itemName;
string itemQuantity;
double itemPrice;

public:
//Getters and setters for above variables.
void setItemName(string iname){
itemName = iname;
}
void setItemQuantity(string iqty){
itemQuantity = iqty;
}
void setItemPrice(double iprice){
itemPrice = iprice;
}
string getItemName(){
return itemName;
}
string getItemQuantity(){
return itemQuantity;
}
double getItemPrice(){
return itemPrice;
}
};

int main(){
// set the values
// get the values and print
string name, qty;
double p;
Shop s;
cout<<"Enter the item name";
cin>>name;
cout<<"Enter the item quantity:";
cin>>qty;
cout<<"Enter the item price";
cin>>p;
s.setItemName(name);
s.setItemQuantity(qty);
s.setItemPrice(p);
cout<<"Item Name:"<<s.getItemName()<<"\n";
cout<<"Item Quantity:"<<s.getItemQuantity()<<"\n";
cout<<"Item Price:"<<s.getItemPrice()<<"\n";
}

6)
#include <iostream>
#include<string>
using namespace std;
int calculateTicketPrice(int price,int noOfAdults)
{
int price1 = price * noOfAdults;
return price1;
}

int calculateTicketPrice(int price,int noOfAdults,int noOfKids)


{
int kprice = price/2;
int price2 = (price * noOfAdults) + (kprice * noOfKids);
return price2;
}

int calculateTicketPrice(int price,int noOfAdults,bool camera)


{ int price3 = price * noOfAdults;
if(camera) {price3 = price3 + 100;return price3;}
else return price3;
}

int calculateTicketPrice(int noOfStudents)


{
int price4 = 100 * noOfStudents;
return price4;
}

int main() //DO NOT change the 'main' signature


{
//Fill code here
cout<<calculateTicketPrice(1000,3)<<endl;
cout<<calculateTicketPrice(1000,3,2)<<endl;
cout<<calculateTicketPrice(1000,3,true)<<endl;
cout<<calculateTicketPrice(10)<<endl;

7)
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

class MonthlyExpense {
public:

double household_exp;
double medical,total;

void setHouseHoldExpense(double houseExp) {


//Implement your code
household_exp = houseExp;
}

void setMedicalExpense(double medical) {


//Implement your code
this->medical = medical;
}

double totalNovemberExpense() {

//Implement your code

total = household_exp + medical;


return total;
}

double totalDecemberExpense() {
//Implement your code

total = household_exp + medical;


return total;
}

double totalNovDecExpense() {
//Implement your code
total = household_exp + medical;
return this->total;
}

MonthlyExpense operator +(const MonthlyExpense b)


{
//Implement your code
MonthlyExpense temp;
temp.household_exp = household_exp + b.household_exp;
temp.medical = medical + b.medical;

return temp;
}

};

int main() {
//Implement your code
MonthlyExpense nov;
MonthlyExpense dec,res;

nov.setHouseHoldExpense(10000);
nov.setMedicalExpense(5000);
dec.setHouseHoldExpense(20000);
dec.setMedicalExpense(500);

cout<<"November Expenses:"<<nov.totalNovemberExpense()<<"\n";
cout<<"December Expenses:"<<dec.totalDecemberExpense()<<"\n";
res = nov + dec;
cout<<"Total Expenses for the month of Nov and Dec:"<<res.totalNovDecExpense();

return 0;
}

8)
#include<iostream>
using namespace std;

class Product{
public:
int markedPrice(){
return 1000;
}
int discount(){
return 40;
}

};

class Dress: public Product{


public:
char calculateShirtSize(int chestSize){
if(chestSize >= 20 && chestSize <= 30){
return 'S';
}else if(chestSize >= 31 && chestSize <= 40){
return 'M';
}else if(chestSize > 40){
return 'L';
}
}
};

class Shirt: public Dress{


public:
int calculatePrice(int chestSize){
int price = (markedPrice()-((markedPrice()*discount())/100));
if(calculateShirtSize(chestSize) == 'S'){
return price;
}else if(calculateShirtSize(chestSize) == 'M'){
return price+500;
}else if(calculateShirtSize(chestSize) == 'L'){
return price+1000;
}
}
};

int main(){
int chestSize;
cin>>chestSize;
Shirt obj;
cout<<"Dress Size: "<<obj.calculateShirtSize(chestSize)<<endl;
cout<<"Price: "<<obj.calculatePrice(chestSize)<<endl;
return 0;
}

9)
#include<iostream>
using namespace std;

class Player
{
public:
//Declare membervariables
int playerID, playedMatches, playerScore;
string playerName;

public:
void setPlayerID(int playerID){
this->playerID=playerID;

}
int getPlayerID(){
return playerID;
}
void setPlayerName(int playerName){
this->playerName=playerName;

}
string getPlayerName(){
return playerName;
}
void setPlayerScore(int playerScore){
this->playerScore=playerScore;

}
int getPlayerScore(){
return playerScore;
}
void setPlayedMatches(int playedMatches){
this->playedMatches=playedMatches;

}
int getPlayedMatches(){
return playedMatches;
}
Player(int playerID, string playerName, int playerScore){
this->playerID=playerID;
this->playerName=playerName;
this->playerScore=playerScore;

}
Player(int playerID,string playerName,int playedMatches, int playerScore){

this->playerID=playerID;
this->playerName=playerName;
this->playedMatches=playedMatches;
this->playerScore=playerScore;
}
//Implement a parameterized constructor for 3 arguments - playerID, playerName
and playerScore.

//Implement a parameterized constructor for 4 arguments - playerID,


playerName,playedMatches and playerScore.

void displayThreeArgument()
{
cout<<"Player ID. : "<<playerID<<""<<endl;
cout<<"Player Name : "<<playerName<<""<<endl;
cout<<"Player Score : "<<playerScore<<""<<endl;
//Implement your code here
}

void displayFourArgument()
{
cout<<"Player ID. : "<<playerID<<""<<endl;
cout<<"Player Name : "<<playerName<<""<<endl;
cout<<"Played Matches : "<<playedMatches<<""<<endl;
cout<<"Player Score : "<<playerScore<<""<<endl;

}
~Player(){
cout<<"Destructor Called"<<endl;
}
//Implement Destructor here

};
int main(){
Player p1=Player(1001,"John",130);
Player p2=Player(1002,"Raj",100,500);
p1.displayThreeArgument();
cout<<"--------------------------------"<<endl<<endl;
p2.displayFourArgument();

//Implement your code here


return 0;
}

10)
#include<iostream>
using namespace std;

class Country{
private:
string countryName;
public:
string getCountryName(){
return countryName;
}
void setCountryName(string name){
countryName = name;
}
};

class City: public virtual Country{


private:
string cityName;
public:
string getCityName(){
return cityName;
}
void setCityName(string name){
cityName = name;
}
};

class State: public virtual Country{


private:
string stateName;
public:
string getStateName(){
return stateName;
}
void setStateName(string name){
stateName = name;
}
};

class CountryInfo: public City, public State{


private:
string countryInfo;
public:
void display(){
cout<<"Country Info: "<<endl;
cout<<"Country Name: "<<getCountryName()<<endl;
cout<<"City Name: "<<getCityName()<<endl;
cout<<"State Name: "<<getStateName()<<endl;
}
};

int main(){
string countryName,cityName,stateName;
cin>>countryName>>cityName>>stateName;
CountryInfo obj;
obj.setCountryName(countryName);
obj.setCityName(cityName);
obj.setStateName(stateName);
obj.display();
return 0;
}

11)
#include<iostream>
using namespace std;

class BankAccount{
private:
double _balance;
public:
virtual double withdrawal(double amount){

}
double getBalance(){
return _balance;
}
void setBalance(double balance){
_balance = balance;
}
};

class SavingsAccount: public BankAccount{


public:
double withdrawal(double amount){
int result = getBalance()-amount;
setBalance(result);
return getBalance();
}
};

int main(){
double balance,amount;
cin>>balance>>amount;
SavingsAccount obj;
obj.setBalance(balance);
obj.withdrawal(amount);
cout <<"Available balance: "<<obj.getBalance()<<endl;
return 0;
}

12)
#include <iostream>
#include<string>
using namespace std;
int *pt;
int stringLength(char* pt){
int length =0;

while(*pt !='\0'){
length++;
pt++;
}
return length;
}

int main(){ //DO NOT change the 'main' signature

//Fill code here


char str[20] ;

cin.getline(str,20);

cout<<stringLength(str);

return 0;

13)
#include <iostream>
#include <exception>
#include <string>
using namespace std;

void elementReplication()
{
int size, index;
cin >> size;
int arr[size];
for (int i = 0; i < size; i++)
{
cin >> arr[i];
}
cin >> index;
if (index < size)
{
for (int i = 0; i < size; i++)
{
cout << arr[i] << endl;
}
cout << arr[index];
}
else
{
throw runtime_error("Array index is out of range");
}
}

int main()
{
try
{
elementReplication();
}
catch (exception &e)
{
cerr << e.what();
}
return 0;
}

14)
#include<iostream>
using namespace std;

double eligibility_ForAdmission(int a,int b,int c){


if(a<60 || b<60 || c<60){
throw "Not eligible for Admission";
}
return (double)a+b+c;
}

int main(){
int a,b,c;
cin>>a>>b>>c;
try{
cout<<"Total score is "<<eligibility_ForAdmission(a,b,c)<<endl;
}catch(const char *msg){
cerr<<msg<<endl;
}
return 0;
}

You might also like