CS1313 final (quizzes)

Ace your homework & exams now with Quizwiz!

2^40 is approximately 10 to what power?

10^12

2^10 is approximately 10 to what power?

10^3

EXPRESS the approximate number of bytes in each of these to the nearest power of 10 (that is, as 10x for the appropriate value of x): kilobyte terabyte yottabyte zettabyte

10^3 10^12 10^24 10^21

HOW MUCH will CodeLab cost?

$25

For the two examples of arithmetic operations, above, WHAT ARE THE ASSOCIATED OPERATORS?

(a) + (b) -

WHAT are the three major categories of hardware that computers typically have?

(a) CPU (b) Storage (c) I/O

WHAT THREE COMPONENTS does every language have?

(a) grammar (b) symbols (c) semantics

NAME three ways to set the value of a variable

(a) input (b) assignment (c) initialization

NAME THREE EXAMPLES of programming languages.

(a) java (b) python (c) C

WHAT FOUR THINGS does every variable have?

(a) name (b) address (c) data type (d) value

For each of the above four things, WHO chooses it?

(a) the name is chosen by the programming (b) the address is chosen by the compiler (c) the data type is chosen by the programmer (d) the value is sometime chosen by the programmer and sometimes while the program is running

GIVE TWO EXAMPLES of binary arithmetic operations (NOT operators).

(a) x+z (b) x-o

HOW does a C compiler know that the following line is a comment? /****************************************/

/* and */

HOW MANY free CodeLab exercises will you be allowed, before you have to pay for the rest of the semester's CodeLab exercises?

10

WHAT PERCENTAGE of your grade will come from quizzes?

10

WHAT PERCENTAGE of your grade will come from short programming (CodeLab) assignments?

10

Is an assignment an ACTION or an EQUATION?

action

NAME TWO THINGS that every main memory location has.

address value

WHERE in a program is the declaration section?

at the beginning of program after the open block

WHEN will your TA take attendance?

beginning and end of lab

For each of the following, WRITE A DECLARATION STATEMENT for a named constant representing this quantity. For each, you should choose an appropriate data type and initialization value. The name should comply with the "favorite professor" rule, and should also be a valid C identifier. Assume that int variables and float variables take 4 bytes (32 bits) each. normal human body temperature in degrees Fahrenheit

const float body_temp_in_degrees_fahrenheit=98.6;

WHAT does the term I/O stand for?

input/output

A C program has the following declarations: float x = 28.0, y = 36.0, z = 48.0; int i = 28, j = 40, k = 48; char sky_is_blue = 1; char chair_is_green = 0; char chair_is_brown = 1; WRITE THE RESULT of evaluating each of the following expressions. SHOW ALL INTERMEDIATE STEPS, including the type of each subexpression (indicating a float with a decimal point). If you are giving the results of testing the C program, mark TESTED. k >= j && j >= y

int 48 >= int 40 && int 40 >= float 36.0 1 && 40 >= float 36.0 1 >= float 36.0 1

For each of the following, WRITE A DECLARATION STATEMENT for a variable representing this quantity. For each, you should choose an appropriate data type. The name should comply with the "favorite professor" rule, and should also be a valid C identifier. You DON'T need to initialize the variables. Assume that int variables and float variables take 4 bytes (32 bits) each. the number of students in CS1313

int number_of_students_in_CS1313

For each of the following, WRITE A DECLARATION STATEMENT for a variable representing this quantity. For each, you should choose an appropriate data type. The name should comply with the "favorite professor" rule, and should also be a valid C identifier. You DON'T need to initialize the variables. Assume that int variables and float variables take 4 bytes (32 bits) each. a spaceship's speed in inches per century, approximated to three significant figures (assume that the spaceship travels at 99% of the speed of light)

int spaceshipSpeedInInchesPerCentury; float inchesPerCentury

Unix Questions: Give the Unix commands to accomplish the following task: EDIT an existing text file named want_editing.txt that is in your current working directory MAKE an executable named my_program from a C source file named my_program.c that are both in your current working directory. EXECUTE (that is, run) a program named this_is_it that is in your current working directory.

nano want_editing.txt make my_program this_is_it

Are Unix commands part of a C program?

no

YES OR NO: Are literal constants declared?

