Starting from:
$30

$24

Homework 2 Solution

Files to submit: conversions.c

Time it took Matthew to Complete: 45 mins




All programs must compile without warnings when using the -Wall and -Werror options



Submit only the files requested



Do NOT submit folders or compressed files such as .zip, .rar, .tar, .targz, etc



Your program must match the output exactly to receive credit.



Make sure that all prompts and output match mine exactly.



Easiest way to do this is to copy and paste them



All input will be valid unless stated otherwise



Print all real numbers to two decimal places unless otherwise stated



The examples provided in the prompts do not represent all possible input you can receive.



All inputs in the examples in the prompt are underlined



You don't have to make anything underlined it is just there to help you differentiate between what you are supposed to print and what is being given to your program
If you have questions please post them on Piazza



Restrictions




No global variables are allowed



Your main function may only declare variables and call other functions.



Assumptions




Input is NOT guaranteed to be valid
For this program you will be converting temperatures and distances from one unit to another.







Temperatures




From


Fahrenheit
Celsius


Kelvin














Fahrenheit(F)


F


(F – 32) * 5/9


(F-32) * 5/9 + 273.15














Celsius(C)


(C * 9/5) + 32
C


C + 273.15














Kelvin(K)


(K – 273.15) * 9/5 + 32
K – 273.15


K
































Distances














From
Inches
Feet
Yards
Miles










Inches(I)
I
I/12
I/36
I / 63360










Feet(F)
F*12
F
F / 3
F / 5280










Yards(Y)
Y*36
Y * 3
Y
Y / 1760










Miles(M)
M * 63360
M * 5280
M * 1760
M




















Requirements:




Users should be able to enter both upper and lower case letters for their choices



Any amount of white space should be allowed between a number and its unit



Hints:




This is a large program that you will want to break down into lots of functions to help manage the complexity
When doing the conversions you can save yourself a bit of work by always converting your units into a common one and then converting to the desired one.



For example when converting temperatures you could always convert the given temperature to Celsius and then from Celsius go to the desired unit



Examples on Next Page.

Examples:

T or t for temperature D or d for distance Enter your choice: t



Enter the temperature followed by its suffix (F, C, or K): 0K

Enter the new unit type (F, C, or K): C 0.00K is -273.15C

Pick the type of conversion that you would like to do. T or t for temperature
D or d for distance Enter your choice: d




Enter the distance followed by its suffix (I,F,Y,M): 5 y

Enter the new unit type (I,F,Y,M): i 5.00Y is 180.00I

Pick the type of conversion that you would like to do. T or t for temperature
D or d for distance Enter your choice: J




Unknown conversion type J chosen. Ending Program.

Pick the type of conversion that you would like to do. T or t for temperature
D or d for distance Enter your choice: 10




Invalid formatting. Ending program.
Pick the type of conversion that you would like to do. T or t for temperature
D or d for distance Enter your choice: t




Enter the temperature followed by its suffix (F, C, or K): 42 G G is not a valid temperature type. Ending program.




Pick the type of conversion that you would like to do. T or t for temperature



D or d for distance Enter your choice: t




Enter the temperature followed by its suffix (F, C, or K): 420 Blaze It




Invalid formatting. Ending program.



Files to submit: grade_need.c

Time it took Matthew to Complete: 15 mins




All programs must compile without warnings when using the -Wall and -Werror options



Submit only the files requested



Do NOT submit folders or compressed files such as .zip, .rar, .tar, .targz, etc



Your program must match the output exactly to receive credit.



Make sure that all prompts and output match mine exactly.



Easiest way to do this is to copy and paste them



All input will be valid unless stated otherwise



Print all real numbers to two decimal places unless otherwise stated



The examples provided in the prompts do not represent all possible input you can receive.



All inputs in the examples in the prompt are underlined



You don't have to make anything underlined it is just there to help you differentiate between what you are supposed to print and what is being given to your program
If you have questions please post them on Piazza



