CSC 242 ACST Introduction to Programming Concepts Worksheet

CSC242 Introduction to Programming ConceptsWeek Two Midterm Exam
First Name
Last Name
ID#
Email Address
Table of Contents
How to submit………………………………………………………………………………………………………………… 1
P1 (35 Points) – Compute the Perimeter of a Triangle …………………………………………………………. 2
P2 (30 Points) – Solve Linear Equations……………………………………………………………………………… 2
P3 (20 Points) – Finding the sum of the digits …………………………………………………………………….. 3
P4 (15 Points) – Print Shape……………………………………………………………………………………………… 3
How to submit
After filling all the parts in this file, please follow the following steps.
1) Add your name and Student ID# to the first page.
2) Save the file in the original format (Docx or Doc)
(please do not convert to other file formats e.g. PDF, ZIP, RAR, …).
3) Rename the file as
YOUR First Name-YOUR Last Name- ID-Midterm.docx
Example:
John – Smith – 234566435 – Midterm.docx
4) Upload the file and submit it (only using Blackboard)
P1 (35 Points) – Compute the Perimeter of a Triangle
Write a program that reads three edges for a triangle (edge1, edge2, edge3) and computes the
perimeter (perimeter = edge1+edge2+edge3) if the input is valid. Otherwise, display that the input is
invalid. The input is valid if the sum of every pair of two edges is greater than the remaining edge
(edge1+edge2>edge3 and edge1+edge3>edge2 and edge3+edge2>edge1).
Your C++ code for this HW
— Copy and paste your code here
Run the code for the following two inputs and show the results:
Input 1: edge1 = 3, edge2 = 4, edge3 = 5
Input 2: edge1 = 3, edge2 = 9, edge3 = 5
The program run result
Copy and paste the result here (e.g. the screen shot of the result you get by running the code).
P2 (30 Points) – Solve Linear Equations
You can use Cramer’s rule to solve the following 2*2 system of linear equation:
Write a program that prompts the user to enter a, b, c, d, e, and f, and displays the result. If (ad – bc) is
0, report that “The equation has no solution.”
Here is a sample run.
Enter a, b, c, d, e, f: 9.0 4.0 3.0 -5.0 -6.0 -21.0
x is -2.0 and y is 3.0
Enter a, b, c, d, e, f: 1.0 2.0 2.0 4.0 4.0 5.0
The equation has no solution
Your C++ code for problem
— Copy and paste your code here
Run the code a
following box.
= 1, b = 1 , c = 2 , d = 4, e = 4 and f = 12 and put the result in the
The program run result
Copy and paste the result here (e.g. the screen shot of the result you get by running the code).
P3 (20 Points) – Finding the sum of the digits
Write a program that gets a single 10-digit number and find the sum of all the digits.
Here is a sample run:
Please enter a 10-digit number: 1234567890
The sum of the digits 1+2+3+4+5+6+7+8+9+0 = 45
Note: You should get a single 10-ditit number, not 10 separate inputs from the user.
Important: Do not use strings, arrays or any concept that is not covered in the first 3 chapters of the
book.
Hint: This problem can easily be solved by using series of integer division (/) and remainder (%).
Your C++ code for problem
— Copy and paste your code here
Run the program for the 10-digit input 0133252816 and copy and paste the result in the following
box.
The program run result
Copy and paste the result here (e.g. the screen shot of the result you get by running the code).
P4 (15 Points) – Print Shape
Write a program that gets integer n from the user and prints the character “*” as the following pattern.
For example, for n = 5, we have a 5*5 square in the middle and then for 5 rows and columns no
character is printed and then then boundary is created using the 5 asterisks.
Write a program that gets the odd number input from the user and prints the pattern above. Test your
program with n = 3 and 5.
Your C++ code for problem
— Copy and paste your code here
Run the code for two cases with n
= 3 and n = 5. Insert the result in the following box.
The program run result
Copy and paste the result here (e.g. the screen shot of the result you get by running the code).

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper
Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER