0% found this document useful (0 votes)
92 views

Assignment 1 Questions LAB

This document provides instructions for Assignment 1 of the Computer Programming I course. It consists of two parts: Part 1 involves answering multiple choice and coding questions, while Part 2 involves coding programs based on provided prompts. Students must submit their solutions for each part separately in PDF format by the due date of October 24, 2021. The document then provides the specific questions and prompts for each part.

Uploaded by

Chaitya Vora
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

Assignment 1 Questions LAB

This document provides instructions for Assignment 1 of the Computer Programming I course. It consists of two parts: Part 1 involves answering multiple choice and coding questions, while Part 2 involves coding programs based on provided prompts. Students must submit their solutions for each part separately in PDF format by the due date of October 24, 2021. The document then provides the specific questions and prompts for each part.

Uploaded by

Chaitya Vora
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Computer Programming, I – Fall 2021

Assignment 1

Individual/independent
Due Date: OCT 24, 2021
Assignment 1: 15 points of total mark

Assignment 1 consist of two sections:


PART1: Answering questions [40%]
PART2: Coding (Lab) [60%]

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.

How submit your solution for assignment 1:


PART1:
• For the first part submit solution as a single PDF file and upload it on
mycourselink.
• Solutions can be typed or take pictures (scan) of if done by hand and
upload them with the following name pattern.
• Name_FamilyName_StudentID_LAB1_PART1.pdf

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

2. Discuss the meaning of each of the following names: (5 Points)


a. stdin
b. stdout
c. stderr

3. Identify and correct the errors in each of the following statements. (Note: There
may be more than one error per statement.): (10 Points)

a. scanf( "d", value) ;

b. printf( "The product of %d and %d is %d"\n, x, y) ;

c. firstNumber + secondNumber = sumOfNumbers

d. if ( number => largest)


largest == number;

e. */ Program to determine the largest of three integers /*

f. Scanf( "%d", anInteger) ;

g. printf( "Remainder of %d divided by %d is\n", x, y, x % y) ;

h. if ( x = y) ;
printf( %d is equal to %d\n", x, y) ;

i. print( "The sum is %d\n," x + y) ;

j. Printf( "The value you entered is: %d\n, &value) ;

2
Computer Programming, I – Fall 2021

4. What, if anything, prints when each of the following statements is performed? If


nothing prints, then answer “Nothing.” Assume x =2 and y=3. (10 Points)

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)

a. scanf( "%d%d%d%d%d", &b, &c, &d, &e, &f) ;


b. p = i + j + k + 7;
c. printf( "Values are replaced") ;
d. printf( "a = 5");

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

7. What does the following code print? (5 Points)

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)

a. if ( age >= 65) ;


puts( "Age is greater than or equal to 65") ;
else
puts( "Age is less than 65") ;

b. int x = 1, total;

while ( x <= 10) {


total += x;
++x;
}

c. While ( x <= 100)


total += x;
++x;

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

Assignment 1 – PART2 (LAB)

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:

Enter account number (-1 to end): 100


Enter beginning balance: 5394.78
Enter total charges: 1000.00
Enter total credits: 500.00
Enter credit limit: 5500.00
Account: 100
Credit limit: 5500.00
Balance: 5894.78
Credit Limit Exceeded.
Enter account number (-1 to end): 200
Enter beginning balance: 1000.00
Enter total charges: 123.45
Enter total credits: 321.00
Enter credit limit: 1500.00

Enter account number (-1 to end): 300


Enter beginning balance: 500.00
Enter total charges: 274.73
Enter total credits: 100.00
Enter credit limit: 800.00
Enter account number (-1 to end): -1
7. Drivers are concerned with the mileage obtained by their automobiles. One driver
has kept track of several tankfuls of gasoline by recording miles driven and gallons
used for each tankful. Develop a program that will input the miles driven and
gallons used for each tankful. The program should calculate and display the miles
per gallon obtained for each tankful. After processing all input information, the
program should calculate and print the combined miles per gallon obtained for all
tankfuls. Here is a sample input/output dialog: (25 Points)

Enter the gallons used (-1 to end): 12.8


Enter the miles driven: 287
The miles/gallon for this tank was 22.421875
Enter the gallons used (-1 to end): 10.3
Enter the miles driven: 200
The miles/gallon for this tank was 19.417475
Enter the gallons used (-1 to end): 5
6
Computer Programming, I – Fall 2021

Enter the miles driven: 120


The miles/gallon for this tank was 24.000000
Enter the gallons used (-1 to end): -1
The overall average miles/gallon was 21.601423

You might also like