-
February 16th, 2011, 06:55 AM
#1
help on a program
this program used to work flawlessly 4 years ago but it can only run without showing anything now. i am wondering why is this so. can anyone please help shed some light on this? thanks in advance!
Code:
#include<iostream>
#include <fstream>
#include <string>
using namespace std;
class service_provider //class name service_provided
{
protected :
double total;
double oc,smc;
};
class singtel:public service_provider //class name Singtel with derived class service_provider
{
public :
void plan1(double, double);
void plan2(double, double);
void showplan1(){cout<<"The total charges for Singtel-ione value is: $"<<total<<endl;}
void showplan2(){cout<<"The total charges for Singtel-ione plus is: $"<<total<<endl;}
};
void singtel::plan1(double o, double sm) //first service plan from Singtel
{
if (o<=80) // when outgoing call time is 80 minutes or less,its is free.
oc=0;
else
oc=0.1605*(o-80); // calculate outgoing charge
total=20.33+oc+(0.0535*sm); //calculate total
}
void singtel::plan2(double o, double sm) //second service plan from Singtel
{
if (o<=100) // when outgoing call is 100 minutes or less,there is no charge.
oc=0;
else
oc=0.1605*(o-100); // calculate outgoing charge
if (sm<=500) //when sms is 500 or less,there is no charge.
smc=0;
else
smc=0.0535*(sm-500); //calculate sms charge
total=25.68+oc+smc; //calculate total
}
class starhub:public service_provider //class named Starhub with derived class service_provider
{
public :
void plan1(double, double);
void plan2(double, double);
void showplan1(){cout<<"\nThe total charges for Starhub-powercall is: $"<<total<<endl;}
void showplan2(){cout<<"The total charges for Starhub-powerplay II is: $"<<total<<endl;}
};
void starhub::plan1(double o, double sm) //first service plan from Starhub
{
if (o<=160) //when outgoing call time is 160 minutes or less,there is no charge.
oc=0;
else
oc=0.1605*(o-160); // calculate outgoing charge when outgoing call time exceeds 160 minutes
total=29.96+oc+(0.0535*sm); //calculate total
}
void starhub::plan2(double o, double sm) //second service plan from Starhub
{
if (o<=80) //when outgoing call time is 80 minutes or less,there is no charge.
oc=0;
else
oc=0.1605*(o-80); // calculate outgoing charge when outgoing call time exceeds 80 minutes.
if (sm<=300) // when sms is 300 or less,there is no charge.
smc=0;
else
smc=0.0535*(sm-300); //calculate sms charge when sms exceeds 300.
total=29.96+oc+smc; //calculate total
}
class M1:public service_provider //class named M1 with derived class service_provider
{
public :
void plan1(double, double);
void plan2(double, double);
void showplan1(){cout<<"\nThe total charges for M1-suntalk plus idd 80 is: $"<<total<<endl;}
void showplan2(){cout<<"The total charges for M1-suntalk plus idd 100 is: $"<<total<<endl;}
};
void M1::plan1(double o, double sm) //first service plan from M1
{
if (o<=80) //when outgoing call time is 80 minutes or less,there is no charge
oc=0;
else
oc=0.1605*(o-80); // calculate outgoing charge when outgoing call time exceeds 80 minutes
if (sm<=500) //when sms is 500 or less,there is no charge.
smc=0;
else
smc=0.0535*(sm-500); //calculate sms charge if sms exceeds 500
total=21.40+oc+smc; //calculate total
}
void M1::plan2(double o, double sm) //second service plan from M1
{
if (o<=100) //when outgoing call time is 100 minutes or less,there is no charge.
oc=0;
else
oc=0.1605*(o-100); // calculate outgoing charge when call exceeds 100 minutes
if (sm<=500) //when sms is 500 or less,there is no charge.
smc=0;
else
smc=0.0535*(sm-500); //calculate sms charge when sms exceeds 500
total=25.68+oc+smc; //calculate total
}
void main()
{
char ans;
string str;
ifstream inFile("E:\C++ Project1\mini project\charges.txt"); //link to the text that the program is supposed to read from.
while (! inFile.eof())
{
getline(inFile, str);
cout<<str<<endl;
}
inFile.close();
while(1)
{
double i,o,sm;
cout<<"Expected no of minutes of in-coming local calls: ";
cin>>i;
cout<<"Expected no of minutes of out-going local calls: ";
cin>>o;
cout<<"Expected no of SMS: ";
cin>>sm;
cout<<endl;
singtel s;
s.plan1(o,sm);
s.showplan1();
s.plan2(o,sm);
s.showplan2();
starhub h;
h.plan1(o,sm);
h.showplan1();
h.plan2(o,sm);
h.showplan2();
M1 m;
m.plan1(o,sm);
m.showplan1();
m.plan2(o,sm);
m.showplan2();
while(1)
{
cout<<"\ncontinue?(y/n) : "; //prompting the user to continue or not to continue with the calculation.
cin>>ans;
if (ans=='n'||ans=='y')
break;
}
if (ans=='n')
break;
}
}
Last edited by Marc G; February 17th, 2011 at 09:58 AM.
Reason: Added code tags
-
February 16th, 2011, 06:59 AM
#2
Re: help on a program
SORRY! this program is supposed to calculate mobile phone chargers and display them. it also has to display a file. i can't, for the life of me figure out how to edit my main post. so sorry for the double post!
-
February 16th, 2011, 06:59 AM
#3
Re: help on a program
Welcome to codeguru.
Please use code tags for posting code.
Your file won't open like this...
Code:
ifstream inFile("E:\C++ Project1\mini project\charges.txt");
needs to be
Code:
ifstream inFile("E:\\C++ Project1\\mini project\\charges.txt");
-
February 16th, 2011, 07:01 AM
#4
Re: help on a program
Please, use Code tags, indentations and white spaces.
See Announcement: Before you post....
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|