Restrictions




No global variables are allowed



Your main function may only declare variables and call other functions.



Assumptions




Input is not guaranteed to be valid
You will be writing a program that calculates the minimum percent needed on a final to get the desired grade in the class. For this problem assume

Grade
Minimum Percent Needed




A
90.00%




B
80.00%




C
70.00%




D
60.00%




F
0.00%







Your program should accept both lower case and upper case letters for the grades



You can no longer assume that the user's input will be valid



Some wrong things the user can do wrong include but aren't limited to



Improperly formatting the input



Choosing a grade that doesn't exist



If the user does something like this, your program should report the error and terminate



Examples on the next page.

Examples

Enter the grade you want in the class: B
Enter your current percent in the class: 75

Enter the weight of the final: 20

You need a grade of at least 100.00% on the final to get a B in the class.

Enter the grade you want in the class: b
Enter your current percent in the class: 75

Enter the weight of the final: 25

You need a grade of at least 95.00% on the final to get a b in the class.

Enter the grade you want in the class: A
Enter your current percent in the class: 85

Enter the weight of the final: 20

You cannot get a A in the class because you would need to score at least 110.00% on the final.

Enter the grade you want in the class: F
Enter your current percent in the class: 90

Enter the weight of the final: 10

You cannot score low enough on the final to get a F in the class.

Enter the grade you want in the class: H
Unknown Grade Received: H. Ending program.

Enter the grade you want in the class: C
Enter your current percent in the class: bob Invalid formatting. Ending program.

Enter the grade you want in the class: A
Enter your current percent in the class: 87

Enter the weight of the final: !75 Invalid formatting. Ending program.




Enter the grade you want in the class: B
Enter your current percent in the class: 12G Invalid formatting. Ending program.

Enter the grade you want in the class: B
Enter your current percent in the class: -35

The number you last entered should have been positive. Ending program.







Files to submit: quad.c

Time it took Matthew to Complete: 5 mins




All programs must compile without warnings when using the -Wall and -Werror options



Submit only the files requested



Do NOT submit folders or compressed files such as .zip, .rar, .tar, .targz, etc



Your program must match the output exactly to receive credit.



Make sure that all prompts and output match mine exactly.



Easiest way to do this is to copy and paste them



All input will be valid unless stated otherwise



Print all real numbers to two decimal places unless otherwise stated



The examples provided in the prompts do not represent all possible input you can receive.



All inputs in the examples in the prompt are underlined



You don't have to make anything underlined it is just there to help you differentiate between what you are supposed to print and what is being given to your program
If you have questions please post them on Piazza



Restrictions




No global variables are allowed



Your main function may only declare variables and call other functions.
1. quad.c (My time 5 min) A quadratic equation is an equation with the following form

ax2∗bx∗c . The roots of a quadratic equation are the values of x that cause the equation to

evaluate to 0 and can be solved using the quadratic formula: x =
−b±√
b2−4ac
Write a
2a




program called quad.c that asks the user to enter the coefficients, a, b and c, and solves for x. Note that there can be either 2 real answers, 1 real answer, or no real answers depending on the values of a, b, and c.

Name your executable quad.out



Only use doubles for this problem
Report your answer to 2 decimal places
a will never be 0
You may need to link in the math library in order to get your program to compile. To do this add the -lm command at the end of your compile statement. Your compile statement should



look like: gcc -g -Wall -o quad.out quad.c -lm

Examples:

Given a quadratic equation of the form a*x^2 + b * x + c Please enter a: 1
Please enter b: 2

Please enter c: 1

There is one real solution: -1.00

Given a quadratic equation of the form a*x^2 + b * x + c Please enter a: 4
Please enter b: 3

Please enter c: 7

There are no real solutions

Given a quadratic equation of the form a*x^2 + b * x + c Please enter a: 3
Please enter b: 11

Please enter c: 8

There are 2 real solutions Solution 1: -1.00 Solution 2: -2.67

More products