1 / 23

Problem

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.

ankti
Download Presentation

Problem

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 remaining side and the two acute angles in the triangle.

  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 remaining side and the two acute angles in the triangle.

  3. Problem angle1 hyp side1 angle2 side2

  4. Defining Diagram

  5. 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

  6. Basic Elements of C++

  7. Preprocessor directive # include <iostream> using namespace std; int main() { cout<<“Hello world!”; return 0; } Function main Curly braces Semicolons

  8. # include <iostream> using namespace std; int main() { cout<<“Hello world!”; return 0; }

  9. # include <iostream> using namespace std; void main() { cout<<“Hello world!”; return; }

  10. /* 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

  11. Variables • Identifiers can consist of • Letters • Digits (but cannot start with digits) • Underscore character Identifiers are case sensitive. Identifiers should be self-explanatory.

  12. price+tax • My Number • costofthepurchase • _total_sum • one*two • pay$ • xcsrtysb • Average_Age • 3rd_side Valid Identifiers?

  13. C++ Data Types • Simple • Structured • Pointers

  14. Basic Data Types • Integer - int • Floating point value – float, double • Character - char • Boolean - bool

  15. 3.3 • -4 • 39.001 • 0 • 0.0 • ‘d’ • ‘Bob’ • 9.0 • +123 • ‘ ’

  16. Variable Declaration data-type variable-name , var-name… int num; float price1, price2; double average; char letter_grade; optional

  17. Variable Initialization • int a=3; //initialization • int a; a=3; //assignment • int a; cin>>a; //input data

  18. # include <iostream> using namespace std; int main() { int age; cout<<“Enter your age”; cin >>age; cout<<endl<<“You are ”<<age; return 0; }

  19. 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

  20. # 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; }

  21. 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 = _____________.

  22. Review - identify the operation • int num; • num = 5; • int num=5; declaration assignment assignment during declaration  initialization

  23. 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%).

More Related