You are on page 1of 3

Programming Applications for Engineers

CS 159 (Spring - 2022)


Lab 2 – Part 2- (3%)
Instructor: Dr. Alper Alan
Individual submission: Upload a clear version of your answers to Moodle.

Student name:……………….. Student ID:……………………

1. Name the .c file with your ID_your name. Mention your name, your section, your ID
as comments on top of the code.
2. Strictly, the submission file type should be .c file.
3. Assessment submission deadline is 7/4/2022 @23:59. A delay in assessment
submission will result in the following grade deduction
· Delay of 1 Day : 40% Deduction
· Delay of 2 Days: 60% Deduction
· Delay of 3 Days: 100% Deduction
4. In case of plagiarized submission, student will receive a notification email with the
below penalty applied starting the date of the email:
· Resubmission on the first day (within 24 hours after notification): 40% deduction
· Resubmission on the second day after notification: 60% deduction.
· Failing to resubmit within two days after notification, the assessment will be
graded with zero.
5. Please check Banner for your Gradebook and Attendance.
6. AUM rules and regulations apply.
Problem
Write a C program that implements the following parts. The program should run successfully
with different scenarios. In the program, constant statements and global variables cannot be
used. You should write code based on the covered material; It is not allowed to include
statements that are not covered in the lab until the end of week 6. The program should
perform the following:

A. Define a string variable A_YourName (example: A_Ahmed) of size equal to the sum of digits
of your AUM ID. Note that the name of the string variable should include your name. For
example, if your AUM ID number is 42357 and your name is “Ahmed”, the size of the variable
A_Ahmed is 21 (4+2+3+5+7 = 21). Expressions are not allowed to be used to calculate size.
Initialize the string with your name. Print the following on the screen: Lab 2 followed by the
value of string A_YourName, your AUM ID number and your section number. For example,
if your section number = F2 and ID = 42357, the program should print: (5 points)
Lab 2 is created by student xxx yyy - ID = 42357- section F2

B. Define two integers A_YourAUMID and B_YourAUMID (example: A_42357), and initializes
them with the first and second digits of your AUM ID, respectively. If your ID is 42357, the
value of the variable A_42357 will be 4 and the value of variable B_42357will be 2. (5 points)

C. Define an integer variable C_YourName (example: C_Ahmed) and initialize it with the largest
of the two numbers A_YourAUMID and B_YourAUMID using switch statement. Note that
the name of the string variable should include your name. For example, if your ID is 42357
and your name is “Ahmed”, the value of A_42357 is 4 and the value of B_42357 is 2, the
value of C_ Ahmed will be 4. Using other variables, if and if else statements are not allowed
in this part. (15 points)

D. Prompt the user to enter the price of C_YourName items. For example, if the value of
C_YourName is 4, then you have to prompt the user to enter price of 4 items. The program
should print the price of each item after discount as shown in the sample output. Then, it
prints the total price after discount of all items which got a discount of 20%. Using else is
not allowed in this part. (20 points)
Item Discount
Price < 1000 10%
1000 <= Price <=2000 20%
Price > 2000 15%

You should use the loop type based on the following table:
Student AUM ID Loop type
Less than 50000 for
Between 50000 and 60000 do while
above 60000 while

Page 2 of 3
E. Define an integer variable E_YourName (example: E_Ahmed), and initialize it with the
highest digit of your AUM. Using the correct loop type, print output as per the following
rules:

Value of E_YourName Loop type Output


Less than 7 for Student ID, first name, last name, section should be printed
x times each on separate line. x is equal to E_YourName -1.
7 or 9 while Student first name, last name, major, ID should be printed x
times each on separate line. x is equal to E_YourName - 2.
8 do while Student ID, first name, section, major should be printed x
times each on separate line. x is equal to E_YourName - 3.
For example, if your AUM ID is 42357, then the value of E_YourName is 7, so you should use
while loop to print the output. (10 points)

G. The program should adhere the following requirements:


 It is not allowed to store your AUM ID in a variable.
 The name of the .C file is equal to your ID and your first name “ID_NAME.c”. For
example, "42357_Ahmed.c". (3 points)
 Write your first name, your last name, the course code CS159, your section number
and your ID as comments at the top of the code as shown below: (2 points).
If your name is xxx yyy, your ID is 42357and your section is F2, comments should
be:
/* This program is created by: xxx yyy ID = 42357 Section F2 CS159 */
Sample output: (If your name = xxx yyy, section number = F2 and ID = 42357)

Page 3 of 3

You might also like