Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

COMP 1900 - Fall 2018 Lab 3: Conditionals (12 pts) Number of Peopis: Individual

ID: 3751090 • Letter: C

Question

COMP 1900 - Fall 2018 Lab 3: Conditionals (12 pts) Number of Peopis: Individual Dus: By the end of your lab session today. You MUST submit dis before leaving the lab Grader Please refer to the COMP 1900 syllabus for your lab TA. Questions about grading? Contact him ber firt Coding Style: Use camelCase for variable names, use consistent indentaticn in your code, and include a reasonable asount of comments throughout your code. The TAs may deduct points for poor coding style Within the 1900 folder on your desktop, create a new folder named Labs Suppose that a university uses the following scherme to compute tuition fees. This is loosely based on how ahe U of M actually does it . Tuition costs $400 per eredit hour for each bour up to and including 12 . For each hour beyond 12, the cost is $60 per credit hour Engineering and science courses are charged an extra lab foe of $25 per credit hou Exampls l: Alvin is taking 9 hours, 3 of which are from engineering/science courses. His tuition is calculated like this ($400 per credit hour up to 12) (9 credit hours)$3600 ($25 per E/S credit hour)(3 credit hours) TOTAL S75 53675 Example 2 Brooke is taking 17 hours, 14 of which are from engineering/science courses. (Brooke is not a happy student.) Her tuition is calculated like this: ($400 per credit hour up to 12) (12 credit hours)$4800 ($60 per credit hour beyond 12) (5 credit hours) $300 ($25 per E/S credit hour) (14 credit hours) TOTAL 350 $5450 Lab Assignment 1. (4 pts) Before we write a program to do anything, it's essential that we have a good understanding of the problem we're trying to solve. One way of doing this is to start by developing a set of test cases Remember from your last lab homework that a test case is a set of program inputs that has a known output. In the lab homework, you wrote a test case after you wrote your program. Here we're going to write some test cases before we start writing the program. This technique is called test-drivern development. Writing the tests first can sometimes give insight into how to solve the probiem

Explanation / Answer

Written the code in C++ and Java language. Hence sharing them both.Use according to your requirement.

C++ code to the given requirement:

#include<iostream>

using namespace std;

//main method to run the program

int main()

{

//CONSTANTS to use in the program

int const TUTIONFEEPERHOUR=400;

int const E_S_SERVICES=25;

int const BEYOND_COST=60;

//variable declaration

string name;

char engServCourses;

bool hasEngSerCourse=false;

int courseHours,engServCourseHours=0;

//asking user to input

cout<<"Your good name please:";

cin>>name;

cin.get();

cout<<name<<",input your course hours:";

cin>>courseHours;

cout<<name<<",are your taking engineering/serivces courses?";

cout<<"Enter (y) yes or (n) no:";

cin>>engServCourses;

//checking whether the student has engineering/serivces course or not

if('y'==engServCourses || 'Y'==engServCourses)

{

//if has, then ask him to enter course hours

hasEngSerCourse=true;

cout<<"Please input engineering/serivces course hours?";

cin>>engServCourseHours;

}

cout<<" "<<name<<",here is your TutionFee cost details: ";

//variables to hold data for calculation

int totalCourseFee=0,beyondHours=0;

/*Calculation part based on the inputs*/

if(courseHours<12) {

if(hasEngSerCourse) { //if student engineering/serivces course hours

cout<<"($"<<TUTIONFEEPERHOUR<<" per credit hour upto 12)*("<<courseHours<<" credit hours)";

cout<<" = $"<<(TUTIONFEEPERHOUR*courseHours);

cout<<" ($"<<E_S_SERVICES<<" per E/S credit hour)*("<<engServCourseHours<<"credit hours";

cout<<" = $"<<(E_S_SERVICES*engServCourseHours);

//calculating total course tuition fee

totalCourseFee=(TUTIONFEEPERHOUR*courseHours) + (E_S_SERVICES*engServCourseHours);

cout<<" Total = $"<<totalCourseFee;

}else{

cout<<"($"<<TUTIONFEEPERHOUR<<" per credit hour upto 12)*("<<courseHours<<" credit hours)";

cout<<" = $"<<(TUTIONFEEPERHOUR*courseHours);

//calculating total course tuition fee

totalCourseFee=(TUTIONFEEPERHOUR*courseHours);

cout<<" Total = $"<<totalCourseFee;

}

}else { //if credit hours > 12, then this is the condition

if(hasEngSerCourse) { //if student has engineering/serivces course hours

//calculating beyond hours

beyondHours=courseHours-12;

cout<<"($"<<TUTIONFEEPERHOUR<<" per credit hour upto 12)*(12 credit hours)";

cout<<" = $"<<(TUTIONFEEPERHOUR*12);

cout<<" ($"<<BEYOND_COST<<" per credit hour beyond 12)*("<<beyondHours<<" credit hours)";

cout<<" = $"<<(BEYOND_COST*beyondHours);

cout<<" ($"<<E_S_SERVICES<<" per E/S credit hour)*("<<engServCourseHours<<" credit hours)";

cout<<" = $"<< (E_S_SERVICES*engServCourseHours);

//calculating total course tuition fee

totalCourseFee=(TUTIONFEEPERHOUR*12) + (E_S_SERVICES*engServCourseHours)+(BEYOND_COST*beyondHours);

cout<<" Total = $"<<totalCourseFee;

}else {

//calculating beyond hours

beyondHours=courseHours-12;

cout<<"($" << TUTIONFEEPERHOUR << " per credit hour upto 12)*(12 credit hours)";

cout<<" = $" << (TUTIONFEEPERHOUR*courseHours);

cout<<" ($" << BEYOND_COST << " per credit hour beyond 12)*(" << beyondHours << " credit hours)";

cout<<" = $" << (BEYOND_COST*beyondHours);

//calculating total course tuition fee

totalCourseFee=(TUTIONFEEPERHOUR*12)+(BEYOND_COST*beyondHours);

cout<<" Total = $" << totalCourseFee;

}

}

return 0;

}

Java code:

public class TutionFeeCalculator {

//main method to run application

public static void main(String[]arg) {

//CONSTANTS to use in the program

final int TUTIONFEEPERHOUR=400;

final int E_S_SERVICES=25;

final int BEYOND_COST=60;

//Scanner class object to read input from keyboar(user)

Scanner scan = new Scanner(System.in);

//asking user to input

System.out.print("Your good name please:");

String name=scan.nextLine();

System.out.print(name+",input your course hours:");

int courseHours=scan.nextInt();

System.out.print(name+",are your taking engineering/serivces courses?");

System.out.print("Enter (y) yes or (n) no:");

char engServCourses=scan.next().charAt(0);

boolean hasEngSerCourse=false;

int engServCourseHours=0;

//checking whether the student has engineering/serivces course or not

if('y'==engServCourses || 'Y'==engServCourses)

{

//if has, then ask him to enter course hours

hasEngSerCourse=true;

System.out.print("Please input engineering/serivces course hours?");

engServCourseHours=scan.nextInt();

}

System.out.println(name+" here is your TutionFee cost details: ");

/*Calculation part based on the inputs*/

int totalCourseFee=0,beyondHours=0;

if(courseHours<12) {

if(hasEngSerCourse) { //if student engineering/serivces course hours

System.out.print("($"+TUTIONFEEPERHOUR+" per credit hour upto 12)*("+courseHours+" credit hours)");

System.out.print(" = $"+(TUTIONFEEPERHOUR*courseHours));

System.out.print(" ($"+E_S_SERVICES+" per E/S credit hour)*("+(engServCourseHours+"credit hours"));

System.out.print(" = $"+(E_S_SERVICES*engServCourseHours));

//calculating total course tuition fee

totalCourseFee=(TUTIONFEEPERHOUR*courseHours) + (E_S_SERVICES*engServCourseHours);

System.out.print(" Total = $"+totalCourseFee);

}else {

System.out.print("($"+TUTIONFEEPERHOUR+" per credit hour upto 12)*("+courseHours+" credit hours)");

System.out.print(" = $"+(TUTIONFEEPERHOUR*courseHours));

//calculating total course tuition fee

totalCourseFee=(TUTIONFEEPERHOUR*courseHours);

System.out.print(" Total = $"+totalCourseFee);

}

}else { //if credit hours > 12, then this is the condition

if(hasEngSerCourse) { //if student has engineering/serivces course hours

//calculating beyond hours

beyondHours=courseHours-12;

System.out.print("($"+TUTIONFEEPERHOUR+" per credit hour upto 12)*(12 credit hours)");

System.out.print(" = $"+(TUTIONFEEPERHOUR*12));

System.out.print(" ($"+BEYOND_COST+" per credit hour beyond 12)*("+beyondHours+" credit hours)");

System.out.print(" = $"+(BEYOND_COST*beyondHours));

System.out.print(" ($"+E_S_SERVICES+" per E/S credit hour)*("+(engServCourseHours+" credit hours)"));

System.out.print(" = $"+(E_S_SERVICES*engServCourseHours));

//calculating total course tuition fee

totalCourseFee=(TUTIONFEEPERHOUR*12) + (E_S_SERVICES*engServCourseHours)+(BEYOND_COST*beyondHours);

System.out.print(" Total = $"+totalCourseFee);

}else {

//calculating beyond hours

beyondHours=courseHours-12;

System.out.print("($"+TUTIONFEEPERHOUR+" per credit hour upto 12)*(12 credit hours)");

System.out.print(" = $"+(TUTIONFEEPERHOUR*courseHours));

System.out.print(" ($"+BEYOND_COST+" per credit hour beyond 12)*("+beyondHours+" credit hours)");

System.out.print(" = $"+(BEYOND_COST*beyondHours));

//calculating total course tuition fee

totalCourseFee=(TUTIONFEEPERHOUR*12)+(BEYOND_COST*beyondHours);

System.out.print(" Total = $"+totalCourseFee);

}

}

}

}

Output:

Your good name please:Alen

Alen,input your course hours:17

Alen,are your taking engineering/serivces courses?Enter (y) yes or (n) no:y

Please input engineering/serivces course hours?14

Alen here is your TutionFee cost details:

($400 per credit hour upto 12)*(12 credit hours) = $4800

($60 per credit hour beyond 12)*(5 credit hours) = $300

($25 per E/S credit hour)*(14 credit hours) = $350

Total = $5450

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote