Assignment 1 Questions LAB
Assignment 1 Questions LAB
Assignment 1
Individual/independent
Due Date: OCT 24, 2021
Assignment 1: 15 points of total mark
For the coding section, you may work with TAs during lab sessions. Please
consider that TAs will assist with any problems and errors; TA will not be
assistant on answering the solutions.
PART2:
• Take screenshots of the output (source code is not necessary) of each
program and submit it as a single file with the following name pattern.
Name_FamilyName_StudentID_LAB1_PART2.pdf
• Upload the source code of each program with a following pattern:
Name_FamilyName_StudentID_LAB1_PROGRAMX.c
Ex: AMIN_SAFAEI_123456_LAB1_PROGRAM1.c
1
Computer Programming, I – Fall 2021
Assignment 1 - PART1
1. Categorize each of the following items as either hardware or software: (5 Points)
a. CPU
b. C++ compiler
c. ALU
d. C++ preprocessor
e. input unit
f. an editor programs
3. Identify and correct the errors in each of the following statements. (Note: There
may be more than one error per statement.): (10 Points)
h. if ( x = y) ;
printf( %d is equal to %d\n", x, y) ;
2
Computer Programming, I – Fall 2021
a. printf( "%d", x) ;
b. printf( "%d", x + x) ;
c. printf( "x=") ;
d. printf( "x=%d", x) ;
e. printf( "%d = %d", x + y, y + x) ;
f. z = x + y;
g. scanf( "%d%d", &x, &y) ;
h. // printf( "x + y = %d", x + y) ;
5. Which, if any, of the following C statements contain variables whose values are
replaced? (10 Points)
6. Write a program that prints the numbers 1 to 4 on the same line. Write the
program using the following methods. (15 Points)
a. Using one printf statement with no conversion specifiers.
b. Using one printf statement with four conversion specifiers.
c. Using four printf statements
printf( "*\n**\n***\n****\n*****\n") ;
8. Write a single pseudocode statement that indicates each of the following (15
Points):
a. Display the message "Enter two numbers".
b. Assign the sum of variables x, y, and z to variable p.
c. The following condition is to be tested in an if…else selection statement:
The current value of variable m is greater than twice the current value of
variable v.
d. Obtain values for variables s, r, and t from the keyboard.
3
Computer Programming, I – Fall 2021
9. Identify and correct the errors in each of the following. [Note: There may be more
than one error in each piece of code.] (10 Points)
b. int x = 1, total;
d. while ( y > 0) {
printf( "%d\n", y) ;
++y;
}
10. Formulate a pseudocode algorithm for each of the following: (15 points)
a. Obtain two numbers from the keyboard, compute their sum and display
the result.
b. Obtain two numbers from the keyboard, and determine and display which
(if either) is the larger of the two numbers.
c. Obtain a series of positive numbers from the keyboard, and determine and
display their sum. Assume that the user types the sentinel value -1 to
indicate “end of data entry.”
4
Computer Programming, I – Fall 2021
1. Write a program that asks the user to enter two numbers, obtains them from the
user and prints their sum, product, difference, quotient and remainder (10
Points).
2. Write a program that asks the user to enter two integers, obtains the numbers from
the user, then prints the larger number followed by the words “is larger.” If the
numbers are equal, print the message “These numbers are equal.” (10 Points)
3. Write a program that reads in the radius of a circle and prints the circle’s diameter,
circumference and area. Use the constant value 3.14159 for Π. Perform each of
these calculations inside the printf statement(s) and use the conversion specifier
%f. (15 Points)
4. Write a program that reads in two integers and determines and prints whether the
first is a multiple of the second. [Hint: Use the remainder operator.] (15 Points)
5. Write a program that prints the following shapes with asterisks. (10 Points)
********* *** * *
* * * * *** * *
* * * * ***** * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
********* *** * *
6. Develop a C program that will determine whether a department store customer has
exceeded the credit limit on a charge account. For each customer, the following
facts are available: (25 Points)
a. Account number
b. Balance at the beginning of the month
c. Total of all items charged by this customer this month
d. Total of all credits applied to this customer's account this month
e. Allowed credit limit
5
Computer Programming, I – Fall 2021
The program should input each fact, calculate the new balance (= beginning
balance + charges – credits) , and determine whether the new balance exceeds the
customer's credit limit. For those customers whose credit limit is exceeded, the
program should display the customer's account number, credit limit, new balance
and the message “Credit limit exceeded.” Here is a sample input/output dialog: