problem you require an algorithm that will receive the length of the hypotenuse and one of the sides...
TRANSCRIPT
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.
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.
ProblemProblem
side1
side2
hyp
angle1
angle2
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
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
Basic Elements of C++Basic Elements of C++
# 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
# include <iostream># include <iostream>
using namespace std;using namespace std;
int main()int main()
{ {
cout<<“Hello world!”;cout<<“Hello world!”;
return 0;return 0;
}}
# include <iostream># include <iostream>
using namespace std;using namespace std;
void main()void main()
{ {
cout<<“Hello world!”;cout<<“Hello world!”;
return;return;
}}
# 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
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.
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?
C++ Data TypesC++ Data Types
SimpleSimple StructuredStructuredPointersPointers
Basic Data TypesBasic Data Types
Integer - Integer - int int Floating point value – Floating point value – float, doublefloat, doubleCharacter - Character - charcharBoolean - bool - bool
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. ‘ ’‘ ’
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
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
# 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;}}
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
# 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;
}}
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 = _____________.
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
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%).