Lecture-3 - ECE 3090 Software for Engineering Systems Prof...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ECE 3090 Software for Engineering Systems Prof. Hongwei Wu School of Electrical and Computer Engineering Georgia Institute of Technology (Savannah) Today’s topics ¡ Standard Input Object: cin ¡ Mathematical Expressions ¡ More on Data Types ¢ Type Conversion ¢ Overflow and Underflow ¢ Ranks of Data Types ¡ Named constant ¡ Multiple Assignment and Combined Assignment ¡ Formatting Input and Output ¡ File Input and Output ¡ g++, makefile Standard input object: cin ¡ Used to read input from standard input device (usually keyboard) ¡ Stream extraction operator >> ¡ Inputs are stored in variables ¡ #include <iostream> when either cin or cout or both are used. ¡ always use cout to display a message before each cin statement. ¡ cin causes a program to wait until data is typed at the keyboard and the [Enter] key is pressed. ¡ cin automatically converts data to the type that matches the variable. 1. // This program asks the user to enter the length and width of 2. // a rectangle. It calculates the rectangle's area and displays 3. // the value on the screen. 4. #include <iostream> 5. using namespace std; 6. int main() 7. { 8. int length, width, area; 9. 10. cout << "This program calculates the area of a "; 11. cout << "rectangle.\n"; 12. cout << "What is the length of the rectangle? "; 13. cin >> length; 14. cout << "What is the width of the rectangle? "; 15. cin >> width; 16. area = length * width; 17. cout << "The area of the rectangle is " << area << ".\n"; 18. return 0; 19. } ¡ cin deals with stream of data. ¢ Multiple values of the same or different data types. ¢ Use space (which can be one or multiple) to separate numbers, and press [Enter] after the last number is entered. ¢ Order is important: first value entered goes to first variable, etc. 1. // This program asks the user to enter the length and width of 2. // a rectangle. It calculates the rectangle's area and displays 3. // the value on the screen. 4. #include <iostream> 5. using namespace std; 6. int main() 7. { 8. int length, width, area; 9. cout << "This program calculates the area of a "; 10. cout << "rectangle.\n"; 11. cout << "Enter the length and width of the rectangle "; 12. cout << "separated by a space.\n"; 13. cin >> length >> width; 14. area = length * width; 15. cout << "The area of the rectangle is " << area << endl; 16. return 0; 17. } 1. // This program demonstrates how cin can read multiple values 2. // of different data types. 3. #include <iostream> 4. using namespace std; 5. int main() 6. { 7. int whole; 8. double fractional; 9. char letter; 10. cout << "Enter an integer, a double, and a character: "; 11. cin >> whole >> fractional >> letter; 12. cout << "Whole: " << whole << endl; 13. cout << "Fractional: " << fractional << endl; 14. cout << "Letter: " << letter << endl; 15. return 0; 16. } Reading strings with cin ¡ Must first declare an array to hold characters in a string: char myName[21]; ¡ myName is name of array, 21 is the number of characters that can be...
View Full Document

This note was uploaded on 10/24/2009 for the course ECE 3090 taught by Professor Staff during the Fall '08 term at Georgia Tech.

Page1 / 32

Lecture-3 - ECE 3090 Software for Engineering Systems Prof...

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

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