problem you require an algorithm that will receive the length of the hypotenuse and one of the sides...
TRANSCRIPT
![Page 1: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/1.jpg)
ProblemProblem
You require an algorithm that will receive You require an algorithm that will receive the length of the hypotenuse and one of the length of the hypotenuse and one of the sides of a right triangle, and calculate the sides of a right triangle, and calculate the length of the remaining side and the the length of the remaining side and the two acute angles in the triangle. two acute angles in the triangle.
![Page 2: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/2.jpg)
ProblemProblem
You require an algorithm that will You require an algorithm that will receivereceive the the length of the hypotenuselength of the hypotenuse and and one of one of the sidesthe sides of a right triangle, and of a right triangle, and calculatecalculate the the length of the remaining sidelength of the remaining side and the and the two acute anglestwo acute angles in the triangle. in the triangle.
![Page 3: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/3.jpg)
ProblemProblem
side1
side2
hyp
angle1
angle2
![Page 4: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/4.jpg)
Defining DiagramDefining Diagram
InputsInputs ProcessingProcessing OutputOutput
hyphyp
side1side1
PromptPrompt for and for and getget hyp hyp and side1and side1
CalculateCalculate side2 side2 (Pythagorean theorem)(Pythagorean theorem)
CalculateCalculate angle1 and angle1 and angle2angle2
DisplayDisplay results results
side2side2
angle1angle1
angle2angle2
![Page 5: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/5.jpg)
Calculate_Side_and_AnglesCalculate_Side_and_Angles
Prompt user for hyp and side1Prompt user for hyp and side1
Get hyp and side1Get hyp and side1
side2 = hyp*hyp – side1*side1side2 = hyp*hyp – side1*side1
side2 = SQRT(side2)side2 = SQRT(side2)
angle1 = ARCSIN (side2/hyp)angle1 = ARCSIN (side2/hyp)
angle2 = 90 – angle1angle2 = 90 – angle1
Display side2, angle1 and angle2Display side2, angle1 and angle2
ENDEND
![Page 6: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/6.jpg)
Basic Elements of C++Basic Elements of C++
![Page 7: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/7.jpg)
# include <iostream># include <iostream>
using namespace std;using namespace std;
int main()int main()
{ {
cout<<“Hello world!”;cout<<“Hello world!”;
return 0;return 0;
}}
Preprocessor directive
Function main
Semicolons
Curly braces
![Page 8: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/8.jpg)
# include <iostream># include <iostream>
using namespace std;using namespace std;
int main()int main()
{ {
cout<<“Hello world!”;cout<<“Hello world!”;
return 0;return 0;
}}
![Page 9: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/9.jpg)
# include <iostream># include <iostream>
using namespace std;using namespace std;
void main()void main()
{ {
cout<<“Hello world!”;cout<<“Hello world!”;
return;return;
}}
![Page 10: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/10.jpg)
# include <iostream># include <iostream>using namespace std;using namespace std;
int main() int main() { { cout<<“Hello world!”;cout<<“Hello world!”; return 0;return 0;}}
/* This is our first C++ /* This is our first C++ programprogram Oh, how exciting!!!!!Oh, how exciting!!!!!*/*/
//this is our first function//this is our first function
//this is preprocessor //this is preprocessor directivedirective
![Page 11: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/11.jpg)
VariablesVariables
Identifiers can consist ofIdentifiers can consist ofLettersLettersDigits (but cannot start with digits)Digits (but cannot start with digits)Underscore characterUnderscore character
Identifiers are case sensitive.Identifiers are case sensitive.
Identifiers should be self-explanatory.Identifiers should be self-explanatory.
![Page 12: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/12.jpg)
price+taxprice+tax My NumberMy Number costofthepurchasecostofthepurchase _total_sum_total_sum one*twoone*two pay$pay$ xcsrtysbxcsrtysb Average_AgeAverage_Age 3rd_side3rd_side
Valid Identifiers?
![Page 13: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/13.jpg)
C++ Data TypesC++ Data Types
SimpleSimple StructuredStructuredPointersPointers
![Page 14: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/14.jpg)
Basic Data TypesBasic Data Types
Integer - Integer - int int Floating point value – Floating point value – float, doublefloat, doubleCharacter - Character - charcharBoolean - bool - bool
![Page 15: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/15.jpg)
1.1. 3.33.32.2. -4-43.3. 39.00139.0014.4. 005.5. 0.00.06.6. ‘‘d’d’7.7. ‘‘Bob’Bob’8.8. 9.09.09.9. +123+12310.10. ‘ ’‘ ’
![Page 16: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/16.jpg)
Variable DeclarationVariable Declaration
data-type variable-name data-type variable-name , var-name…, var-name…
int num;int num;
float price1, price2;float price1, price2;
double average; double average;
char letter_grade;char letter_grade;
optional
![Page 17: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/17.jpg)
Variable InitializationVariable Initialization
int a=3; int a=3; //initialization//initialization
int a;int a;
a=3;a=3; //assignment//assignment
int a;int a;
cin>>a; cin>>a; //input data//input data
![Page 18: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/18.jpg)
# include <iostream># include <iostream>using namespace std;using namespace std;
int main() int main() { { int age;int age; cout<<“Enter your age”;cout<<“Enter your age”; cin >>age;cin >>age; cout<<endl<<“You are ”<<age;cout<<endl<<“You are ”<<age; return 0;return 0;}}
![Page 19: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/19.jpg)
Calculate_MidpointCalculate_Midpoint
Prompt user for x1, y1, x2, y2Prompt user for x1, y1, x2, y2
Get x1, y1, x2, y2Get x1, y1, x2, y2
xm=(x1+x2)/2xm=(x1+x2)/2
ym=(y1+y2)/2ym=(y1+y2)/2
Display xm and ymDisplay xm and ym
ENDEND
![Page 20: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/20.jpg)
# include <iostream># include <iostream>using namespace std;using namespace std;int main()int main(){{
int x1, y1, x2, y2, xm, ym;int x1, y1, x2, y2, xm, ym;cout<<endl<<“Enter the coordinates of the 1st point”;cout<<endl<<“Enter the coordinates of the 1st point”;cin >>x1 >>y1;cin >>x1 >>y1;cout<<endl<<“Enter the coordinates of the 2nd point”;cout<<endl<<“Enter the coordinates of the 2nd point”;cin>>x2 >>y2;cin>>x2 >>y2;xm=(x1+x2)/2;xm=(x1+x2)/2;ym=(y1+y2)/2;ym=(y1+y2)/2;cout<<endl<<“The midpoint is ”<<xm<<“,”<<ym;cout<<endl<<“The midpoint is ”<<xm<<“,”<<ym;return 0; return 0;
}}
![Page 21: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/21.jpg)
ReviewReview
Declare an integer variable and initialize it to 8Declare an integer variable and initialize it to 8 Give an example of preprocessor directiveGive an example of preprocessor directive What is the name of the function that every C++ What is the name of the function that every C++
program must have?program must have? If A is initialized to 5 and B is initialized to 7 what If A is initialized to 5 and B is initialized to 7 what
are the values of A and B after the following are the values of A and B after the following assignment operation:assignment operation:
B=A;B=A;
A = ________, B = _____________.A = ________, B = _____________.
![Page 22: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/22.jpg)
Review - Review - identify the operationidentify the operation
int num; int num;
num = 5;num = 5;
int num=5; int num=5;
declaration
assignment during declaration initialization
assignment
![Page 23: Problem You require an algorithm that will receive the length of the hypotenuse and one of the sides of a right triangle, and calculate the length of the](https://reader030.vdocuments.net/reader030/viewer/2022032516/56649c765503460f94929d09/html5/thumbnails/23.jpg)
The grade distribution in a certain class is The grade distribution in a certain class is
as follows:as follows:
HW – 30% - 100 points maxHW – 30% - 100 points max Tests – 45% - 100 points maxTests – 45% - 100 points max Labs - 25% - 100 points maxLabs - 25% - 100 points max
Write an algorithm that will receive the Write an algorithm that will receive the scores in each category of one student scores in each category of one student and display his final grade (out of 100%).and display his final grade (out of 100%).