65 838
Assignments Done
99,1%
Successfully Done
In October 2018

Answer to Question #78864 in C++ for erica

Question #78864
Create a program that computes the tuition of a certain student base on the chosen payment method.

10% discount - CASH
5% discount - 2-installment
10% interest - 3-installment
Expert's answer
#include <iostream>

using namespace std;

struct stud
{
char name[20];
char lastname[20];
int age;
double price;
};

double discount_1(double k)
{
return k - (k * 0.1);
}

double discount_2(double k)
{
return k - (k * 0.05);
}

double discount_3(double k)
{
return k + (k * 0.1);
}
int main()
{
cout << "How many students?" << endl;
int n;
cin >> n;
stud *base = new stud[n];
for (int i = 0; i < n; i++)
{
cout << "Name: ";
cin >> base[i].name;
cout << "Lastname: ";
cin >> base[i].lastname;
cout << "Age: ";
cin >> base[i].age;
cout << "Price: ";
cin >> base[i].price;
cout << endl;
}
cout << endl;
cout << "10% discount - 1-CASH" << endl;
cout << "5% discount - 2-installment" << endl;
cout << "10% interest - 3-installment" << endl;
int c;
double *sum = new double[n];
cin >> c;
switch (c)
{
case 1:

for (int i = 0; i < n; i++)
{
sum[i] = discount_1(base[i].price);
}
break;
case 2:
for (int i = 0; i < n; i++)
{
sum[i] = discount_2(base[i].price);
}
break;
case 3:
for (int i = 0; i < n; i++)
{
sum[i] = discount_3(base[i].price);
}
break;
default:
cout << "This payment method does not exist";
break;
}
double sum1 = 0;
for (int i = 0; i < n; i++)
{
cout << "Name: ";
cout << base[i].name;
cout << endl;
cout << "Lastname: ";
cout << base[i].lastname;
cout << endl;
cout << "Age: ";
cout << base[i].age;
cout << endl;
cout << "Price: ";
cout << base[i].price;
cout << endl;
cout << "Must paid: " << sum[i] << endl;
cout << endl;
sum1 = sum1 + sum[i];
}
cout << "Total: " << sum1 <<endl;
system("pause");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions