The energy company in Program 1 now uses different rates for residential and business customers. Residential customers pay \$0.12 per kWh for the first 500 kWh. After the first 500 kWh, the rate is \$0.15 per kWh. Business customers pay \$0.16 per kWh for the first 800 kWh. After the first 800 kWh, the rate is \$0.20 per kWh. Write a program to calculate energy charge. You must write and use the following two functions. (a)A main function: Ask the user to enter number of kWh used and customer type (enter R for residential or B for business). Call the bill_calculator function and pass number of kWh used and customer type to it as arguments. You must use positional arguments to pass kWh used and customer type. (b)A bill_calculator function: This function has two parameters to receive number of kWh used and customer type. Calculate and display the energy charge.

The c# program for the scenario is given below.

using System;

public class Program2 {

double total = 0;

static void Main() {

Program2 ob = new Program2();

Console.WriteLine("Enter total energy used in kilo watts ");

int p;

Console.WriteLine("Enter type of customer ");

char t;

ob.bill_calculator(p, t);

Console.WriteLine("Total charge for " + p + " kilo watts electricity for " + t + " customers is " + ob.total);

}

public void bill_calculator(int e, char c)

{

int first=500, second = 800;

double chg_one = 0.12, chg_two=0.15, chg_three = 0.16, chg_four = 0.20;

if(c == 'R')

{

if(e <= 500)

{

total = (e * chg_one);

}

else if(e > 500)

{

total = ( first * chg_one);

total = total + ((e-first) * chg_two);

}

}

if(c == 'B')

{

if(e <= 800)

{

total = (e * chg_three);

}

else if(e > 800)

{

total = ( first * chg_three);

total = total + ((e-second) * chg_four);

}

}

}

}

OUTPUT

Enter total energy used in kilo watts

1111

Enter type of customer

B

Total charge for 1111 kilo watts electricity for B customers is 142.2

Explanation:

The program takes user input for the type of customer and the amount of electric current used by that customer.

The two input values decide the rate at which total charge is calculated.

For residential customers, charges are divided into slabs of 500 or less and more than 500.

Alternatively, for business customers, charges are divided into slabs of 800 or less and more than 800.

User input is taken in main function.

Charges are calculated in the bill_calculator method which takes both user input as parameters.

If else block is used to calculate the charges.

No input validation is implemented as it is not mentioned in the question.

All code is written inside the class. An object is created of the class.

The methods outside main() are called using the object of the class.

Related Questions

How does an Index Organized table differ from a standard table and a typical index?

The thing is that an Index organized table, also known as IOT, is a type of table that stores data in a B tree index structure, which is used by Oracle. Normal relational tables, called heap-organized tables, store rows in any order and  primary key indexes store only the columns included in its definition.

Use the STL class vector to write a C function that returns true if there are two elements of the vector for which their product is odd, and returns false otherwise. Provide a formula on the number of scalar multiplications in terms of n, the size of the vector, to solve the problem in the best and worst cases. Describe the situations of getting the best and worst cases, give the samples of the input at each case and check if your formula works. What is the classification of the algorithm in the best and worst cases in terms of the Big-O notation

Code is provided in the attachment form

Explanation:

Vector Multiplication code:

Vector_multiplication.c file contains C code.

See attachment no 1 attached below

Classification of Algorithm: For creating elements in vector c of size n, number of scalar  multiplications is equal to n. The size of original two vectors scales directly with the number of  operations. Hence, it is classified as O(n).

In an e-credit card transaction the clearinghouse plays the following role:A. validates and verifies the sellers payment information

B. initiates the transfer of money

C. transfers funds between the sellers bank and the buyers bank

D. all of the above

validates and verifies the seller's payment information- A.

Hi Samantha, i have a work with you.

Write a program that takes user input describing a playing card in the following short-hand notation:А Ace
2... 10 Card values
J Jack
Q Queen
K King
D Diamonds
H Hearts
C Clubs

Your program should print the full description of the card. For example, Enter the card notation: QS Queen of Spades
Implement a class Card whose constructor takes the card notation string and whose getDescription method returns a description of the card. If the notation string is not in the correct format, the getDescription method should return the string "Unknown".

In python Language:

cardNotation = raw_input("Enter card notation: ")

# Create a dict for values

cardColors = {"D": "Diamonds",

"H": "Hearts",

"C": "Clubs"}

cardNumberValues = {"A": "Ace",

"J": "Jack",

"Q": "Queen",

"K": "King",

"2": "Two",

"3": "Three",

"4": "Four",

"5": "Five",

"6": "Six",

"7": "Seven",

"8": "Eight",

"9": "Nine",

"10": "Ten"}

# Handle cases when 10 comes in input

if len(cardNotation) == 3:

number = cardNotation[:2]

color = cardNotation[2:]

print cardNumberValues.get(number) + " of " + cardColors.get(color)

elif len(cardNotation) == 2:

number = cardNotation[:1]

color = cardNotation[1:]

print cardNumberValues.get(number) + " of " + cardColors.get(color)

else:

print "INVALID VALUE"

Host A and B are communicating over a TCP connection, and Host B has already received from A all bytes up through byte 126. Suppose Host A then sends two segments to Host B back-to-back. The first and second segments contain 80 and 40 bytes of data, respectively. In the first segment, the sequence number is 127, the source port number is 302, and the destination port number is 80. Host B sends an acknowledgment whenever it receives a segment from Host A. In the second segment sent from Host A to B, what are the sequence number, source port number, and destination port number?

sequence number = 207

source port number = 302

destination port number = 80

Explanation:

The sequence number is 127 + 80 = 207

The source port number is 302, and the destination port number is 80.

Write an if statement that assigns 100 to x when y is equal to 0.

if(y==0)

{

x=100;

}

Explanation:

The above written if statement is for assigning 100 to x when the value of y is equal to 0.To check the value of the y I have used equal operator == which returns true when the value on it's left side is equal to the value to it's right else it returns false and for assigning the value to y I have used assignment operator =.

First it will be checked that the value y is equal to 0.If the then it return true means the if statement will execute.Inside if statement 100 is assigned to x.