CSC242 Introduction to Programming Concepts - Midterm
First Name Marcus
Last Name Moody
Student ID# 041410203
Email Address mrmoodymarcus@gmail.com
Table of Contents
TOC \o "1-3" \h \z \u Ho ...
CSC242 Introduction to Programming Concepts - Midterm
First Name Marcus
Last Name Moody
Student ID# 041410203
Email Address mrmoodymarcus@gmail.com
Table of Contents
TOC \o "1-3" \h \z \u How to submit PAGEREF _Toc38074328 \h 1P1 (35 Points) – Compute the Perimeter of a Triangle PAGEREF _Toc38074329 \h 2P2 (30 Points) – Solve Linear Equations PAGEREF _Toc38074330 \h 2P3 (20 Points) – Finding the sum of the digits PAGEREF _Toc38074331 \h 3P4 (15 Points) – Print Shape PAGEREF _Toc38074332 \h 3
How to submitAfter filling all the parts in this file, please follow the following steps.
Add your name and Student ID# to the first page.
Save the file in the original format (Docx or Doc)
(please do not convert to other file formats e.g. PDF, ZIP, RAR, …).
Rename the file as
YOUR First Name-YOUR Last Name- ID-Midterm.docx
Example:
John - Smith - 234566435 - Midterm.docx
Upload the file and submit it (only using Blackboard)
P1 (35 Points) – Compute the Perimeter of a TriangleWrite 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
--
#include<iostream>
#include<cmath>
#include <iomanip>
using namespace std;
int main()
{
double edge1, edge2, edge3, perimiter;
cout << "Enter the value of edge 1: ";
cin >> edge1;
cout << "Enter the value of edge 2: ";
cin >> edge2;
cout << "Enter the value of edge 3: ";
cin >> edge3;
if ((edge1 + edge2) > edge3 && (edge1 + edge3) > edge2 && (edge3 + edge2)
> edge1)
{
perimiter = edge1 + edge2 + edge3;
cout << "
Perimeter of the triangle is : " << perimiter << endl;
}
else
{
cout << "
The input is invalid." << endl;
}
return 1;
}
//PART TWO
#include<iostream>
#include<cmath>
#include <iomanip>
using namespace std;
int main()
{
double edge1, edge2, edge3, perimiter;
cout << "Enter the value of edge 1: ";
cin >> edge1;
cout << "Enter the value of edge 2: ";
cin >> edge2;
cout << "Enter the value of edge 3: ";
cin >> edge3;
if ((edge1 + edge2) > edge3 && (edge1 + edge3) > edge2 && (edge3 + edge2)
> edge1)
{
perimiter = edge1 + edge2 + edge3;
cout << "
Perimeter of the triangle is : " << perimiter << endl;
}
else
{
cout << "
The input is invalid." << endl;
}
return 1;
}
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
Part One
Enter the value of edge 1: 3
Enter the val
Document Details
| Word Count: | 2473 |
| Page Count: | 11 |
| Level: | AS and A Level |
| Subject: | Other |