#include<iostream>
using namespace std;
class Electric
{
float unit;
char name[20];
public:
void accept()
{
cin>>name;
cin>>unit;
}
void print_bill();
};
void Electric::print_bill()
{
float bill=0;
if(unit>=100 && unit<=300)
bill=(500+(unit*0.40));
else if(unit>100 && unit<=300)
bill=(500+(unit*0.40)+(unit*0.50));
else if(unit>300)
bill=(500+(unit*0.60));
if(bill>250)
bill=(bill+(bill*(15/100)));
cout<<"\nConsumer Name:"<<name;
cout<<"\nConsumed:"<<unit;
cout<<"\nBill to pay:"<<bill;
}
int main()
{
Electric e[10];
int i,cnt;
cin>>cnt;
cout<<"\nNumber of Consumers:"<<cnt;
for(i=0; i<cnt; i++)
e[i].accept();
for(i=0; i<cnt; i++)
e[i].print_bill();
return 0;
}
using namespace std;
class Electric
{
float unit;
char name[20];
public:
void accept()
{
cin>>name;
cin>>unit;
}
void print_bill();
};
void Electric::print_bill()
{
float bill=0;
if(unit>=100 && unit<=300)
bill=(500+(unit*0.40));
else if(unit>100 && unit<=300)
bill=(500+(unit*0.40)+(unit*0.50));
else if(unit>300)
bill=(500+(unit*0.60));
if(bill>250)
bill=(bill+(bill*(15/100)));
cout<<"\nConsumer Name:"<<name;
cout<<"\nConsumed:"<<unit;
cout<<"\nBill to pay:"<<bill;
}
int main()
{
Electric e[10];
int i,cnt;
cin>>cnt;
cout<<"\nNumber of Consumers:"<<cnt;
for(i=0; i<cnt; i++)
e[i].accept();
for(i=0; i<cnt; i++)
e[i].print_bill();
return 0;
}
//This code worked for me
ReplyDelete#include
using namespace std;
class Electric
{
float unit;
char name[20];
public:
void accept()
{
cin>>name;
cin>>unit;
}
void print_bill();
};
void Electric::print_bill()
{
float bill=0;
if(unit>=0 && unit<=100)
bill=(500+(unit*0.40));
else if(unit>100 && unit<=300)
bill=(500+(100*0.40)+((unit-100)*0.50));
else if(unit>300)
bill=(500+(100*0.40)+(200*0.50)+((unit-300)*0.60));
if(bill>250)
bill=(bill+(bill*(15/100)));
cout<<"\nConsumer Name:"<>cnt;
cout<<"\nNumber of Consumers:"<<cnt;
for(i=0; i<cnt; i++)
e[i].accept();
for(i=0; i<cnt; i++)
e[i].print_bill();
return 0;
}
This comment has been removed by the author.
ReplyDelete#include
ReplyDeleteusing namespace std;
class Electric
{
float unit;
char name[20];
public:
void accept()
{
cin>>name;
cin>>unit;
}
void print_bill();
};
void Electric::print_bill()
{
float bill=0;
if(unit>=0 && unit<=100)
bill=(500+(unit*0.40));
else if(unit>100 && unit<=300)
bill=(500+(100*0.40)+((unit-100)*0.50));
else if(unit>300)
bill=(500+(100*0.40)+(200*0.50)+((unit-300)*0.60));
if(bill>250)
bill=(bill+(bill*(15/100)));
cout<<"\nConsumer Name:"<>cnt;
cout<<"\nNumber of Consumers:"<<cnt;
for(i=0; i<cnt; i++)
e[i].accept();
for(i=0; i<cnt; i++)
e[i].print_bill();
return 0;
}
The solution posted above is a little incorrect here's the code.All credits to the author i made minor adjustments.
ReplyDelete#include
using namespace std;
class Electric
{
float unit;
char name[20];
public:
void accept()
{
cin>>name;
cin>>unit;
}
void print_bill();
};
void Electric::print_bill()
{
float bill=0;
if(unit<=100)
bill=(500+(unit*0.40));
else if(unit>100 && unit<=300)
bill=(500+(100*0.40)+((unit-100)*0.50));
else if(unit>300)
bill=(500+(100*0.40)+(200*0.50)+((unit-300)*0.60));
if(bill>250)
bill=(bill+(bill*(15/100)));
cout<<"\nConsumer Name:"<>cnt;
cout<<"\nNumber of Consumers:"<<cnt;
for(i=0; i<cnt; i++)
e[i].accept();
for(i=0; i<cnt; i++)
e[i].print_bill();
return 0;
}
This comment has been removed by the author.
ReplyDelete#include
ReplyDeleteusing namespace std;
class Electric{
public:
int tno;
string name;
float unit;
void accept()
{
cin>>name>>unit;
}
void print_bill();
};
void Electric::print_bill()
{
float bill = 0;
if(unit<=100)
bill=(500+(unit*0.40));
else if(unit>100 && unit<=300)
bill=(500+(100*0.40)+((unit-100)*0.50));
else if(unit>300)
bill=(500+(100*0.40)+(200*0.50)+((unit-300)*0.60));
if(bill>250)
bill=(bill+(bill*(15/100)));
cout<<"\nConsumer Name:"<>t;
int ans = t;
for(int i = 0;i<t;i++)
{
ele[i].accept();
}
cout<<"Number of Consumers:"<<ans;
for(int i = 0;i<t;i++)
{
//cout<<"Number of Consumers:"<<ans;
ele[i].print_bill();
}
return 0;
}
#include
ReplyDeleteusing namespace std;
class Electric
{float unit;
char name[20];
public:
void accept()
{cin>>name;
cin>>unit;
}
void print_bill();
};
void Electric::print_bill()
{
float bill=0;
{if(unit<=100)
{bill=(500+(unit*0.40));}
else
if(unit>100 && unit<=300)
{bill=(540+((unit-100)*0.50));}
else
if(unit>300)
{bill=(640+((unit-300)*0.60));}}
if(bill>250)
{bill=(bill+(bill*(15/100)));}
cout<<"\nConsumer Name:"<>cnt;
cout<<"\nNumber of Consumers:"<<cnt;
for(i=0; i<cnt; i++)
e[i].accept();
for(i=0; i<cnt; i++)
{e[i].print_bill();
} return 0;
}
not a single one works
ReplyDelete//Test case 2 is wrong , bill should be 811.21
ReplyDelete#include
using namespace std;
class Electric
{
public:
int noc;
string name;
float unit;
void accept()
{cin>>name;
cin>>unit;}
void print_bill();
};
void Electric::print_bill()
{
{
float bill=0;
if(unit<=100)
bill=(500+(unit*0.40));
else if(unit>100 && unit<=300)
bill=500+(unit*0.40)+((unit-100)*0.10);
else if(unit>300)
bill=500+(unit*0.40)+((unit-100)*0.10)+((unit-300)*0.20);
if(bill>250)
bill=(bill+(bill*(15/100)));
cout<<"\nConsumer Name:"<>cnt;
cout<<"\nNumber of Consumers:"<<cnt;
for(i=0; i<cnt; i++)
e[i].accept();
for(i=0; i<cnt; i++)
e[i].print_bill();
return 0;
}
Copy main() from authors code as I couldn't comment the whole code.
ReplyDelete
ReplyDelete#include
using namespace std;
class Electric
{
float unit;
char name[20];
public:
void accept()
{
cin>>name;
cin>>unit;
}
void print_bill();
};
void Electric::print_bill()
{
float bill=0;
if(unit>=0 && unit<=100)
bill=(500+(unit*0.40));
else if(unit>100 && unit<=300)
bill=(500+(100*0.40)+((unit-100)*0.50));
else if(unit>300)
bill=(500+(100*0.40)+(200*0.50)+((unit-300)*0.60));
if(bill>250)
bill=(bill+(bill*(15/100)));
cout<<"\nConsumer Name:"<>cnt;
cout<<"\nNumber of Consumers:"<<cnt;
for(i=0; i<cnt; i++)
e[i].accept();
for(i=0; i<cnt; i++)
e[i].print_bill();
return 0;
}
//complete the include header. The rest of the code works fine.
#include
ReplyDeleteusing namespace std;
class Electric
{
float unit;
char name[20];
public:
void accept()
{
cin>>name;
cout << "\nConsumer Name:"<< name;
cin>>unit;
cout <<"\nConsumed:"<=0 && unit<=100)
bill=(500+(unit*0.40));
else if(unit>100 && unit<=300)
bill=(500+(100*0.40)+((unit-100)*0.50));
else if(unit>300)
bill=(500+(100*0.40)+(200*0.50)+((unit-300)*0.60));
if(bill>250)
bill=(bill+(bill*(15/100)));
cout << "\nBill to pay:"<> cnt;
cout<<"Number of Consumers:"<<cnt;
Electric e[cnt];
for(int i=0; i<cnt; i++)
{
e[i].accept();
e[i].print_bill();
}
return 0;
}
// This is finally correct
Just complete the header the file
Delete#include
ReplyDeleteusing namespace std;
class Electric
{
float unit;
char name[20];
public:
void accept()
{
cin>>name;
cin>>unit;
}
void print_bill();
};
void Electric::print_bill()
{
float bill=0;
if(unit<=100)
bill=0.40*unit;
else if(unit>=100 && unit<=300)
bill=(40+((unit-100)*0.50));
else if(unit>300)
bill=(140+((unit-300)*0.60));
if(bill>250)
bill=(bill+(bill*(15/100)));
bill+=500;
cout<<"\nConsumer Name:"<>cnt;
cout<<"\nNumber of Consumers:"<<cnt;
for(i=0; i<cnt; i++)
e[i].accept();
for(i=0; i<cnt; i++)
e[i].print_bill();
return 0;
}
//100% working
NOT WORKING
Delete#include
ReplyDeleteusing namespace std;
class Electric
{
float unit;
char name[20];
public:
void accept()
{
cin>>name;
cin>>unit;
}
void print_bill();
};
void Electric::print_bill()
{
float bill=0;
if(unit>=0 && unit<=100)
bill=(500+(unit*0.40));
else if(unit>100 && unit<=300)
bill=(500+(100*0.40)+((unit-100)*0.50));
else if(unit>300)
bill=(500+(100*0.40)+(200*0.50)+((unit-300)*0.60));
if(bill>250)
bill=(bill+(bill*(15/100)));
cout<<"\nConsumer Name:"<>cnt;
cout<<"\nNumber of Consumers:"<<cnt;
for(i=0; i<cnt; i++)
e[i].accept();
for(i=0; i<cnt; i++)
e[i].print_bill();
return 0;
}
100 %
ReplyDeletenot working
ReplyDelete#include
ReplyDeleteusing namespace std;
class Electric
{
public:
float unit;
char name[20];
void accept()
{
cin>>name;
cin>>unit;
}
void print_bill();
};
void Electric::print_bill()
{
float bill;
if(unit>=0 && unit<=100)
bill=(500+(unit*0.40));
else if(unit>100 && unit<=300)
bill=(500+(100*0.40)+((unit-100)*0.50));
else if(unit>300)
bill=(500+(100*0.40)+(200*0.50)+((unit-300)*0.60));
if(bill>250)
bill=(bill+(bill*(15/100)));
cout<<"\nConsumer Name:"<>cnt;
cout<<"\nNumber of Consumers:"<<cnt;
for(i=0;i<cnt;i++)
{
e[i].accept();
}
for(i=0;i<cnt;i++)
{
e[i].print_bill();
}
return 0;
}
it work 100% now 09/03/2021