Professional Documents
Culture Documents
#include <iostream>
using namespace std;
2)
#include <iostream>
using namespace std;
3)
#include <iostream>
using namespace std;
4)
#include <iostream>
using namespace std;
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;
}
7)
#include <iostream>
#include <iomanip>
#include <string>
class MonthlyExpense {
public:
double household_exp;
double medical,total;
double totalNovemberExpense() {
double totalDecemberExpense() {
//Implement your code
double totalNovDecExpense() {
//Implement your code
total = household_exp + medical;
return this->total;
}
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;
}
};
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.
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();
10)
#include<iostream>
using namespace std;
class Country{
private:
string countryName;
public:
string getCountryName(){
return countryName;
}
void setCountryName(string name){
countryName = name;
}
};
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;
}
};
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;
}
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;
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;
}