Question

In: Computer Science

Branching Program write a program to do the following: A university needs to compute the tuition...

Branching Program write a program to do the following: A university needs to compute the tuition of its students. They will ask for the name, the number of units the student is taking, and their residency status. R=resident , N = non- resident. The tuition to be computed as follows: non-resident students pay $100 per unit; resident students pay $50 per unit if they take 12 or units or more and $75 per unit if they take less than 12 units Users may enter upper or lower case letters (R/r or N/n) for residency. Error check the user input and output an appropriate message if the input is invalid. If the input is valid, determine the unit price, and calculate the tuition. Output student name, residency, status, number of units, part-time(<12 units) or full-time ( 12 and over units), the price per unit, and the total cost. Do not use loops.

Solutions

Expert Solution

Here is the solution,

Language : C++ & Java

here is the C++ code:-

// your code starts here
#include <iostream>

using namespace std;

int main()
{
// variable declarations
string name;
int units;
char status;
// accepting student name
cout<<"Enter Student Name:";
getline(cin,name);
cin.sync(); // for clearing the input buffer
cout<<"Enter no. of Units:";
cin>>units;
// for validation
if (units <= 0 )
{
cout<<"Sorry invalid input...";
exit(0);
}
cout<<"Enter Student Status:";
cin>>status;
// for validation
if (!(status =='R' || status =='r' || status =='N' || status =='R'))
{
cout<<"Sorry invalid input...";
exit(0);
}
float unit_charges=0;
if (status == 'N' || status == 'n')
{
// for non resident units * 100
unit_charges = units * 100;

}
else if(status == 'R' || status =='r')
{
if(units >= 12)
{
// if units >=12 then per unit charge 50
unit_charges = units * 50;
}
else if(units < 12)
{
// if units < 12 then per unit charge 75
unit_charges = units * 75;
}
}

// displaying the output
cout<<endl;
// to display name
cout<<"Student Name : " << name<<endl;
// to display status
cout<<"Residence : " <<status<<endl;
// to display units
cout<<"No. of Units : " <<units<<endl;
// to display part time/ full time
if(units < 12)
cout<<"Type : Part-Time"<<endl;
else if(units >= 12)
cout<<"Type : Full-Time"<<endl;
// to display charges per unit
if(status =='N' || status == 'n')
cout<<"Price Per unit:$"<<100<<endl;
else if(status =='R' || status == 'r')
{
if(units >=12)
cout<<"Price Per unit:$"<<50<<endl;
else if(units <12)
cout<<"Price Per unit:$"<< 75<<endl;
}
// to display the total cost
cout<<"Total Cost :$"<<unit_charges;
cout<<endl;
cout<<endl;

return 0;
}
// code ends here
Here is the sample output:-

Here is the screenshot of c++ code:-

// Java code

// your code starts here
import java.util.*;
class BranchingDemo {
public static void main(String[] args) {
String name;
int units;
char status;
Scanner input = new Scanner(System.in);
System.out.println("Branching Demo Program");
// accepting name
System.out.println("Enter student name:");
name = input.nextLine(); // to read name
System.out.println("Enter number of units:");
units = input.nextInt(); // to read units
// check for valid input of unit
if (units <= 0 )
{
System.out.println("Sorry invalid input...");
System.exit(0);
}
System.out.println("Enter Status (R or N) :");
status = input.next().charAt(0); // to read status
// check for valid input of status
if (!(status =='R' || status =='r' || status =='N' || status =='R'))
{
System.out.println("Sorry invalid input...");
System.exit(0);
}
  
// calculations
float unit_charges=0;
if (status == 'N' || status == 'n')
{
// for non resident units * 100
unit_charges = units * 100;

}
else if(status == 'R' || status =='r')
{
if(units >= 12)
{
// if units >=12 then per unit charge 50
unit_charges = units * 50;
}
else if(units < 12)
{
// if units < 12 then per unit charge 75
unit_charges = units * 75;
}
}
// displaying the output
System.out.println();
// to display name
System.out.println("Student Name : " + name);
// to display status
System.out.println("Residence : " + status);
// to display units
System.out.println("No. of Units : " + units);
// to display part time/ full time
if(units < 12)
System.out.println("Type : Part-Time");
else if(units >= 12)
System.out.println("Type : Full-Time");
// to display charges per unit
if(status =='N' || status == 'n')
System.out.println("Price Per unit:$"+ 100);
else if(status =='R' || status == 'r')
{
if(units >=12)
System.out.println("Price Per unit:$"+ 50);
else if(units <12)
System.out.println("Price Per unit:$"+ 75);
}
// to display the total cost
System.out.println("Total Cost :$"+ unit_charges);
  
}
}
// code ends here

Here is the sample output:-

here is the screenshot of the code:-

Thank You.


Related Solutions

For this program you will be looking at future tuition at your university. In 2020, the...
For this program you will be looking at future tuition at your university. In 2020, the tuition for a full time student is $6,549 per semester, the tuition for a part time student is $3,325. The tuition will be going up for the next 7 years at a rate of 3.5% per year. Write a program using if-else and a loop. Ask the user if they are a full time or part time student, then display the projected semester tuition...
For this program you will be looking at future tuition at your university. In 2020, the...
For this program you will be looking at future tuition at your university. In 2020, the tuition for a full time student is $6,549 per semester, the tuition for a part time student is $3,325. The tuition will be going up for the next 7 years at a rate of 3.5% per year. Write a program using if-else and a loop. Ask the user if they are a full time or part time student, then display the projected semester tuition...
During this course you will design a program for a state university. The university needs a...
During this course you will design a program for a state university. The university needs a website design that will enable students to order books online. Each week you will receive additional instructions for the elements of the design based on the needs of the university. The elements will correspond with the concepts and skills you learn that week. According to the university's website design request, students need to order five books, one for each of the five required courses...
Write a complete program in java that will do the following:
Write a complete program in java that will do the following:Sports:             Baseball, Basketball, Football, Hockey, Volleyball, WaterpoloPlayers:           9, 5, 11, 6, 6, 7Store the data in appropriate arraysProvide an output of sports and player numbers. See below:Baseball          9 players.Basketball       5 players.Football           11 players.Hockey            6 players.Volleyball        6 players.Waterpolo       7 players.Use Scanner to provide the number of friends you have for a team sport.Provide an output of suggested sports for your group of friends. If your...
Program in C++ **********Write a program to compute the number of collisions required in a long...
Program in C++ **********Write a program to compute the number of collisions required in a long random sequence of insertions using linear probing, quadratic probing and double hashing. For simplicity, only integers will be hashed and the hash function h(x) = x % D where D is the size of the table (fixed size of 1001). The simulation should continue until the quadratic hashing fails.*********
Write a program to compute intersection of two sorted array of integers and compute the CPU...
Write a program to compute intersection of two sorted array of integers and compute the CPU time for different sets of unsigned integers generated by a random number generator. Test this using the same data sets: atleast 3 of size 1000 integers, atleast 3 of size 10000 integers, atleast 3 of size 100000 integers, atleast 3 of one million integers and atleast 3 of size 10 million integers DONT FORGET CPU TIME FOR EACH ONE NO HASH SET
4.9 Branching Practice - Python Exercise #Write the code for the following # Exercise 1 #...
4.9 Branching Practice - Python Exercise #Write the code for the following # Exercise 1 # Ask user for a number using an input statement (no prompt) & assign the input to a variable # Convert the user entry to an integer and assign it to a variable # Condition: user entry is greater than zero # Action: display the following word on screen: positive # Exercise 2 # Ask user for a number using an input statement (no prompt)...
Which of the following is not an example of an accommodation and enhancement program? A)Tuition reimbursement...
Which of the following is not an example of an accommodation and enhancement program? A)Tuition reimbursement B)Stress management C)Family assistance D)Disability insurance
write a java code Write a generic program to compute the sum of 30 terms of...
write a java code Write a generic program to compute the sum of 30 terms of the following series. (181 - 5)/31 + (186 + 9)/34 - (191 - 13)/37 + (196 + 17)/40 + . . . . . 1 5 11 Note: the 3rd, 6th, 9th term etc, has a negative sign in front of parenthesis. User Input: None Expected output: Term Ratio Sum 1 5.677 5.677 2 5.735 11.413 3 -4.811 6.602
in C++ Write a program to compute the current and the power dissipation in an AC...
in C++ Write a program to compute the current and the power dissipation in an AC circuit that has four resistors R1, R2, R3, and R4 in parallel. The voltage source is V. Test your solution with various voltage levels and resistor values. Execute and submit the program and the results in screen captures. Please note that the equivalent resistor is given by 1/Rtotal = 1/R1 + 1/R2 + 1/R3 + 1/R4 and the current I is given by I...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT