230 likes | 390 Views
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 remaining side and the two acute angles in the triangle. Problem.
E N D
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 remaining side and the two acute angles in the triangle.
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 remaining side and the two acute angles in the triangle.
Problem angle1 hyp side1 angle2 side2
Calculate_Side_and_Angles Prompt user for hyp and side1 Get hyp and side1 side2 = hyp*hyp – side1*side1 side2 = SQRT(side2) angle1 = ARCSIN (side2/hyp) angle2 = 90 – angle1 Display side2, angle1 and angle2 END
Preprocessor directive # include <iostream> using namespace std; int main() { cout<<“Hello world!”; return 0; } Function main Curly braces Semicolons
# include <iostream> using namespace std; int main() { cout<<“Hello world!”; return 0; }
# include <iostream> using namespace std; void main() { cout<<“Hello world!”; return; }
/* This is our first C++ program Oh, how exciting!!!!! */ # include <iostream> using namespace std; int main() { cout<<“Hello world!”; return 0; } //this is preprocessor directive //this is our first function
Variables • Identifiers can consist of • Letters • Digits (but cannot start with digits) • Underscore character Identifiers are case sensitive. Identifiers should be self-explanatory.
price+tax • My Number • costofthepurchase • _total_sum • one*two • pay$ • xcsrtysb • Average_Age • 3rd_side Valid Identifiers?
C++ Data Types • Simple • Structured • Pointers
Basic Data Types • Integer - int • Floating point value – float, double • Character - char • Boolean - bool
3.3 • -4 • 39.001 • 0 • 0.0 • ‘d’ • ‘Bob’ • 9.0 • +123 • ‘ ’
Variable Declaration data-type variable-name , var-name… int num; float price1, price2; double average; char letter_grade; optional
Variable Initialization • int a=3; //initialization • int a; a=3; //assignment • int a; cin>>a; //input data
# include <iostream> using namespace std; int main() { int age; cout<<“Enter your age”; cin >>age; cout<<endl<<“You are ”<<age; return 0; }
Calculate_Midpoint Prompt user for x1, y1, x2, y2 Get x1, y1, x2, y2 xm=(x1+x2)/2 ym=(y1+y2)/2 Display xm and ym END
# include <iostream> using namespace std; int main() { int x1, y1, x2, y2, xm, ym; cout<<endl<<“Enter the coordinates of the 1st point”; cin >>x1 >>y1; cout<<endl<<“Enter the coordinates of the 2nd point”; cin>>x2 >>y2; xm=(x1+x2)/2; ym=(y1+y2)/2; cout<<endl<<“The midpoint is ”<<xm<<“,”<<ym; return 0; }
Review • Declare an integer variable and initialize it to 8 • Give an example of preprocessor directive • What is the name of the function that every C++ program must have? • If A is initialized to 5 and B is initialized to 7 what are the values of A and B after the following assignment operation: B=A; A = ________, B = _____________.
Review - identify the operation • int num; • num = 5; • int num=5; declaration assignment assignment during declaration initialization
The grade distribution in a certain class is as follows: • HW – 30% - 100 points max • Tests – 45% - 100 points max • Labs - 25% - 100 points max Write an algorithm that will receive the scores in each category of one student and display his final grade (out of 100%).