Presentation is loading. Please wait.

Presentation is loading. Please wait.

Subject: Programming in C++ 1. LEARNING OUTCOME  At the end of this slide, student able to:  Know the brief history of C++.  Explore Microsoft Visual.

Similar presentations


Presentation on theme: "Subject: Programming in C++ 1. LEARNING OUTCOME  At the end of this slide, student able to:  Know the brief history of C++.  Explore Microsoft Visual."— Presentation transcript:

1 Subject: Programming in C++ 1

2 LEARNING OUTCOME  At the end of this slide, student able to:  Know the brief history of C++.  Explore Microsoft Visual C++  Create applications using Variables, Data Types and Arithmetic expressions. 2

3 History & fundemental of C++ 3 C, C++, Java, and C# are very similar. C++ evolved from C. Java was modeled after C++. C# is a subset of C++ with some features similar to Java. If you know one of these languages, it is easy to learn the others. C evolved from the B language and the B language evolved from the BCPL language. BCPL was developed by Martin Richards in the mid-1960s for writing operating systems and compilers. C++ is an extension of C, developed by Bjarne Stroustrup at Bell Labs during 1983-1985. C++ added a number of features that improved the C language. An international standard for C++ was created by American National Standards Institute (ANSI) in 1998.

4 Microsoft Visual C++ 4

5 Example 1 5 Let us begin with a simple C++ program that displays the message “Welcome to C++!” on the console. #include using namespace std; int main() { // Display Welcome to C++ to the console cout << "Welcome to C++!" << endl; System(“pause”); // this is needed within visual studio return 0; } STAR T Step1: Display show: “Welcome to C++ FINIS H

6 Example 2 6 #include using namespace std; int main() { cout << "Programming is fun!" << endl; cout << "Fundamentals First"; // what happens when no “endl”? cout << "Problem Driven" << endl; System(“pause”); return 0; } STAR T Step 4: Display show: “Problem Driven” Step 2: Display show: “Fundamental First” Step1: Display show: “Programming is fun!” FINIS H

7 Example 3 7 #include using namespace std; int main() { string name, age; cout << “Type your name" << endl; cin>> name>>; cout<< “Type your age” << endl; cin>>age>>; cout << “My name is”<<name<<endl; cout << “My age is”<<age<<endl; System(“pause”); return 0; } STAR T Display show: “My age is” Step 2: Computer ask to key in your name Step1: Display show: “Type your name” Step 3: Display show: “My name is” FINIS H

8 Example 4 8 #include using namespace std; int main() { int first, second; cout << “Welcome to math " << endl; cout<< “Type for first number” << endl; cin>>first>>; cout << “Type for second number”<<second<<endl; cin>> second>>; cout << “The total is”<<first + second <<endl; System(“pause”); return 0; } STAR T Step 4: Display show: “The total is” Step 2: Computer ask to key in first number Step1: Display show: “Welcome to math” & “Type for first number” Step 3: Display show: “Type for second number” FINIS H

9 Trace a Program Execution #include using namespace std; int main() { double radius; double area; // Step 1: Read in radius radius = 20; // Step 2: Compute area area = radius * radius * 3.14159; // Step 3: Display the area cout << "The area is "; cout << area << endl; } 9 no value radius allocate memory for radius animation

10 Trace a Program Execution 10 no value radius memory animation #include using namespace std; int main() { double radius; double area; // Step 1: Read in radius radius = 20; // Step 2: Compute area area = radius * radius * 3.14159; // Step 3: Display the area cout << "The area is "; cout << area << std::endl; } no value area allocate memory for area

11 Trace a Program Execution 11 20 radius no value area assign 20 to radius animation #include using namespace std; int main() { double radius; double area; // Step 1: Read in radius radius = 20; // Step 2: Compute area area = radius * radius * 3.14159; // Step 3: Display the area cout << "The area is "; cout << area << std::endl; } Note: “=“ is not “equals” but an “assignment” i.e., “take the value of the expression on the right and stick it in the memory location on the left.” Think <=

12 Trace a Program Execution 12 20 radius memory 1256.636 area compute area and assign it to variable area animation #include using namespace std; int main() { double radius; double area; // Step 1: Read in radius radius = 20; // Step 2: Compute area area = radius * radius * 3.14159; // Step 3: Display the area cout << "The area is "; cout << area << std::endl; }

13 Trace a Program Execution 13 20 radius memory 1256.636 area print a message to the console animation #include using namespace std; int main() { double radius; double area; // Step 1: Read in radius radius = 20; // Step 2: Compute area area = radius * radius * 3.14159; // Step 3: Display the area cout << "The area is "; cout << area << std::endl; }

14 EXERCISE IN CLASS By given flowchat, create a C++ programming that can calculate BMI (Body Mass Index), (BMI=weight/height) START Step 4: Computer ask to key in your birth year Step 2: Computer ask to key in your name Step1: Display show: “What is your name?” Step 3: Display show: “what is your birth year?” FINISH Step 5: Display show: “what is your weight?” Step 6: Computer ask to key in your weight Step 7: Display show: “what is your height?” Step 8: Computer ask to key in your height Step 9: Display show: “the BMI of is and age is


Download ppt "Subject: Programming in C++ 1. LEARNING OUTCOME  At the end of this slide, student able to:  Know the brief history of C++.  Explore Microsoft Visual."

Similar presentations


Ads by Google