C/C++ ELECTRIC BILL LAB REPORT 1) Enter your name, student ID, platform (Mac or
ID: 3870823 • Letter: C
Question
C/C++ ELECTRIC BILL LAB REPORT
1) Enter your name, student ID, platform (Mac or PC) and date
Name and StudentID:
Class: CIS054 C/C++ Programming
Platform (Mac or PC):
Language (C or C++):
Date:
OBJECTIVES:
Use if...else if...else statements to compare numeric values
Use Exception Handling in a C++ program to process unexpected or illegal inputs. Use error processing in a C program to process unexpected or illegal inputs. – Refer to the lecture
PROJECT DESCRIPTION:
Create a program that does the following:
1) Read the number of kWh used by the customer
2) compute the Electric Bill with a lower rate for the baseline kWh and a higher rate for kWh over the baseline
3) display the Electric Bill
If writing your program in C++, you must use Try…Throw…Catch Exception Handling to process unexpected or illegal inputs. If writing your program in C, you must test the return from scanf to process input errors.
– Refer to the FAQ links in the lecture section on Canvas
Input kWh from user, convert to double
Determine Base_kWh (up to 500)
Determine Extra_kWh (over 500)
Base_Bill = Base_kWh * 0.27
Extra_Bill = Extra_kWh * 0.55
Electric_Bill = Base_Bill + Extra_Bill
Display Electric_Bill
Explanation / Answer
#include <iostream>
using namespace std;
int main() {
double base_kWh;
double extra_Bill;
int a;
cout << "Please enter number of kWh electricity consumed by the customer ";
cin >> base_kWh;
try
{
if(base_kWh<=0)
{
throw a;
}
double base_Bill = base_kWh * 0.27;
if(base_kWh > 500)
{
double extra_kWh = base_kWh -500;
extra_Bill = extra_kWh * 0.55;
}
cout << "The value you entered is " << base_kWh << " ";
cout<<"Electric Bill is " << base_Bill+extra_Bill;
}
catch(int a)
{
cout<<"An Exception occured due to invalid input, please enter valid number greater than zero";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.