no

YES OR NO: Can a character string literal constant be more than one line long?

no

YES OR NO: Should homeworks be submitted for a grade?

no

YES OR NO: Should you count on grades being curved to your benefit?

no

YES OR NO: Will you get credit for attending a lab session other than the one for which you are officially registered?

no

WHAT KIND OF STATEMENT outputs to standard output?

printf

WHAT IS THE NAME of each of the following C constructs? printf("Hello, world!\n"); */ /* What is this? */ int main () }

printf statement end of comment, comment delimiter comment main function header end of block, block open

Are the properties of the condition of a while loop the same as, or different from, the properties of the condition of an if block?

same as

When that character comes at the end of a statement, WHAT is it known as?

statement terminator

How is standard output ABBREVIATED in writing?

stdout

GIVE AN EXAMPLE of a character string literal constant.

"Character literal constant one.\n"

The Kelvin temperature scale is very similar to the Celsius temperature scale, except that zero degrees Kelvin is absolute zero, the lowest physically conceivable temperature. Zero degrees Kelvin is -273.16 degrees Celsius. Write a program that prompts for and inputs a temperature in degrees Kelvin, then idiotproofs, then calculates the associated temperature in degrees Celsius, then outputs the temperature in degrees Celsius. You DON'T have to use comments. Otherwise, all rules for Programming Projects (through PP#4) apply.

#include <stdio.h> #include <stdlib.h> int main () { /* main */ int degrees_kelvin; float degrees_celsius; printf("Please enter the temperature in degrees Kelvin \n"); scanf("%f", &degrees_kelvin); if (degrees_kelvin < 0) { printf("Error, temperature input is invalid \n"); } degrees_celsius = (degrees_kelvin - 273.1); printf("The temperature in degrees Celsius is %f", degrees_celsius); } /* main */

CHANGE THE ORDER of the lines below so that the program outputs meaningful output. You MUST use EVERY SINGLE LINE SHOWN BELOW. } /* main */ int main () mass_in_kg = 10.5; printf("Mass: %f kg\n", mass_in_kg); { /* main */ float mass_in_kg; #include <stdio.h> mass_in_kg = 5.75;

#include <stdio.h> int main () { /* main */ Float mass_in_kg; Int mass_in_kg = 5.75; mass_in_kg = 10.5; printf("Mass: %f kg\n", mass_in_kg); } /* main */

WHAT IS THE OUTPUT of each of these programs? Examine the programs CAREFULLY. You do not need to include extraneous blank spaces in your answer. If a program will not compile, mark WON'T COMPILE and EXPLAIN. If a program compiles and runs but does not produce any output, mark NO OUTPUT and EXPLAIN. If a program compiles and runs but produces garbage output, mark GARBAGE and EXPLAIN. If you are giving the results of testing the C program, mark TESTED. #include <stdio.h> int main ( ){ /* main */ int woopdedoo; woopdedoo = 127; printf("%d\n", woopdedoo); } /* main */

127

Suppose that a programming project is worth 250 points and is due by 10:35am Wed Sep 9. If you submit it at 10:35am Fri Sep 11, WHAT IS THE MAXIMUM POSSIBLE SCORE that you can get on it (excluding bonus points, if any)?

200

Based on Moore's Law, and using 2 years as the doubling period, approximately HOW MUCH FASTER will computers be in 2080 than they are today?

2^30

On a Linux PC under the GNU gcc compiler (the compiler being used in this course), HOW MANY BITS are in a float by default? Therefore, HOW MANY DIFFERENT POSSIBLE VALUES could a float variable of the default number of bits exactly represent?

32, 2^31

WHAT OVERALL PERCENTAGE SCORE for the course will you need to be guaranteed each of these letter grades? B C

80 70

WHAT CHARACTER comes at the end of every statement?

;

DESCRIBE THE CONDITION of a while loop. ("The condition is a ...")

A Boolean expression completely enclosed in parenthesis

WHAT IS THE DIFFERENCE between a constant and a variable? NOTE: This question is NOT about how can you tell what a declaration statement declares.

A variable's value can vary while a constant's value remains constant

What are the TWO CATEGORIES OF PENALTIES for an academic misconduct "full violation," as specified on the OU Provost's Academic Integrity webpage?

Admonition Charge

WHAT IS THE OUTPUT of each of these programs? If the program has no output, mark NO OUTPUT and then EXPLAIN WHY. If the program does not compile, mark WON'T COMPILE and then EXPLAIN WHY. If the program outputs garbage, mark GARBAGE and then EXPLAIN WHY. If you are giving the results of testing the C program, mark TESTED. #include <stdio.h> int main () { /* main */ printf("Also cute and fluffy!\n"); } /* main */

Also cute and fluffy!

Suppose that you receive 99.9% credit on all assignments (including exams) except lecture/lab attendance, but 0% on lecture/lab attendance and bonus assignments. WHAT IS THE MAXIMUM LETTER GRADE that you can receive for the course (assuming that grades aren't curved, which probably they won't be)?

B

Suppose that you receive 99.9% credit on all assignments (including exams) except quizzes and bonus assignments but 0% on all quizzes and bonus assignments. WHAT IS THE MAXIMUM LETTER GRADE that you can receive for the course (assuming that grades aren't curved, which probably they won't be)?

B

The word "bit" is a contraction of WHAT PHRASE?

Binary digit

DESCRIBE THE CONDITION of an if block. ("The condition is a ...")

Boolean expression completely enclosed in parenthesis

HOW CAN YOU TELL that a declaration statement declares a named constant?

By using "const" and initializing the named constant

For each of these kinds of statements, mark CAN if it can appear inside a clause of an if block, and mark CANNOTif it cannot appear inside a clause of an if block. EXPLAINeach. A if block A variable declaration A scanf statement

CAN. we can write a if block CANNOT. cant declare in the if block CAN. we can write a scanf answer

For each of these kinds of statements, mark CAN if it can appear in the body of a for loop, and mark CANNOT if it cannot appear in the body of a for loop. EXPLAIN. A named constant declaration A scanf statement A for loop An assignment statement

Cannot- declaration can't be in body of code Can- They can be in any executable statement Can- They can be in any executable statement Can- They can be in any executable statement

For each of these kinds of statements, mark CAN if it can appear in the body of a while loop, and mark CANNOT if it cannot appear in the body of a while loop. EXPLAIN. A variable declaration A scanf statement A while loop An if block

Cannot. All declarations must come before any executable statements Can. They can be in any executable statement Can. They can be in any executable statement Can. They can be in any executable statement

Is C case-sensitive or case-insensitive?

Case-sensitive

What are the FOUR KINDS OF PLAGIARISM ("IT IS PLAGIARISM TO . . . "), as specified on the OU Provost's Academic Integrity webpage (on the Plagiarism tab)?

Copy words and present them as your own writing Copy words even if you give the source, unless you indicate that the copied words are a direct quotation Copy words and then change them a little, even if you give the source Even if you express them in your own words, it is plagiarism to present someone else's idea as your own

WHICH of the above four things does the statement below cause to be set? float y = 22.7;

Data type, value, name, and address

WHAT IS THE NAME of the other section of a program?

Execution section

Suppose that you receive 99.9% credit on all programming projects, but 0% on all other assignments (including exams and bonus assignments). WHAT IS THE MAXIMUM LETTER GRADE that you can receive for the course (assuming that grades aren't curved, which probably they won't be)?

F

A C program has the following declarations: float x = 10.0, y = 5.5, z = 2.1;int i = 3, j = 5, k = 7, m; EVALUATE each of the following expressions. SHOW YOUR WORK, including the type of each subexpression (indicating a float with a decimal point). If the expression would compile and runs but would produce garbage output, mark GARBAGE and EXPLAIN. If you are giving the results of testing the C program, mark TESTED. 324 / m - 12

Garbage, m has garbage value because it's never initialized.

HOW MANY VALUES does a variable have at any given moment in runtime? BE VERY SPECIFIC.

Infinite values

When you write an if-block for idiotproofing, does the exit statement belong before the if-block, inside the if-block or after the if-block? Therefore, should the exit statement be indented less than the if statement, the same as the if statement, or more than the ifstatement?

Inside if-block; more than statement

WHAT are the two categories of storage that computers typically have?

Main memory Cache

WHAT is the section access code for CodeLab this semester?

OKLA-28349-GUPH-46

WHAT IS THE OUTPUT of each of these programs? If the program has no output, mark NO OUTPUT and then EXPLAIN WHY. If the program does not compile, mark WON'T COMPILE and then EXPLAIN WHY. If the program outputs garbage, mark GARBAGE and then EXPLAIN WHY. If you are giving the results of testing the C program, mark TESTED. #include <stdio.h> int main () { /* main */ printf("\n"); } /* main */

Output is a new line

WHAT is standard output?

Output to terminal screen

DEBUG the following program. If you are giving the results of testing the C program, mark TESTED. #include <stdio.h> int main () { /* main */ int input_value1, input_value2;int aggregate = 0; printf("Input two integers:\n"); scanf("%d %d", &input_value1, &input_value2); printf("Before\n"); if (input_value1 < input_value2) ||(input_value1 > input_value2) {printf("First\n"); aggregate = input_value1 + input_value2; } /* if (input_value1 < input_value2) || ... */ printf("After\n"); printf("aggregate = %d\n", aggregate); } /* main */

TESTED #include <stdio.h> int main () { /* main */ int input_value1, input_value2; int aggregate = 0; printf("Input two integers:\n"); scanf("%d %d", &input_value1, &input_value2); printf("Before\n"); if ((input_value1 < input_value2) || (input_value1 > input_value2)) { printf("First\n"); aggregate = input_value1 + input_value2; } /* if (input_value1 < input_value2) || ... */ printf("After\n"); printf("aggregate = %d\n", aggregate); } /* main */ line 10 was missing a "(" after the if and line 11 was missing a ")" before the "{" as highlighted

WHAT IS THE OUTPUT of each of these programs, for each of the following inputs? (You do not need to show the output of the greeting nor the prompt message.) Examine the programs CAREFULLY. If you are giving the results of testing the C program, mark TESTED. #include <stdio.h> int main () { /* main */ const float standard_deduction = 4150.0; const float single_exemption = 2650.0; const float tax_rate = 0.15; const int tax_year = 1997;float income, tax; printf("I'm going to calculate the federal income tax\n"); printf(" on your %d income.\n", tax_year); printf("What was your %d income in dollars?\n",tax_year); scanf("%f", &income); tax = (income - (standard_deduction + single_exemption)) * tax_rate; printf("The %d federal income tax on $%2.2f\n",tax_year, income); printf(" was $%2.2f.\n", tax); } /* main */ (i) 30000 (ii) 40000 (iii) 100000

TESTED (I) the 1997 federal income tax on $30000.00 was $3480.00. (II) e 1997 federal income tax on $40000.00 was $4980.00. (III) the 1997 federal income tax on $100000.00 was $13980.00.

For each of the following programs, WHAT IS THE OUTPUT for each of the given sets of input? Your answer does not need to include the message that prompts the user to input the data, nor the user's input. If you are giving the results of testing the C program, mark TESTED. #include <stdio.h> int main () { /* main */ int input_value1, input_value2; int aggregate = 0; printf("Input two integers:\n"); scanf("%d %d", &input_value1, &input_value2); printf("Before\n");if (input_value1 < input_value2) { printf("First\n"); aggregate = input_value1 + input_value2; } /* if (input_value1 < input_value2) */printf("After\n"); printf("aggregate = %d\n", aggregate); } /* main */ i. 1 2 ii. 2 1 iii. 2 2

TESTED i. 1 2 Before First after Aggregate=3 ii. 2 1 Before After Aggregate=0 iii. 2 2 Before After Aggregate=45

For each of the following programs, WHAT IS THE OUTPUT for each of the given sets of input? Your answer does not need to include the message that prompts the user to input the data, nor the user's input. If you are giving the results of testing the C program, mark TESTED. #include <stdio.h>int main () { /* main */ int input_value1, input_value2; int aggregate = 0; printf("Input two integers:\n"); scanf("%d %d", &input_value1, &input_value2); printf("Before\n"); if (input_value1 < input_value2){ printf("First\n"); aggregate = input_value1 + input_value2; } /* if (input_value1 < input_value2) */ else if (input_value1 > input_value2) { printf("Second\n") aggregate = input_value1 - input_value2; } /* if (input_value1 > input_value2) */ printf("After\n"); printf("aggregate = %d\n", aggregate); } /* main */ i. 1 2 ii. 2 1 iii. 2 2

TESTED i. 1 2 Before First After aggregate=3 ii. 2 1 Before Second After aggregate=1 iii. 2 2 Before After Aggregate=0

Inside a character string literal constant, HOW is a newline indicated? Give the sequence of characters.

\n

If a variable is declared but not initialized, and it has not yet been given a value, then WHAT VALUE does it have?

Undefined or "garbage"

When data and instructions reside in the following kinds of storage, WHEN are they expected to be used? Main memory cache

When they're being used by a program that's currently running. data that has just been used or is about to be used

For each of the following, WRITE A DECLARATION STATEMENT for a named constant representing this quantity. For each, you should choose an appropriate data type and initialization value. The name should comply with the "favorite professor" rule, and should also be a valid C identifier. Assume that int variables and float variables take 4 bytes (32 bits) each. boiling temperature of water in degrees Celsius (at sea level on Earth, in case you're picky)

const int boiling_temp_of_water_in_degrees_celcsius=100;

Convert the following for loop into a while loop. for(count = 1; count <= n; count++) {n_factorial *= count; } /* for count */

count = 1; while (count <= n) { n_factorial *= count; count++; }

HOW OFTEN should you check the course website?

daily

In C, WHICH CHARACTERS can be at the BEGINNING of an IDENTIFIER such as a variable name?

digits

WHAT IS THE DIFFERENCE between dividing an int by an int and dividing a float by a float? BE SPECIFIC AND USE THE CORRECT TERMINOLOGY.

dividing int by int is truncated; dividing float by float is like mathematics

A C program has the following declarations: float x = 28.0, y = 36.0, z = 48.0; int i = 28, j = 40, k = 48; char sky_is_blue = 1; char chair_is_green = 0; char chair_is_brown = 1; WRITE THE RESULT of evaluating each of the following expressions. SHOW ALL INTERMEDIATE STEPS, including the type of each subexpression (indicating a float with a decimal point). If you are giving the results of testing the C program, mark TESTED. x < y && y < z

float 28.0 < float 36.0 && float 36.0 < float 48.0 <1 < float 48.0 1

Convert the following while loop into a for loop. count = initial_value;while (count <= final_value) {printf("count = %d\n", count);count += stride; } /* while (count <= final_value) */

for (count = initial_value; count <= final_value; count += stride) { printf("count = %d\n", count); }

WHAT IS THE OUTPUT of each of these programs? Examine the programs CAREFULLY.If a program won't compile, mark WON'T COMPILE and EXPLAIN. If a program compiles and runs but does not produce any output, mark NO OUTPUT and EXPLAIN. If a program compiles and runs but produces garbage output, mark GARBAGE and EXPLAIN. If you are giving the results of testing the C program, mark TESTED. #include <stdio.h> int main () { /* main */ int a = 5, b = 7, c; a = a + 5; c = a * b; printf("a = %d, b = %d, c = %d\n", a, b, c); } /* main */

tested a=10 b=7 c=70

A C program has the following declarations: float x = 10.0, y = 5.5, z = 2.1;int i = 3, j = 5, k = 7, m; EVALUATE each of the following expressions. SHOW YOUR WORK, including the type of each subexpression (indicating a float with a decimal point). If the expression would compile and runs but would produce garbage output, mark GARBAGE and EXPLAIN. If you are giving the results of testing the C program, mark TESTED. 100 / i - x

tested 100/3-10.0=23.0

A C program has the following declarations: float x = 10.0, y = 5.5, z = 2.1;int i = 3, j = 5, k = 7, m; EVALUATE each of the following expressions. SHOW YOUR WORK, including the type of each subexpression (indicating a float with a decimal point). If the expression would compile and runs but would produce garbage output, mark GARBAGE and EXPLAIN. If you are giving the results of testing the C program, mark TESTED. i % j

tested 3%5=3-(3/5)*5=3-0*6*5=3

A C program has the following declarations: float x = 10.0, y = 5.5, z = 2.1;int i = 3, j = 5, k = 7, m; EVALUATE each of the following expressions. SHOW YOUR WORK, including the type of each subexpression (indicating a float with a decimal point). If the expression would compile and runs but would produce garbage output, mark GARBAGE and EXPLAIN. If you are giving the results of testing the C program, mark TESTED. k + z

tested 7+2.1=9.1

What is the OUTPUT of each of these programs? If you are giving the results of testing the C program, mark TESTED. #include <stdio.h> int main () { /* main */ int count; int sum; sum = 0; count = 1; while (count <= 10) { sum = sum + count; count = count + 1; } /* while (count <= 10) */ printf("sum = %d\n", sum); return 0; } /* main */

tested Sum = 55

WHAT IS THE OUTPUT of each of these programs? Examine the programs CAREFULLY.If a program won't compile, mark WON'T COMPILE and EXPLAIN. If a program compiles and runs but does not produce any output, mark NO OUTPUT and EXPLAIN. If a program compiles and runs but produces garbage output, mark GARBAGE and EXPLAIN. If you are giving the results of testing the C program, mark TESTED. #include <stdio.h> int main () { /* main */ float f = 1.0, g; int a = 5, b = 4, c, d; c = a / b;d = b / a; g = a / (f * b); printf("a = %d, b = %d, c = %d, d = %d\n", a, b, c, d); printf("f = %f, g = %f\n", f, g); } /* main */

tested a=5 b=4 c=1 d=0 f=1.000000 g=1.250000

Consider this program: #include <stdio.h> int main () { /* main */ const int constant1 = 10, constant2 = 20,constant3 = 14; int input_value; char current_truth; printf("What is the input value?\n"); scanf("%d", &input_value); current_truth = input_value > constant1; printf("current_truth = %d\n", current_truth); current_truth =current_truth && (input_value < constant2); printf("current_truth = %d\n", current_truth); current_truth =current_truth && (input_value == constant3); printf("current_truth = %d\n", current_truth); } /* main */ WHAT IS THE OUTPUT of this program for the following input? If you are giving the results of testing the C program, mark TESTED. 8 14 16 20

tested current_truth = 0 current_truth = 0 current_truth = 0 tested current_truth =1 current_truth =1 current_truth =1 tested current_truth =1 current_truth =1 current_truth =0 tested current_truth =1 current_truth =0 current_truth =0

What is the OUTPUT of each of these programs? If you are giving the results of testing the C program, mark TESTED. #include <stdio.h> int main () { /* main */ int count; int product; product = 1; count = 1; while (count <= 16) {product = product * count; count = count + 5; } /* while (count <= 16) */ printf("product = %d\n", product); return 0; } /* main */

tested product = 1056

GIVE AN EXAMPLE of an assignment statement.

x = 5;

YES OR NO: Are you required to take the final exam, even if you already have enough assignment credit to guarantee you the overall letter grade for the course that you want?

yes

YES OR NO: Can a comment be more than one line long?

yes

YES OR NO: Can a statement be more than one line long?

yes

Consider each of these numeric literal constants. COMPUTATIONALLY, does it represent an integer? EXPLAIN. -5281023984 1E+15

yes, fixed ending point no it has an e

Consider each of these values. MATHEMATICALLY, does it represent an integer? EXPLAIN. 344513.000000000000000000000000000 +9/5 344513.000000000000000000000000001

yes, fixed ending point no, no fixed ending point No, non-zero value(s) right of decimal

Some compilers on some computers automatically initialize newly declared variables to default values. UNDER WHAT CIRCUMSTANCES should you explicitly initialize or assign a value to a variable, rather than letting the compiler initialize it to the default value?

you should always assign values to your variables, never assume that the compiler will initialize variable for you

WHICH CHARACTER OR SEQUENCE OF CHARACTERSis the block open delimiter?

{


Related study sets

MBIO 4310 - Final Exam Review Questions

View Set

Muntliga italienska, frågor och svar om Sverige och Italien

View Set

Art Appreciation: Unit 3: Quizzes

View Set

PrepU Adult Health: Practice Exam 1

View Set

Chapter 1: Evolution Of A Science

View Set

Unit 14. Vocab. C. Choose the correct word or phrase.

View Set

1. Property Insurance Terms and Related Concepts

View Set