Polymorphic TVs

Questions on C++

Question 1:

Solution 1:

#include<bits/stdc++.h>

#include <math.h>

using namespace std;

#define MOD 1000000007

#define ll long long

#define slld(t) scanf(“%lld”,&t)

#define sd(t) scanf(“%d”,&t)

#define sld(t) scanf(“%ld”,&t)

#define pd(t) printf(“%d\n”,t)

#define plld(t) printf(“%lld\n”,t)

#define pcc pair<char,char>

#define pp pair<int,int>

#define pll pair<ll,ll>

#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)

#define mp(a,b) make_pair(a,b)

#define F first

#define S second

#define pb(x) push_back(x)

struct TV

{

charscreenType; intscreenSize; string resolution; double price; bool standard;

TV()

{

screenType = ‘L’; screenSize = 50;resolution = “HD”; price = 600; standard = 1;

}

TV setOrder()

{

TV tt = TV();

cout<<“Enter your specifications : “<<endl;

cout<<“Enter screenType”<<endl;

char p;

cin>>p;

cout<<“Enter screenSize”<<endl;

intss;

cin>>ss;

cout<<“Enter resolution”<<endl;

string x;

cin>>x;

tt.screenSize = ss;

tt.screenType = p;

tt.resolution = x;

returntt;

}

void display()

{

if(standard==1)

{

cout<<“Standard TV”<<endl;

}

else

{

cout<<“Customized TV”<<endl;

}

}

doublegetPrice()

{

return price;

}

boolgetStandard()

{

return standard;

}

};

int foo(TV t)

{

intans = 600;

if(t.screenType==’O’)

{

ans += 300;

}

if(t.screenSize>50)

{

int ans1 = (t.screenSize-50)*20;

if(t.screenType==’O’)

{

ans1 *= 2;

}

ans += ans1;

}

if(t.resolution==”UHD”)

{

ans += 200;

if(t.screenType==’O’)

{

ans += 200;

}

}

returnans;

}

void display(TV t)

{

cout<<t.resolution<<” “<<t.price<<” “<<t.screenSize<<” “<<t.screenType<<” “<<t.standard<<endl;

cout<<“Thanking for using this program”<<endl;

}

int main()

{

TV t = TV();

//    cout<<t.resolution<<” “<<t.price<<” “<<t.screenSize<<” “<<t.screenType<<endl;

t = t.setOrder();

//    cout<<t.resolution<<” “<<t.price<<” “<<t.screenSize<<” “<<t.screenType<<endl;

intans = foo(t);

cout<<“This will cost you “<<ans<<endl;

}

Question 2:

Solution 2:

#include<bits/stdc++.h>

#include <math.h>

using namespace std;

 

#define MOD 1000000007

#define ll long long

#define slld(t) scanf(“%lld”,&t)

#define sd(t) scanf(“%d”,&t)

#define sld(t) scanf(“%ld”,&t)

#define pd(t) printf(“%d\n”,t)

#define plld(t) printf(“%lld\n”,t)

#define pcc pair<char,char>

#define pp pair<int,int>

#define pll pair<ll,ll>

#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)

#define mp(a,b) make_pair(a,b)

#define F first

#define S second

#define pb(x) push_back(x)

 

class Rental

{

private:

stringshopId; //s1, s2, s3 ….. s10

stringmallId; //m1, m2, m3

int month;

double amount;

public:

Rental(string=” “, string=” “, int = 0, double= 0);

voidsetRental(string x, string y, int a, double b)

{

shopId=x;

mallId=y;

month=a;

amount = b;

}

stringgetShopId()

{

returnshopId;

}

stringgetMallID()

{

returnmallId;

}

intgetMonth()

{

return month;

}

doublegetAmount()

{

return amount;

}

};

 

 

class Consolidation

{

private:

Rental r[50];

intrcount=0;

public:

voidreadFile()

{

// take file input here

// use this method

fstreamdatafile;

datafile.open(“your file name”);

while(!datafile.empty())

{

// take inputs here

datafile>>value;

rcount += value;

// r count is rent for that month

}

}

voidwriteFile(int month)

{

// this will write file to the output location

fstreamdatafile;

datafile.open(“output file name”);

while(!datafile.empty())

{

// write output here

datafile<<“variables”<<endl;

datafile<<rcount<<endl;

}

}

};

 

int main()

{

Consolidation s;

s.readFile();

s.writeFile();

}