

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


I.Indicate the output that would be produced by each of the following. Consider each case separately. A.(10pts) #include <stdio.h> #include <string.h> main( ) {char s[ ]="Algernon",t[20]="Timbuktu"; printf("%c\n",s[2]); printf("%s\n",&s[2]); printf("%d\n",strncmp(s,"Algeria",5)); printf("%s\n",strcpy(t,strstr(s,"no"))); printf("%d\n",strlen(t));
output: B.(3pts) #include <stdio.h> main( ) {float x = 4.26,y=1.2345,z=0.00000421; printf("%-6.1f,%+.2f\n%.2e",x,y,z);} output: C.(8pts) #include <stdio.h> main( ) {int i = 3,j=11,k=4; float a = 2.4,b=5,x,y; x = j/i; y = a++b; k += 25%j3+4; printf("%f %f %f %d",x,y,a,k);} output:
#include <stdio.h> #include <stdlib.h> int fun1(int ,int *); void fun2(int *,int ); main ( ) {int a=4,b=2,c=5; fun2(&a,b); printf("%d %d\n",a,b); c = fun1(a,&b); printf("%d %d %d",a,b,c); } int fun1(int x,int y) {int c = 3; if(x<=0) return(y+c++); else { y = abs(x-y); c= fun1(x-5,&c);} return(c); } void fun2(int *x,int y) {int a,b;
a = *x+5; b = y-a;
II. Write the C statements necessary to do each of the following. Do not write complete programs. Unless otherwise indicated, assume variables have been appropriately declared and values assigned. A.(3pts)Store your last name in the previously declared character array last.
included in the sum in order for the sum to differ from the true value of by less than EPS, where EPS has previously been defined. C.(3pts)Assign the value 15 to n and the value 13 to k if x is strictly between 1.3 and 4.6, otherwise double x. D.(4pts)Assuming the FILE pointer fin has been assigned to a data file containing only real numbers (which may have decimal parts), determine the number of positive values in the file and write this value, clearly labeled. E.(5pts)Given an m´n array named santa of integers, create a new array named claus consisting of only those rows of santa that have exactly three 3's. F.(5pts)Declare a structure with tag month_data to store the name of a month and its number of days (don't worry about leap year). Define a variable named dec of this type and initialize it to the appropriate values for December. III.(6pts)Write a C function that will determine both the square and the cube roots of its first argument, which is a double. Both roots should be made available to the referencing function but NO global variables should be used. IV. Answer each of the following concerning C++ A.(2pts)Explain briefly the difference between a class and an object. B.(2pts)Explain briefly what is meant by the term operator overloading. V.(10pts)A petroleum exploration company has collected some depth readings (in meters) for a square section of the ocean. The diagonal of the square is parallel to the equator as illustrated below.
The readings are stored in a plain text file named depdata.txt so that the first line of the file contains the total number of readings. This is followed by the readings in row order. Write a complete C program that will A. Read the data into two-dimensional array named depth. B. Determine the location (in terms of row and column) of the deepest point. Print out the location and the depth, clearly labelled. For example, if the data is as given above then a sentence such as The deepest point is 342 meters at row 1, column 1. should be printed.