Cop3223c - homework develop a c program to input each


Homework -

Q1. (Debugging) - No partial credit if you couldn't fix all errors.

Fix the errors in the attached C code. The indentation indicates the desired behavior for the if statement.

Q2. (Formatting)

Write, compile and run the following code in repl.it. You may see different values for (3/2) using different data types and different conversion specifier while we expect to see (3/2=1.5). Simply justify each output seen using a comment for each output in your code. For some cases different compiler, might show different values. You don't need to explain the exact values. Just explain the reason as best as you can.

Q3. (Sales-Commission Calculator)

One large chemical company pays its salespeople on a commission basis. The salespeople each receive $250 per week plus 10 percent of their gross sales for that week. For example, a salesperson who sells $5000 worth of chemicals in a week receives $250 plus 10 percent of $5000 (=$500), or a total of ($500+$250=$750).

Develop a C program to input each salesperson's gross sales for last week and calculates and displays that salesperson's earnings. Process one salesperson's figures at a time. The output should be similar the followings:

 Enter your sales in dollars: 5000.00

Your Salary is: 750.00

Q4. if...else and switch statements

In the attached link, you will see the example used in the class for explaining the switch statement. Instead of using switch, try to rewrite the program using if or if...else statements.

Q5. Converting a flowchart to a program

Write a program in c asking user to input two integers (n and m) and print a message according the following flowchart.

1687_figure.png

Q6. Average

Write a code in C to calculate the average (AVG) of the integers entered by a user.

  • ask the user to enter the values.
  • to show the end of data entry use -1.
  • Print the average like the following example: (suppose the user has entered 2, 3, 4) The average value is 3.00.
  • Use the following formula for calculating average of n integers x1, x2,...,xn. AVG = (x1 + x2+...+xn)/n
  • The default is the user enters just positive integer numbers. (-1 is sentinel value.)

Q7. Perfect square

In mathematics, a square number, sometimes also called a perfect square, is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 9 is a square number, since it can be written as 3×3. (Text from Wikipedia)

Write a program to check if the input number (less than 1000) is the summation of two perfect square or not. For example 25 is 16+9 that both numbers 16 and 9 are perfect square. The output should be such as the following examples:

If input is 3 → the message should be: 3 is not a summation of two perfect square.

If input is 25: → the message should be: 25 is the summation of two perfect square, because 25 = SQ (3) + SQ (4).

Q8. Cruise ship cost

A cruise ship offers the following packages for 5 day / 4 night Cruise & Stay.

Package                         Rate

1. Room only                  $1000.00

2. Room plus Meals         $1000.00 + $200.00 for each person sharing the room (Maximum 3)

Discount Details (just for package 2):

-$50.00: if just one of the occupant is 17 or under

-$80.00: if at least two of the occupants are 17 or under

Write a program to ask the user the following information:

  • The package type (R: Room only and M: Room plus Meals)
  • Number of persons who share a room and their ages.

You may assume that the user input for all the numerical data is entered as integers and greater than zero. Based on this information the program should calculate and display the package cost as below:

Q9. Equivalent resistance for Series and Parallel Resistors

The following formulas are used for calculating the "equivalent resistance" in electric circuits.

In Series resistances: Req = R1 + R2 + R3 + ?

In Parallel resistances: Req = 1/(1/R1 + 1/R2 + 1/R3 + ? )

To calculate the total current (????????????) in a combinational circuit like the following figure, it is enough to use the following formula.

Itotal = V/Req, where V is source voltage.

Write a code in C programming

Asking two questions:

1. The type of resistors model (p for parallel and s for series)

2. The values of the resistors are in "ohm".

After the last resistor was entered, the user should enter "-1" to exit.

Note: there is no negative value resistor and a "0-ohm" resistor in parallel systems cause a short circuit; the equivalent resistor will be 0 and the total current will be infinity.(For series system if all of resistors are zero, a short circuit will be occurred.)

The voltage supply is a fixed value 24 volts.

Calculate the equivalent resistance and report it.

Calculate the total current and report it.

If user entered a negative value for a resistor, the program should show a message and ask the user to make it correct.

All of the elements are considered ideal.

Q10. Calculate the acceleration of a system

An Atwood Machine is a basic physics laboratory device often used to demonstrate basic principles of dynamics and acceleration. The machine typically involves a pulley, a string, and a system of masses. Keys to solving Atwood Machine problems are recognizing that the force transmitted by a string or rope, known as tension, is constant throughout the string, and choosing a consistent direction as positive. To calculate the acceleration of two masses the following formula is used.

2061_fiogure1.png

Write a code in C

Asking masses m1 and m2. (unit should be in kg)

g = 10 m/s2

Calculate the acceleration a (should be positive) and direction (m1: down or m1:up)

Show the results as below:

  • Mass m1 goes .............. down/up................ with acceleration ............ a ............... (Meter per second squared)
  • m1 and m2 are equal and they are balanced.

Attachment:- Assignment File.rar

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: Cop3223c - homework develop a c program to input each
Reference No:- TGS02462362

Expected delivery within 24 Hours