finalsp01sol

# finalsp01sol - EGN 3210 Final Spring 2001 NAME ran 9 SS# To...

This preview shows pages 1–8. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: EGN 3210 Final Spring 2001 NAME ran 9 SS# To receive maximum partial credit, clearly show all of your work. 1. (Functions) Write a function to perform division. The function is to accept 3 doubles, the numerator and the denominator and a pointer to the remainder. The function is to divide the 2 doubles and produce a quotient and a remainder. The quotient is to be returned through the function name and the remainder through the pointer in the third parameter. Assume you have the functions ﬂoor ( ) which returns the integer part of a double and the function ﬁac( ) which returns the fractional part of a double. Algorithm: Result = numerator / denominator; Quotient = ﬂoor(result) Remainder = frac(result) * denominator gawk/e aiVlSEK aoulale WW", 30“”? 9am”) éOmb/f * V€m> 3 60¢“? Q“0,l€€4wi+j ﬁﬁwH‘: l/lviVl/I/ae‘vxam @m0‘£)@0r[g€4w|+>> 7696M : gyng’iK €89” if) V6 hm 62w) 3 2. (File) Write a program to two ﬁles called “inputl.dat” and “input2.dat” both for input. Read the ﬁrst 5 integers from each ﬁle and compute the sum of the 10 integers. Print the sum then close the ﬁles. Print an error message if the ﬁle carmot be opened. FILE ﬁg?) % . Qov (wmx < ng++> é ‘ x u M . (§(dwg(§€]/(X> ) 220) 9%” ; gww‘ 3 éov(x:&x>;x<sg x++> Z \ (éiﬁw€[e<62, H Z3H/£X>) éwvv»: 94"") 3 M066 [3 1,, . - / m) Q I? J -. f 6/095 a _ €m> I‘é é //€vz2 Wm.“ 3. (Classes) Create a class called Point that has as private elements the x and y positions on the Cartesian graph. The class is to have as public the color code of the point represented by an integer, a function that retums the distance the point is from the origin, use the formula dist = ‘le + y2 , and a constructor that initializes the point’s x and y position and sets the color to 0. 6/496 9(er (PYIVG 1T6”. 3001b).? gambie “‘th 2 (Y imi‘ (Olaf). aawbk QS‘X'C) ’ ad‘va §ZV+(?<*X +y*>’)) % ‘ (VOM‘i'[a0mwe MewX, &6m)9/€ “CV7> é X: hewx‘) >/ : Mew 5W0! % 4. (Scope). What is the output if you run the program 3 times and each time you enter 1,2 and 3 for k. intz; void mainO i{nt *p,*q,x,y’k, (k==1) x: r 7 5/ 2: w[3]= {10,20,30}; W! : )0 u? ; :29 Va, ,— 770 char 0; 1 £355)? (k==2) X;3 2:5 23/R 3:333 wt: )0 \Ja :90 v3,— 39 q=&(w[1]); X; 7/ y; 23 2‘ : 37 g) scanf(“%d”, &k); w ~ \J ; 30 U3 2 0 z=3m *(q + 1) = 90; } printf (“x =%d, y= %d z= %d”, x, y, z); printf(“ w[0] = %d w[l] = %d w[2]=%d \n”, w[y]: w[21, w[zﬁ; } 0:2 5. (pointers and arrays) On the right side show what is in the array. main( ) b { int a[2][3],b[5],*p; - _. tr I a[l][0] = 1 *(a + 4) = 2; p=a+x *(P + 2) = 3; P = &(a[0][2]); *(p — 1) = 4; } “&WWQIXA 0%: w~¥7°~k< 6. (Short answers). Answer each of the following. —- l , 0 Assumea=3,b=7,c=l7. ,h ] for(x=-1;x<2;x~H-) I 0/0 for(y=0;y<2;y++) Q} l printf("%d %d\n",x,y); — "' l / 5 for(x=0;x<8;x=x+3) { y = 1; while ( y < x ) ’5 l ‘ 3’ a printf(" %d %d \n ", x, y); I 1': y I. 2; 5/ I } 6 I a 6 2 ‘f j) 61 for (x = 0; x < 6; x++) for(y=0;y<10;y4+) 8’? if(x+y==10) . 3/7 printf("%d %d\n",x,y); . 5 if((a=\{3&&b<\{0)||(a==4&&b>10)) ’/ printf(“Red \n”); else ' printf(“Blue \n”); Q 9 5 if(a==3 Hb‘<4) if(b==5&&c< 10) X printf(“Yellow \n”); else printf(“Green \n” ; else' if(b== 15 &&c> 10) printf (“Orange \n” ; l e se printf(“Black \n”); L 6 9V1 7. (Declarations) Declare the following variables. Do not initialize them. a. Declare a structure called address with 3 ﬁelds of type string called street, city, and state. §Twct Mam; glam §1LM€+[30] [kw C'IL/[gpj‘j 36km Giafffgol‘) b. Declare an array of 3 by 5 where each element is a pointer to struct address called aapsa. abawé 5 aéqaféaig] [5] c. Declare 2 objects of type Point as deﬁned in problem 4 called p1 and p2. The objecth is to be initialized to 5 and 3 and p2 to 10 and 7. (fagwjf (W (93% 0720027)) d. Declare a 3 dimensional array, 3 by 5 by 10 of integers called aaai. /1w’+— am; [3153 0033 e. Declare an array with 10 elements where each element is an 80-character string called as. c kw a §[%0][10] ...
View Full Document

## This note was uploaded on 05/11/2008 for the course EGN 3210 taught by Professor Fernando during the Fall '05 term at University of Central Florida.

### Page1 / 8

finalsp01sol - EGN 3210 Final Spring 2001 NAME ran 9 SS# To...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online