Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439

Students are expected to attempt all of the questions in the Multi choice, Short answer and Lab quesitons BEFORE the lab time.

Multi choice

Q1: What would the below program print?

    #include<stdio.h>    void fun(int x) {        x = 6;    }    int main() {        int y;    y = 5;    fun(y);    printf("%d",y);    }      
A) 4B) 5C) 6D) 7

Q2: How many times is printf('a') executed in the below?

    for (i=0;i<4;i++) {        for (j=i;j<4;j++) {        printf('a');     }    }  
A) 16B) 4C) 10D) 17

Q3: What does the expression "3 + 5 >> 1" evaluate to?

A) 3B) 4C) 5D) 6

Q4: In c the expression "4>>2" would ______________

A) return false.B) not compile.C) evaluate to 1.D) use integer comparison.

Q5:

Given:
#define TIMESTWO(A) (2*A)

the expression "TIMESTWO(2+4)" would

A) evaluate to 12.B) evaluate to 8.C) evaluate to 10.D) evaluate to 6.

Q6: Strings in c _____________

A) are terminated by a null.B) are terminated by a -1.C) store their length in an int.D) are terminated by a ''.

Q7: Given:

int array[] = {2,5,3,9};

The expression "array[array[0]]" would ________

A) evaluate to 5.B) not compile.C) evaluate to 2.D) evaluate to 3.

Q8: Given:

int array[] = {7,5,3,9};

The expression "array[0] + array[2]" would evaluate to _____ .

A) 11B) 7C) 14D) 10

Q9: Given:

char str[] = "Hello!";str[3] = 0;

The length of the string 'str' would be?

A) 0B) 2C) 3D) 6

Q10: A macro will end at the end of the line, however, you can

______________ continue it onto the next line.

A) use backslash () toB) use hash (#) toC) notD) use star (*) to

Q11: In c what would the below code do?

int i;for(i=0;i=10;i++) {   printf("%d ",i);}
A) Not compile due to a syntax error.B) Print 0, 1, ... up to 9.C) Print "10 " repeatedly forever!D) Print nothing.

Short answer questions

Q12: When should you add brackets within an expression? Only add the minimum required??? Add brackets around every operator???

Lab Excercises

Q13 (Excercise)Write a program in c called "welcome" that takes your name from standard input and outputs to standard out "Hello " and your name. So if run it would:

% echo "Eric" | ./welcomeHello Eric

Q14 (Excercise)Write a program that takes a list of floating point numbers line separated from standard input and calculates the average. An example of the code running is:

~/courses/ics/labs/lab2code$ cat test.nums3.07.26.09.51.0~/courses/ics/labs/lab2code$ cat test.nums | ./averageaverage 5.340000

Note you can also type the numbers directly into the terminal, just use Ctl-d to mark the end of file.

Q15 (Excercise)

Add to the above program the ability to also calculate the minimum and the maximum

In-class Group Task

Q16:

In a group of 2 or 3 in the c programming language implement a program that takes a list of numbers on standard input and finds if any 3 numbers sum to 100.
If there are 3 numbers that sum to 100 then output "yes" otherwise output "no".
You can use a simple approach that loads the numbers in any array and uses three nested loops with a check for summing to 100 in the middle.

There are 4 simple test files you can use to help check your implementation.
, , , .

There are three aspects we would like to find out about this program:

Share the results using the whiteboard with the rest of the class.

It would be good to have a few people also implement the same task in some different programming languages such as Java, python, haskell, ...
and compare it with that of c in terms of performance, code size, system calls, code readability, and code complexity.