Lab Excercise 3

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1.

int main(){
double amt, total;
int assist, payment;
int count = 0;
char ans;
string fname;
ifstream in_file;
ofstream out_file;

2. cout<<"Enter Input File name"<<endl;


cin>>fname;

3. cout << "** PATRICK GAS STATION **" << endl;


in_file.open(fname.c_str());
//in_file.open("C:\Users\Mohammed\Desktop\Week 10\cus_data.txt");
out_file.open("cus_bills.txt");

4. while (in_file>>amt>>assist>>payment){
total = 0;
out_file<< "Customer " << ++count << ": " << endl;

5. if (assist == 0)
total = amt;
else {
if (amt < 50)
total = amt + 0.50;
6. else
total = amt;
}
if (payment == 1)
total = total + 0.05 * total;

7. out_file<< "=======================================\n";
out_file<< "TOTAL charge ==> RM " << fixed << setprecision(2)<<total<<"\n";
out_file<< "=======================================\n\n";
}
8. cout<<"Bill ready";
return 0;
}
1

2 4

8
1. int main() {
int numbers[20];
int index = 0;
int duplicate;
int value; // number entered by user

2. cout << "Enter 20 numbers between 10 and 100: "<<endl;

3. for ( int i = 0; i < 10; )


{
duplicate = 0;
cin >> value;

4. if ( value >= 10 && value <= 100 )


{
for ( int j = 0; j < index; j++ )
{
if ( value == numbers[ j ] )
{
duplicate = 1;
break;
} // end if
} // end 2nd for
5. if ( !duplicate )
{
numbers[index++ ] = value;
i++;
} // end if
6. else
cout << "Duplicate number. "<<endl; // Duplicate number entered
} // end if
7. else
cout << "Invalid number. "<<endl;
} // end 1st for
cout << "The non-duplicate values entered are: "<<endl;

8. // display array of non-duplicates


for ( int i = 0; i < 10; i++ )
cout << numbers[ i ] << " ";

9. cout << endl;


return 0;
}
1

4 5

You might also like