lecture1a - Lecture1:C+ReviewParti. ECE2574...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 1 : C++ Review Part i. ECE 2574 Chao Huang Virginia Tech Spring 2010
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
 C. Huang, Virginia Tech 2 Outline Procedural vs. object-oriented design Variables Pointers Data arrays
Background image of page 2
 C. Huang, Virginia Tech 3 Procedural Programming:  rectangle.cpp #include <iostream> #include <stdlib.h> using namespace std; double rect_perimeter(double length, double width); int main(void) { double length, width, perimeter, area; cout << "Enter the length and width: "; cin >> length >> width; perimeter = rect_perimeter(length, width); area = length * width; continued on next page…
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
 C. Huang, Virginia Tech 4 rectangle.cpp (cont’d)  cout << endl; cout << "LENGTH = " << length << endl; cout << "WIDTH = " << width << endl; cout << "PERIMETER = " << perimeter << endl; cout << "AREA = " << area << endl; return EXIT_SUCCESS; } // Function: rect_perimeter // Parameters: // len - length of a rectangle // wid - width of a rectangle // Value returned: // perimeter of the rectangle double rect_perimeter(double len, double wid) { return (2.0 * len + 2.0 * wid); }
Background image of page 4
 C. Huang, Virginia Tech 5 What does this program do? » It requests the length and width of a rectangle from the user » It reads 2 values in from the standard input » It computes some geometrical properties » Finally, it sends information to the standard output For the sake of brevity & clarity, many comments and error- checking statements have been omitted. rectangle.cpp (cont’d)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
 C. Huang, Virginia Tech 6 Example session Create source + compile + link in Visual Studio Repeat the above steps until you fix all typing mistakes and VS compiler/linker issue no warnings In console window we see: Enter the length and width of the rectangle: 3 4 LENGTH = 3 WIDTH = 4 PERIMETER = 14 AREA = 12
Background image of page 6
 C. Huang, Virginia Tech 7 But wait! Program  rectangle.cpp is a procedure-oriented example  In this course, we want to emphasize object-oriented design  Let's look at an object-oriented approach to accomplish the  same thing. ..
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
 C. Huang, Virginia Tech 8 rectangle2.cpp #include <iostream> #include <stdlib.h> using namespace std; // Class definitions class RectangleClass
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/28/2010 for the course ECE 2574 taught by Professor Chuang during the Spring '08 term at Virginia Tech.

Page1 / 25

lecture1a - Lecture1:C+ReviewParti. ECE2574...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online