Answer to Question #318642 in C++ for Tito

Question #318642

26. Suppose that the tuition for a university is $10,000 this year and Write a program that computes the tuition in ten years and the total cost of four years"




increases 5% every year.




worth of tuition starting ten years from now. 27. Write a program that convert from kilograms to pounds, miles to kilometers, and from




hour to minutes based on the choice of the user. 28. Write a program that prompts the user to enter the number of students and each student's




name and score, and finally displays the student with the highest score and the student




with the second-highest score.




29. Write a program that prompts the user to enter the number of students and each student's name and score, and finally displays the name of the student with the highest score.

1
Expert's answer
2022-03-28T13:52:41-0400

26

#include <iostream>
#include <iomanip>
using namespace std;

int main() {
    double  year_cost=10000;
    double tot_cost=0;

    for (int i=0; i<4; i++) {
        tot_cost += year_cost;
        year_cost *= 1.05;
    }
    for (int i=4; i<10; i++) {
        year_cost *= 1.05;
    }

    cout << fixed << setprecision(2) 
         << "The tution in ten years will be $" << year_cost << endl;
    cout << "The total cost of four years is $" << tot_cost << endl;

    return 0;
}


27.

#include <iostream>
using namespace std;

void kg2lb() {
    double kg, lb;

    cout << "Enter number of kilograms: ";
    cin >> kg;
    lb  = kg *2.20462;
    cout << kg << " kg = " << lb << " lb" << endl;
}


void mil2km() {
    double miles, km;

    cout << "Enter number of miles: ";
    cin >> miles;
    km  = miles * 1.60934;
    cout << miles << " miles = " << km << " km" << endl;
}


void hr2min() {
    int hr, min;

    cout << "Enter number of hours: ";
    cin >> hr;
    min = hr * 60;
    cout << "In " << hr << " hours " << min << " minutes" << endl;
}


int main() {
    int choice;

    cout << "1. Kilogram to pounds" << endl;
    cout << "2. Miles to kilometers" << endl;
    cout << "3. Hours to minutes"<< endl;
    cout << ">>> ";
    cin >> choice;
    cout << endl;

    if (choice == 1) {
        kg2lb();
    }
    else if (choice == 2) {
        mil2km();
    }
    else if (choice == 3) {
        hr2min();
    }
    else {
        cout << "Wrong choice" << endl;
    }

    return 0;
}


28.

#include <iostream>
#include <string>
using namespace std;

int main() {
    int n;
    string name;
    int score;
    string name1, name2;
    int max_score=-1;

    cout << "Enter number of students: ";
    cin >> n;

    for (int i=0; i<n; i++) {
        cout << "Enter name of the " << i+1 << "th student: ";
        cin >> name;
        cout << "Enter score: ";
        cin >> score;
        if (score >= max_score) {
            max_score = score;
            name2 = name1;
            name1 = name;
        }
    }
    cout << "Student with the highest score: " << name1 << endl;
    cout << "Student with the second-highest score: " << name2 << endl;

    return 0;
}


29.

#include <iostream>
#include <string>
using namespace std;


int main() {
    int n;
    string name;
    int score;
    string max_name;
    int max_score=-1;

    cout << "Enter number of students: ";
    cin >> n;

    for (int i=0; i<n; i++) {
        cout << "Enter name of the " << i+1 << "th student: ";
        cin >> name;
        cout << "Enter score: ";
        cin >> score;
        if (score >= max_score) {
            max_score = score;
            max_name = name;
        }
    }
    cout << "Student with the highest score: " << max_name << endl;

    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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS