Unformatted text preview:

Intro to Programming Topic 9 Part 2 Chapter 4 Coding INPUT from flowcharts INPUT ageOne INPUT ageTwo cout Enter first age Note the cin ageOne spacing cout Enter second age cin ageTwo Notice that the variable names match Note the spacing Each input on a flow chart will have a corresponding cout cin pair all other constructs are 1 1 1 symbol per statement Chapter 2 CS1A Review Ch 3 Basic input Output 2 endl vs n Move the output to a new line They both accomplish essentially the same task endl manipulator n is an escape sequence Chapter 3 Programming Basics 3 1 Program Basic Structure Directive s information the program needs a list of all necessary header files used in the program Heading int main functions by definition return a value the above heading indicates that this function will return an int Inside the int main function named constant declarations variable declarations executable statements return 0 Chapter 2 CS1A Review Ch 3 Basic input Output 4 Identifiers Review What are the two types of identifiers 1 2 Which can appear on the right side of a cout statement Which can appear on the right side of a cin statements Chapter 3 Programming Basics 5 Declaring Identifiers Review How do we declare variables Examples How do we declare constants Examples 6 2 Variables Constants When is the amount of memory that will be allocated determined for a variable When is the amount of memory that will be allocated determined for a constant When is a value placed in a variable When is a value place in a constant Name two ways to assign values to a variable Examples 7 Data Tables What is a Data Table What 2 things should the data table contain Example int ageOne int ageTwo float averageAge char answer IN CALC first age from user IN CALC second age from user CALC OUT average of two input ages IN OUT holds Y or N response from user char userName 20 IN OUT name of program user Chapter 3 Programming Basics 8 Declaration Section Exercise Write the necessary declaration section for a program requiring the following variables and named constants Use the proper style and be sure to include the data table Also remember that identifiers must be descriptive a location to hold the name of the programmer an unchanging value a location to hold the date the code was written an unchanging value locations to hold the names of two users of the program input from the keyboard locations to hold the ages of each of the two users input from the keyboard a location to hold the older of the two calculated output a location to hold the average of the ages calculated output Chapter 3 Programming Basics 9 3 a location to hold the name of the programmer an unchanging value a location to hold the date the code was written an unchanging value locations to hold the names of two users of the program input from keyboard locations to hold the ages of each of the two users input from the keyboard a location to hold the older of the two calculated output a location to hold the average of the ages calculated output 10 Assignment Statements Review Syntax variableName expression Assigns the expression to the variable Example ageOne 15 ageTwo 23 averageAge ageOne ageTwo 2 0 answer y Note the spacing before and after all operators 11 Chapter 2 CS1A Review Ch 3 Basic input Output Review 1 A compiler translates code written in a language into language 2 T F Syntax is the rules that dictate the meaning attached to instructions in a programming language 3 A is the name of a location in memory that has a data value that may be changed 4 Values for these identifiers are obtained at time and the amount of memory to be reserved is determined at 5 A is the name of a location in memory that has a data value that may not be changed 6 Values for these identifiers are obtained at time and the amount of memory to be reserved is determined at 12 4 7 The documentation next to the declarations for variables and named constants is called the 8 It tells the reader and their values are used obtained 9 Each input block shown on a flowchart requires a statement to prompt the user and a statement to place the input value into the specified memory location 10 Explain the difference between the following declarations char charVal char strVal 10 13 5


View Full Document

Saddleback CS 1A - Intro to Programming

Loading Unlocking...
Login

Join to view Intro to 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 Intro to 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?