DOC PREVIEW
UVa-Wise COSC 181 - Foundations of Computer Programming

This preview shows page 1-2-3-4-5 out of 14 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

COSC 181 Foundations of Computer Programming Class 3 Last Time Basic C Programs Output Input escape sequences Basic main function std cout and std cin and comments Taking input from keyboard and adding integers system PAUSE Today s Goals Finish from Friday More basic vocabulary Variables and Computer Memory Practice with arithmetic operators Practice with relational operators arithmetic precedence overall operator precedence Introduction to Software Engineering process What does this program do then Text printing program 2 include iostream allows program to output data to the screen function main begins program execution int main std cout Welcome std cout to C n OUTPUT Welcome to C system PAUSE prepackaged wait function return 0 indicate that program ended successfully end function main What about this program Text printing program 3 include iostream allows program to output data to the screen function main begins program execution int main std cout Wel ncome nto n nC n n system PAUSE prepackaged wait function return 0 indicate that program ended successfully OUTPUT Wel come to C end function main Getting input from the keyboard std cin Standard character input stream Input in C occurs over streams as well The standard stream above is connected to the keyboard by default namespace command as opposed to Operator Stream extraction operator Variable Declarations Variables are used to store certain data The input data for our next program will be stored in variables Must first be declared int number1 type variable name int number2 int sum Then they can be initialized sum number1 number2 std cin number1 Using Input Addition Output include iostream allows program to perform input and output function main begins program execution int main variable declarations int number1 first integer to add int number2 second integer to add int sum sum of number1 and number2 std cout Enter first integer prompt user for data std cin number1 read first integer from user into number1 std cout Enter second integer prompt user for data std cin number2 read second integer from user into number2 sum number1 number2 add the numbers store result in sum std cout Sum is sum std endl display sum end line system PAUSE return 0 indicate that program ended successfully end function main Now Try it Yourself Open up DevC Type in the Code Under the Execute menu First hit Compile Wait for the screen to say Done 0 errors 0 warnings Then hit Run Vocabulary fundamental primitive types int char double identifier a k a variable Identifiers can be anything so long as they aren t keywords and don t begin with a digit int return int pq34 34 int 1number Only this one is allowable Make sure your variable names make sense C is case sensitive char myVariable is different from char myvariable Memory Concepts Every variable is linked to a spot in memory Each variable has a name size type and value Writing to a memory location setting a variable is destructive Reading from a memory location outputting a variable is nondestructive Look at Figs 2 6 2 7 and 2 8 in your book Equality and Relational Operators Fig 2 12 gives a list of these operators binary operators not to be confused with assignment operator Each gives a value of either true or false 1 or 0 Each is evaluated from left to right bool answer 343 43 bool answer 23 3 Code from Fig 2 13 A few new tricks are presented here using using std cout using std cin using std endl 1 cin number1 number2 2 if number1 number2 cout number1 number2 endl Try It Yourself Type in the code as we did before Compile and Run Enter 3 Test Cases 1 99 98 2 5 100 3 23 23


View Full Document

UVa-Wise COSC 181 - Foundations of Computer Programming

Download Foundations of Computer Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Foundations of Computer Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Foundations of Computer Programming and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?