Вы находитесь на странице: 1из 4
PRACTICE eS page 1 of 4 FA quiz 2 ] instructor: Jim osborn 70% Rules: No notes 308 ENG 175 Closed book Lo Calculator OK Computers off ER SHEET) Problems 1-1 Problem 1 Name: (ANS State whether or not each of the following C statements a: valid or invalid. If it is invalid, explain why it is invalid. 1. print£("\nThe temperature is titcC",248,T); (the variable T was previously defined as an—tinc# = ror INVALID, Varuble T correrpends to Jot (deten 'trutch ‘\ { is int, Foe it char) a et 2 auwer FL 2. scant ("tliti",b,a); where variables a and b were previously declared as follows: int b; double a; _ YMUALIO. Va F (again dossn't IMVALID. Variable 6 corresponds te Poh? (agen doesn Watch = bis an int Betis fra dou) Alea variadla a (dowkle) corresponds Fo Vetlt), hevarialee tyes should be the same, Also yer ch core bania Mseank 3. scan ("#£8i", temp,ni); where variables *nl and *temp were previously declared as follows: int *i; float *temp; [Watio|<— Awiwen #3 4. #include int input (void) /* function input prototype */ int main(void) VALID. “int input (void) " should pave a semi -colenf; after 6+) fe “iat inpat feoid); 2 Amster 5S. if (x=#11) { /* start of if */ Gould be 22, ard tb curly bracket ould 6€ } not £ INVALID « funder thei [ane 275 Quiz a -2) [ printf ("ti",n/2); Jetse { prints ("ne#i\nns=-2",n); Abe, # [A] Asser #7 Bee 8. : 9. ass if (iro) { bs3 printf ("iso"); ond; felse if (ic=0) { if ((bea)||lc>b)) { printé("i is tin,4); printf ("Warning!*) ; printf ("\ncannot divide" Jelse if ((bec)&&(asb)) { “by zero"); print£ ("Hello"); jelse { Jeise ( | Print£("i is negative"); printf ("Goodbye") ; E Awieh Write C statements for the following: ——— 10, if a is less than 5 or b is ul. oc = varabF equal to 3 (note: recall that Yor" symbol and "equal" symbol is =: (a <5)]1 (0=23)) | 2 Aniwen #S 22. Translate the flowchart into C statements and find the value of Z if A=2.0, B=3.0, C=3.0, and D=4.0 is | xe keys Febe iF(cso) [3e.9¢ Aner, HY fee=50.00; —————t ee else if (speed>é5) fee = 90.00; A fee PER FOUND for carrying extra luggage is $5.00/1b for the first 5 pounds, $10/1b for the next 5 pounds, and $15/1b for the next 5 pounds up to a maximum of 15 pounds extra luggage (for example for 7 lbs, the cost would be (5*5)4(2#10) =28220=$40) . Write a C program using notation used in the previous handouts that asks the user to enter in the amount of extra luggage up to a maximum of 15 pounds using a separate input function as done in the assignments and will send the entered weight back to the main main function through the input function's argument list, as done in the assignments. Within the main function, determine and display to the screen the total cost in dollars(stored as a float variable "c") for the amount of pounds of extra luggage (stored as a float variable "w"), if the extra luggage was 15 pounds or less. If the extra luggage weight was more than 15 pounds, end the program with a message displayed to the screen saying "Weight cannot be above 15 pounds". You may not use any and's (&&) or or's (||). You may use page 4 for extra space if needed. —— ~~ Ffinclede stdio. kD void input (float #5); int main (void) er i Float, AntsontR, BIE inpat (Fo); ao HF (was 5)f CF sek y Jete if (ws wt c= 2st ets hse if (urs 2. . 3 ate OS + (oto) IS; 3 let Win Weight cannet be above /5 pounds.) : Fetorn (2; . , peut ('1\a Cost for extra Mus gae is BRE" c)j Cetuentoy) Yicd input (Float su) ajbupiea rap ion tg the em entetorts Logg we fo6 m mums of [Sporn | Sean page 4 of 4 ENG 175 QUIZ 1 (CONT) ( Use this page for extra space for problem 14 if needed. )

Вам также может понравиться