الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

إجابة السؤال الأول

مغلق
بدأه ميمون في 2 مايو 2004 · 1 رد · 330 مشاهدة · في ارشيف قسم C/C++
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع
#include<iostream>

using std::cout;
using std::cin;
using std::endl;


#include<fstream>

using std::ifstream;
using std::ofstream;
using std::fstream;
using std::ios;
using namespace std;



void displayMenu(); 	 //function prototype
void tabularFormat();  //function prototype
void specific_customer();	//function prototype
void specific_country();	//function prototype
void total_cost(); 	 //function prototype
double totalcosts(double); 	 //function prototype


{//decleration and intialization
	char choice;
	char answer;
	int done=0;  //assume the user doesn't want to exit



  
  cout<<"Enter your choice"<<endl;
  displayMenu();
        cout<<"Your choice: ";
  cin>>choice;//prompt
  cout<<endl;
  
  do{//using do/while
 	 switch(choice)//using switch
 	 {
 	 case 1:
    tabularFormat();
    break;
 	 case 2:
    specific_customer();
    break;
 	 case 3:
    specific_country();
    break;
 	 case 4:
    total_cost();
    break;
 	 case 5:
    cout<<"Are you sure you want to exit the applications y/n:y"<<endl;//prompt
    cin>>answer;
    if(answer=='Y' || answer=='y')
    {
   	 done=1;
    cout<<"Goodbye!"<<endl;
    }
    
    break;
 	 
 	 default:
    cout<<"Invalid choice"<<endl;
 	 }
  }
  while(!done); 	 // !1=0, !0=1

  return 0;
}


void displayMenu()//1st function
{
	cout<<"Enter your choice"<<endl;
	cout<<"1. Display the list of all calls"<<endl;
	cout<<"2. Display the list of all calls made by a specific customer"<<endl;
	cout<<"3. Display total cost of all calls made to a specific country"<<endl;
	cout<<"4. Print into a file named costs.dat the total cost of all calls" 
  <<"made by a specific customer"<<endl;
	cout<<"5. Exit program"<<endl;
}



void tabularFormat()//2nd function
{//decleration and intialization
	int ID,
  country_code,
  call_lasted;
	double cost;

	ifstream callsfile;
	callsfile.open("calls.dat" ,ios::in);
	cout<<"Customer"<<'\t'<<"Country"<<'\t'<<"Units"<<'\t'<<"Unit Cost"<<endl;
	if(callsfile)
	{
  while(!callsfile.eof())
  {
 	 callsfile>>ID>>country_code>>call_lasted>>cost;
 	 if(callsfile)
    cout<<ID<<'\t'<<country_code<<'\t'<<call_lasted<<'\t'<<cost<<endl;
  }
  callsfile.close();
	}

  
  else
 	 cout<<"No records were entered before."<<endl;



}


void specific_customer()//3rd function
{	//decleration and intialization
	int ID,
  entered_ID,
  country_code,
  call_lasted;
	double unit_cost,
     total_cost,
     total=0;
	ifstream callsfile;

	cout<<"Enter Customer ID:  ";
	cin>>entered_ID;
	if(ID >=10000 && ID<=99999)
	{
  callsfile.open("calls.dat" ,ios::in);
  cout<<"Customer"<<'\t'<<"Country"<<'\t'<<"Units"<<'\t'<<"Unit Cost"
 	 <<'t'<<"Total Cost"<<endl;


  if(callsfile)
  {
  while(!callsfile.eof())
  {
 	 callsfile>>ID>>country_code>>call_lasted>>unit_cost>>total_cost;
 	 if(callsfile)
 	 {
    total_cost=call_lasted*unit_cost;
    if(ID==entered_ID)
   	 cout<<ID<<'\t'<<country_code<<'\t'<<call_lasted<<'\t'<<unit_cost<<'\t'<<total_cost<<endl;
    total=total+total_cost;
 	 }
  }
  callsfile.close();
  cout<<"Total cost of all calls="<<endl;
  }
	}
	else
  cout<<"No records were entered before."<<endl;


}


void specific_country()//fourth function
{	//decleration and intialization
	int entered_country,
  ID,
  country_code,
  call_lasted;
	double unit_cost,
 	 total=0,
     totalcost;
	ifstream callsfile;
	callsfile.open("calls.dat" ,ios::in);

	cout<<"Enter Country ID:  ";
	cin>>entered_country;

	if(entered_country >=100 && entered_country<=999)
	{
  callsfile.open("calls.dat" ,ios::in);
  cout<<"Customer"<<'\t'<<"Country"<<'\t'<<"Units"
 	 <<'\t'<<"Unit Cost"<<'\t'<<"Total Cost"<<endl;

    if(callsfile)
	{
  while(!callsfile.eof())
  {
 	 callsfile>>ID>>country_code>>call_lasted>>unit_cost>>totalcost;
 	 if(callsfile)
    totalcost=call_lasted*unit_cost;
    if(country_code == entered_country)
   	 cout<<ID<<'\t'<<country_code<<'\t'<<call_lasted<<'\t'<<unit_cost<<totalcost<<endl;
   	 total=total+totalcost;
  }
  callsfile.close();
  cout<<"Total cost of all calls="<<endl;
	}

}  
  else
 	 cout<<"No records were entered before."<<endl;


	}



double totalcosts()//fifth function
{	//decleration and intialization
	int unit;
	double cost,totalcost=0,total=0;
	totalcost=(unit*cost);
	total+=totalcost;
return 1;
}
void total_cost()//sixth function
{
//decleration and intialization
	int ID;
	double total,
     totalcost;
    ifstream callsfile;
	ofstream costfile;
	callsfile.open("calls.dat" );


	cout<<"Enter Customer ID:  ";
	cin>>ID;

    double totalcosts();

	costfile.open("costs.dat" );

	costfile<<total<<endl;
	cout<<"Printing total cost of all calls made by customer # 12345 to file costs.dat..."<<endl;
	costfile.close();
	callsfile.close();

}

تم تعديل هذه المشاركة بواسطة HGB في 3 مايو 2004 في 18:21

#2

عن اي سؤال تجيب؟

banner_60_468.gif

NOTHING IS IMPOSSIBLE

هذا الموضوع مغلق.

مواضيع مشابهة