Study recommendations for the Mid-Term Exam - Chapters 1-5
|
|
- Jacob Bryan
- 6 years ago
- Views:
Transcription
1 Study recommendations for the Mid-erm Exam - Chapters 1-5 Review Chapters 1-5 in your textbook, the Example Pages, and in the Glossary on the website Standard problem solving steps used in program development (in order): ANALYSIS: LOGICAL DESK WORK 1. Define the ask or Objectives 2. Define the Output 3. Define the Input 4. Define the Algorithm 5. Check the Algorithm PROGRAMMING: PHYSICAL CODING 6. Code the Program in a high-level language such as C++ 7. Debug the Program he three types of errors common in programming are: 1. Logic errors: mistakes made in the design of an algorithm - minimized by doing desk checks. 2. Syntax errors: mistakes in use of the programming language when writing source code - detected by the compiler during each attempted compilation. 3. Run-time errors: mistakes occurring during an execution of a program, usually resulting from the entry of unexpected data or some hardware problem. he rules of syntax for defining valid identifiers in the C++ Language: Identifiers can contain only letters (either case), numerals, or the underscore character ( _ ), although identifiers starting with an underscore had special restrictions and an identifier consisting of only a lone underscore is forbidden. No blank spaces or special characters are allowed; nor should you use double underscores. Identifiers cannot start with a digit. A C++ reserved word cannot be used as an identifier. Identifiers are case sensitive. he maximum length of an identifiers depends on the compiler being used, but most allow at least 1024 characters (although such lengths would be extremely impractical). Quiz preparation exercise: Circle the labels that are NO valid variable names under the rules of syntax for C++. cout xyz2 int Sue's 4th abc$ my2nd Note that cout is a standard identifier in C++ but not a reserved word, like int. Rev Page 1 of 13
2 Order of Precedence able (including arithmetic, relational and Boolean operators): () Highest / irst postfix ++ postfix -- ^! prefix ++ prefix -- unary + unary - unary & casts * / % + - < > <= >= ==!= && Lowest / Last Quiz preparation exercise: In each of the four separate expressions below, circle the operator of the arithmetic operation that will be performed first. X / Y / Z ( X * ( M - N ) ) / Y Quiz preparation exercise: X - Y * Z Z / ( X - Y ) Circle any (and all) SYNAX errors in the following C++ statements and describe them briefly on the line provided. Do NO mention logical errors. If a line is valid, answer "OK". Each line is a separate question, independent of the others. #include <iostream>; #define ACOR = 9 const int MAX ; float = AM; Compiler directives are not terminated by a semi-colon Assignment is not used with a symbolic constant Named constants must be initialized when defined Equal sign can be used only after an identifier to initialize X = X * 2; OK (this statement simply doubles X) cout << Hello; // Display Hello loat AM,PAY,AX=10.0; String constants should be enclosed in double quotes he keyword float is all lowercase / his is a comment / Comments must be inside /* and */ pairs or preceded by // NUM = 100 / ( AM + 5 ) cin << AM; // Read keyboard cout >> Hello; cout << precision(4) << 12345; he statement terminating semi-colon is missing cin should use the >> stream extraction operator he << (stream insertion) operator belongs with the cout object he precision manipulator is named setprecision Rev Page 2 of 13
3 cout << left(2) << ; C = static-cast<float>(a) / B; cout << "Hello"\n; he left manipulator uses no arguments he keyword static_cast contains an underscore rather than a hyphen he \n escape sequence should be inside the quotes Quiz preparation exercise: or each of the following logical statements, write one C++ statement to perform the specified task. Assume that these tasks are all a part of a restaurant-bill-calculating program using identifiers as shown below: LABEL DESCRIPION SOURCE USAGE DESINAION PUR Amount of the purchase Assigned for AX & PAY --- AX Calculated sales tax Calculation for PAY --- PAY otal amount to pay after tax Calculation - Displayed 1. Allocate (set aside) storage for the three variables that may have decimal points. double PUR,AX,PAY; // Note: the float data type would also be OK for small values 2. Display the program title "AX PROGRAM" on a line of its own. cout << " AX PROGRAM\n "; // or cout << " AX PROGRAM" << endl; 3. Assign the value into the variable that holds the purchase. PUR = ; 4. Calculate and store the tax as 6% of the purchase amount. AX = 0.06 * PUR; 5. Display the string "Please pay $" followed by the total amount to pay rounded to cents, followed by a carriage return. cout << "Please pay $" << setprecision(2) << fixed << PAY << endl; Rev Page 3 of 13
4 Output ormatting Examples Review the following examples of formatted output statements paying close attention to the format of the resulting output beside them. Each box indicates one character position on the screen. All output starts in the leftmost box, although some output might be "padded" with blank spaces to align it to the right edge of the field. "X"'s indicated unused positions. C++ command using cout with various stream manipulators (assuming default values for any missing manipulators) cout << setw(3) << 'A'; Output Produced on Screen Position: A X X X X X X X X X X X X cout << setw(3) << left << 'A'; A X X X X X X X X X X X X cout << setw(8) << "ABCD"; cout << 52; cout << setw(8) << 52; A B C D X X X X X X X 5 2 X X X X X X X X X X X X X 5 2 X X X X X X X cout << setw(8) << left << 52; 5 2 X X X X X X X cout << ; cout << setw(10) << setprecision(2) << fixed << ; cout << setw(10) << setprecision(6) << fixed << showpoint << ; cout << setw(10) << setprecision(2) << fixed << left << ; cout << setprecision(2) << fixed << ; cout << setw(10) << setprecision(3) << fixed << -45.8; cout << setw(10) << ; X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X Rev Page 4 of 13
5 SELECION SRUCURES: Structures such as the one on the left are coded in C++ using the reserved word if. Set X to 1 Set A to 0 A > 0 and A < 9 Replace X with triple its original value. he diamond shape encloses the condition that is being tested (in this example, a Boolean expression). Remember that the C++ if statement can only execute one statement on each leg ( or ), so the pair of steps on the alse leg must be coded inside of a and pair to make them a single compound statement. hus the C++ code would be: if (A>0 && A<9) X=X*3; else X=1; A=0; Note the use of the parentheses around the condition in the code above. Additional parentheses are often necessary because of the order of precedence of operators in C++ (see the table on the previous page). Remember also that the alse leg may be empty, but not the rue leg. If your flowchart shows the opposite, then reverse the labeling of the rue and alse legs and reverse the logic of the condition inside the diamond. If you can't determine what the logical opposite of the condition would be, simply use the NO operator like this:! ( A>0 && A<9 ) ruth ables for Boolean Operators: (Op = Operand, a relational expression or Boolean value) Op.A Op.B Op.A && Op.B Op.A Op.B Op.A Op.B Op.A! ( Op.A ) Rev Page 5 of 13
6 CASE Selection C++'s switch statement can be used in the special situation that you are testing for many possible values in a single ordinal storage location. In the example below, five possible paths might be followed depending on the value stored in the character storage location X. Each path (leg) is selected based on the individual value(s) that might be stored in X. he C++ code would be: A 1 X "A" "B" "C" "D","E" else A 2 Y 1 A 3 A 4 A 0 switch (X) case 'A': A=1; break; case 'B': A=2; Y=1; break; case 'C': A=3; break; case 'D': case 'E': A=4; break; default: A=0; break; Notice: (1) the parentheses around the character expression (X) (2) the inclusion of "break;" after each option serving to brace any multiple statements on each leg (3) the braces used to enclose the full list of options. he use of indentation and the positions of the carriage returns in the code are irrelevant. ( Continued on next page ) Rev Page 6 of 13
7 SAMPLE QUESIONS: (AND ANSWERS) Draw a flowchart that matches the following code. Answer: Start X N = 30 if (N == 0); cout << "Yes"; End Yes Notice that the semicolon which follows the condition N==0 terminates the if statement, making it pointless. he cout statement will be executed regardless of the condition's value. Draw a flowchart that matches the following code. if (X == 3) Y = 4; Z = 5; Answer: Start End X = 3 Z 5 Y 4 Notice that the Z = 5 step follows the selection. It is not part of the true leg because it was not included inside of a pair of braces. he semicolon following the Y = 4 statement terminated the if statement. Circle any SYNAX (not run-time) ERRORS (there may be more than one) in each of the following C++ code segments. If a segment is valid answer "OK". Assume all variables already have been correctly declared. cin >> A; if ( A<10 && >20 ) cout << "ok"; >20 is not a complete relational expression X=1; cin >> Y; if X > Y cout << "OK" else cout << "NO"; missing parentheses around condition and missing semi-colon after if statement Rev Page 7 of 13
8 Indicate the Boolean results (RUE or ALSE) for each of the following expressions, given: #define S "123" /* a string of numerals */ int A=0, B=2, C=-3; A==0 B<2 && C<0!(A>C) && A<C A!=0 B<2 S>"8" rue alse alse alse S>100 Logically invalid (data type mismatch) Given the following declarations for employee data within a program: int A; /* Age */ char D; /* Highest Degree Earned (only possible values are uppercase: 'N' = None, 'B' = Bachelor's, 'M' = Master's, or 'D' = Ph.D.) */ char G; /* Gender (only uppercase 'M' or '' are possible) */ Write a compound If statement in C++ that will display the message "OK" only when the employee is a female, between the ages of 20 and 30 (inclusive) and holds a college degree (Bachelor's, Master's or Ph.D.). Do NO check for case. Assume that previous statements have guaranteed uppercase values only, so that you need only check for uppercase values. Answer: if ( G== && A>=20 && A<=30 && ( D== B D== M D== D ) ) cout << "OK"; REPEIION SRUCURES: Structure: We studied two repetition structures (loops); one known as leading decision (a.k.a. pretest) and another known as trailing decision (a.k.a. posttest). he primary difference between them is in where the test that controls the loop is performed. Leading decision loops test before each pass and are coded in C++ using while (condition) body_statements; railing decision loops test after each pass and are coded in C++ using do body_statements; while (condition); We can design a loop that test somewhere in the middle, but that is consider very poor programming practice. Control: We studied two methods of controlling loop passage and exit. Counting control is based on the testing of values that have been set and altered by the programmer. Programmers know in advance how many times any counting loop will pass (execute its body) because all values of its control variable are predictable. Sentinel Rev Page 8 of 13
9 control is based on the testing of external values that have been read into the program. Programmers do not know in advance how many times a sentinel loop will pass (execute its body) because the values of its control variable are unpredictable. Boundary Values: he values of variables just prior to the entry into a loop and just after the exit from a loop are called boundary values. Steps inside a loop can be organized so that the value of a variable is changed after it is displayed, so don't expect that variables will always contain the last value that you saw displayed. Counting Loops: All counting loops have at least four parts: initialization - prior to the loop entry, a first value of the control variable is set body - where the step(s) to be repeated belong increment (or decrement) - where the control variable is increased (or decreased) test - where the control variable is tested to determine whether the loop should pass or exit. he bottom three steps are not always in the order listed above. he order of the steps will affect the boundary values of the control variable. he two examples below show loops that will count from 1 to 9 and display the value of the control variable (also called a counter in a counting loop). Notice the exit value on N will be 10. N 1 N=1; N 1 N=1; while (N<=9) do N<=9 N cout <<N<<endl; N cout <<N<<endl; N = N+1; N N+1 N = N+1; N N+1 N <= 9 while (N<=9); If a loop: (1) uses the Leading Decision structure, (2) uses counting control, and (3) increments as the last step of its pass, C++ offers a special "automatic loop" statement combining the statements above (on the left) into the single statement: for (N=1; N<=9; N=N+1) cout << N << endl; Note: if the body of the loop has more than one statement to repeat, block it inside of braces. Most common coding errors when writing source code for loops: Closing the loop statement too soon with a misplaced semicolon ailing to block a body with multiple statements inside of braces orgetting the difference between the operators = (assignment) and == (equality) Rev Page 9 of 13
10 SAMPLE QUESIONS: (AND ANSWERS) Circle any SYNAX (not run-time) ERRORS (there may be more than one) in each of the following C++ code segments. If a segment is valid answer "OK". Assume all variables have been correctly declared. for (I=1, I<=79, I++) cout << "-"; the commas (,) should be semi-colons (;) X=1; while X < 5 cout << X++; missing parentheses around condition Use the following for Statement to answer the next 3 questions (A-C). for (Count=Start; Count<=inish; Count++) cout << Count; (A) Which variable is the "control variable"? Count (B) What does Count++ mean? _Increment Count by 1 after a pass is complete (C) If Start contains a value of -4 and inish contains the value 0, how many times will the loop execute? Answer: 5 lowchart a program with a loop that accumulates whole numbers entered by the user until a -1 is entered and then identifies and displays the sum. hen write the C++ code to the right of it. Start ot 0 N is not -1 Sum is: ot Number (-1 to stop)? N N is not -1 ot ot + N End /* accumulate.cpp */ #include <iostream> using namespace std; int main () int N, ot=0; do cout << "Number (-1 to stop)? "); cin >> N; if (N!= -1) ot = ot + N; while (N!= -1); cout << "Sum is: " << ot << endl; return 0; Rev Page 10 of 13
11 or each question below, circle any and all loop control methods for which the claims are true: (A) his control method is based on values assigned by the programmer, not given by the user. counting sentinel (B) his control method is based on values entered by the user. counting sentinel (C) he number of passes that the loop will perform can always be predetermined when the loop starts. counting sentinel or each question below, circle any and all loop structures for which the claims are true: (A) he test for each repetition is performed after the pass through the loop body. leading decision trailing decision (B) he body will always be executed at least once. leading decision trailing decision (C) his structure is appropriate for sentinel controlled loops that use a "prime read". leading decision trailing decision (D) Sentinel controlled loops using this structure need an extra test to guard the body from the sentinel value. leading decision trailing decision DISK ILE INPU AND OUPU: Review the last part of Chapter 5 in your textbook that discuss reading and writing of sequential text files on disks. hen study the practice exercise on the following page. It involves a file with a simple name that is located in the same folder as the program. Be aware that special consideration must be given when providing filenames or paths that contain whitespaces or characters that C++ interprets as having special meaning, such as backwards slashes. or example, to open a file named "My ile.txt" entered at the keyboard, you would need to input the string using the getline() function to prevent the whitespace from truncating the portion of the filename starting at the whitespace before assigning it to a string variable, as in: getline (cin, StringVar); // read a string containing whitespaces Rev Page 11 of 13
12 o associate a file accessible from the disk location "C:\User\JStudent\Data.txt" with a file input stream object named "inile", you would have to escape the backwards slashes (\) as follows: inile.open("c:\\user\\jstudent\\data.txt "); Examine the following C++ source code: /************************************************************ * Program: diskio.cpp - Practice Exercise * * Opens a file in the same folder as the program based on a * * user supplied name (without whitespaces). hen writes ten * * lines of text, closes the file, then reopens the file and * * reads and displays each of the ten lines from the file. * ************************************************************/ #include <iostream> #include <fstream> using namespace std; int main () string ILENAME; // String object to hold a filename system ("cls"); /* Clear the Screen */ cout << "Disk I/O Program\n\n"; cout << "What is the filename (w/o path)? "; cin >> ILENAME; ofstream fileout; fileout.open(ilename.c_str()); // open requires a C-String if (fileout) // Verify successful open cout << ILENAME << " opened successfully for writing.\n\n"; for (int C=1; C<=10; C++) fileout << "Line " << C << endl; fileout.close(); else cout << ILENAME << "\a failed to open.\n"; string OSR; ifstream filein; filein.open(ilename.c_str()); if (filein) cout << ILENAME << " opened successfully for reading.\ncontents:\n"; for (int C=1; C<=10; C++) getline(filein,osr); // read a line of text with whitespaces cout << OSR << endl; Rev Page 12 of 13
13 filein.close(); else cout << ILENAME << "\a failed to open.\n"; system ("pause"); return 0; Rev Page 13 of 13
Study recommendations for Quiz 5 - Chapter 5
Study recommendations for Quiz 5 - Chapter 5 Review Chapter 5 content in: your textbook, the Example Pages, and in the Glossary on the website Review the revised Order of Precedence able (including arithmetic,
More informationCOP 2000 Introduction to Computer Programming Mid-Term Exam Review
he exam format will be different from the online quizzes. It will be written on the test paper with questions similar to those shown on the following pages. he exam will be closed book, but students can
More informationIncrement and the While. Class 15
Increment and the While Class 15 Increment and Decrement Operators Increment and Decrement Increase or decrease a value by one, respectively. the most common operation in all of programming is to increment
More informationc++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.
Chapter 1 File Extensions: Source code (cpp), Object code (obj), and Executable code (exe). Preprocessor processes directives and produces modified source Compiler takes modified source and produces object
More informationBITG 1233: Introduction to C++
BITG 1233: Introduction to C++ 1 Learning Outcomes At the end of this lecture, you should be able to: Identify basic structure of C++ program (pg 3) Describe the concepts of : Character set. (pg 11) Token
More informationChapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.
Chapter 2 C++ Basics 1 Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-3 2.1 Variables and Assignments 2
More informationChapter 2 Basic Elements of C++
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion
More information1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.
1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. B. Outputs to the console a floating point number f1 in scientific format
More informationComputer Programming : C++
The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program
More informationUNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationBy the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program
1 By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program variables. Apply C++ syntax rules to declare variables, initialize
More informationo Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement
Last Time Let s all Repeat Together 10/3/05 CS150 Introduction to Computer Science 1 1 We covered o Counter and sentinel controlled loops o Formatting output Today we will o Type casting o Top-down, stepwise
More informationChapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.
Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style 3 2.1 Variables and Assignments Variables and
More informationChapter 2. C++ Basics
Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-2 2.1 Variables and Assignments Variables
More informationChapter 5: Loops and Files
Chapter 5: Loops and Files 5.1 The Increment and Decrement Operators The Increment and Decrement Operators ++ is the increment operator. It adds one to a variable. val++; is the same as val = val + 1;
More informationChapter 5: Prefix vs. Postfix 8/19/2018. The Increment and Decrement Operators. Increment and Decrement Operators in Program 5-1
Chapter 5: Loops and Files The Increment and Decrement Operators ++ is the increment operator. It adds one to a variable. val++; is the same as val = val + 1; ++ can be used before (prefix) or after (postfix)
More informationChapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments
Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Copyright 2011 Pearson Addison-Wesley. All rights
More informationChapter 4 - Notes Control Structures I (Selection)
Chapter 4 - Notes Control Structures I (Selection) I. Control Structures A. Three Ways to Process a Program 1. In Sequence: Starts at the beginning and follows the statements in order 2. Selectively (by
More information2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program
Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program
More informationObjectives. In this chapter, you will:
Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about
More informationCPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)
Name Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Relational Expression Iteration Counter Count-controlled loop Loop Flow
More informationObjectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program
Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 2: Basic Elements of C++
Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More information5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. The Increment and Decrement Operators
Chapter 5: 5.1 Looping The Increment and Decrement Operators The Increment and Decrement Operators The Increment and Decrement Operators ++ is the increment operator. It adds one to a variable. val++;
More informationChapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction
Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers
More informationMultiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More information5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. Looping. ++ is the increment operator.
Chapter 5: Looping 5.1 The Increment and Decrement Operators Copyright 2009 Pearson Education, Inc. Copyright Publishing as Pearson 2009 Addison-Wesley Pearson Education, Inc. Publishing as Pearson Addison-Wesley
More informationThe C++ Language. Arizona State University 1
The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University
More informationVARIABLES & ASSIGNMENTS
Fall 2018 CS150 - Intro to CS I 1 VARIABLES & ASSIGNMENTS Sections 2.1, 2.2, 2.3, 2.4 Fall 2018 CS150 - Intro to CS I 2 Variables Named storage location for holding data named piece of memory You need
More informationName SECTION: 12:45 2:20. True or False (12 Points)
Name SECION: 12:45 2:20 rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables
More informationCPE Summer 2015 Exam I (150 pts) June 18, 2015
Name Closed notes and book. If you have any questions ask them. Write clearly and make sure the case of a letter is clear (where applicable) since C++ is case sensitive. You can assume that there is one
More informationC++ Programming: From Problem Analysis to Program Design, Third Edition
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection) Control Structures A computer can proceed: In sequence Selectively (branch) - making
More informationFundamentals of Programming CS-110. Lecture 2
Fundamentals of Programming CS-110 Lecture 2 Last Lab // Example program #include using namespace std; int main() { cout
More informationReview: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements
Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja
More informationc) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.
2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C
More informationI/O Streams and Standard I/O Devices (cont d.)
Chapter 3: Input/Output Objectives In this chapter, you will: Learn what a stream is and examine input and output streams Explore how to read data from the standard input device Learn how to use predefined
More informationChapter 2: Introduction to C++
Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 2.1 Parts of a C++
More informationChapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen
Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley
More informationTutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays
Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays Outline 13.1 Test-Driving the Salary Survey Application 13.2 Introducing Arrays 13.3 Declaring and Initializing Arrays 13.4 Constructing
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1
NAGERCOIL COMPUTER SCIENCE Grade: IX C++ PROGRAMMING 1 C++ 1. Object Oriented Programming OOP is Object Oriented Programming. It was developed to overcome the flaws of the procedural approach to programming.
More informationC++ Programming: From Problem Analysis to Program Design, Third Edition
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine
More informationExpressions, Input, Output and Data Type Conversions
L E S S O N S E T 3 Expressions, Input, Output and Data Type Conversions PURPOSE 1. To learn input and formatted output statements 2. To learn data type conversions (coercion and casting) 3. To work with
More information7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING
KEY CONCEPTS COMP 10 EXPLORING COMPUTER SCIENCE Lecture 2 Variables, Types, and Programs Problem Definition of task to be performed (by a computer) Algorithm A particular sequence of steps that will solve
More informationMultiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationChapter 2 - Control Structures
Chapter 2 - Control Structures 1 2.1 Introduction 2.2 Algorithms 2.3 Pseudocode 2.4 Control Structures 2.5 if Selection Structure 2.6 if/else Selection Structure 2.7 while Repetition Structure 2.8 Formulating
More informationCSc 10200! Introduction to Computing. Lecture 4-5 Edgardo Molina Fall 2013 City College of New York
CSc 10200! Introduction to Computing Lecture 4-5 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 3 Assignment, Formatting, and Interactive Input
More informationChapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the
More informationExpressions and Data Types CSC 121 Spring 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationChapter 3 Problem Solving and the Computer
Chapter 3 Problem Solving and the Computer An algorithm is a step-by-step operations that the CPU must execute in order to solve a problem, or to perform that task. A program is the specification of an
More informationMultiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationChapter 3 - Notes Input/Output
Chapter 3 - Notes Input/Output I. I/O Streams and Standard I/O Devices A. I/O Background 1. Stream of Bytes: A sequence of bytes from the source to the destination. 2. 2 Types of Streams: i. Input Stream:
More informationCS242 COMPUTER PROGRAMMING
CS242 COMPUTER PROGRAMMING I.Safa a Alawneh Variables Outline 2 Data Type C++ Built-in Data Types o o o o bool Data Type char Data Type int Data Type Floating-Point Data Types Variable Declaration Initializing
More information*Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN
PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN
More informationFull file at C How to Program, 6/e Multiple Choice Test Bank
2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)
More informationEngineering Problem Solving with C++, 3e Chapter 2 Test Bank
1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A. integer B 1.427E3 B. double D "Oct" C. character B -63.29 D. string F #Hashtag
More informationMultiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More information2 nd Week Lecture Notes
2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous
More informationCS106X Handout 03 Autumn 2012 September 24 th, 2012 Getting Started
CS106X Handout 03 Autumn 2012 September 24 th, 2012 Getting Started Handout written by Julie Zelenski, Mehran Sahami, Robert Plummer, and Jerry Cain. After today s lecture, you should run home and read
More informationChapter 2 - Control Structures
Chapter 2 - Control Structures 1 Outline 2.1 Introduction 2.2 Algorithms 2.3 Pseudocode 2.4 Control Structures 2.5 if Selection Structure 2.6 if/else Selection Structure 2.7 while Repetition Structure
More informationA First Program - Greeting.cpp
C++ Basics A First Program - Greeting.cpp Preprocessor directives Function named main() indicates start of program // Program: Display greetings #include using namespace std; int main() { cout
More informationCPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)
Name rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables retain their value
More informationEngineering Problem Solving with C++, Etter/Ingber
Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs C++, Second Edition, J. Ingber 1 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input
More informationThe C++ Language. Output. Input and Output. Another type supplied by C++ Very complex, made up of several simple types.
The C++ Language Input and Output Output! Output is information generated by a program.! Frequently sent the screen or a file.! An output stream is used to send information. Another type supplied by C++
More information5. Control Statements
5. Control Statements This section of the course will introduce you to the major control statements in C++. These control statements are used to specify the branching in an algorithm/recipe. Control statements
More informationCS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma.
REVIEW cout Statement The cout statement invokes an output stream, which is a sequence of characters to be displayed to the screen. cout
More informationSoftware Design & Programming I
Software Design & Programming I Starting Out with C++ (From Control Structures through Objects) 7th Edition Written by: Tony Gaddis Pearson - Addison Wesley ISBN: 13-978-0-132-57625-3 Chapter 3 Introduction
More informationChapter 2: Overview of C++
Chapter 2: Overview of C++ Problem Solving, Abstraction, and Design using C++ 6e by Frank L. Friedman and Elliot B. Koffman C++ Background Introduced by Bjarne Stroustrup of AT&T s Bell Laboratories in
More information! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char
Week 1 Operators, Data Types & I/O Gaddis: Chapters 1, 2, 3 CS 5301 Fall 2016 Jill Seaman Programming A program is a set of instructions that the computer follows to perform a task It must be translated
More informationWeek 3: File I/O and Formatting 3.7 Formatting Output
Week 3: File I/O and Formatting 3.7 Formatting Output Formatting: the way a value is printed: Gaddis: 3.7, 3.8, 5.11 CS 1428 Fall 2014 Jill Seaman spacing decimal points, fractional values, number of digits
More informationCSCI 1061U Programming Workshop 2. C++ Basics
CSCI 1061U Programming Workshop 2 C++ Basics 1 Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment Statements Console Input/Output
More information1. C++ Overview. C++ Program Structure. Data Types. Assignment Statements. Input/Output Operations. Arithmetic Expressions.
1. C++ Overview 1. C++ Overview C++ Program Structure. Data Types. Assignment Statements. Input/Output Operations. Arithmetic Expressions. Interactive Mode, Batch Mode and Data Files. Common Programming
More informationLoops and Files. of do-while loop
L E S S O N S E T 5 Loops and Files PURPOSE PROCEDURE 1. To introduce counter and event controlled loops 2. To work with the while loop 3. To introduce the do-while loop 4. To work with the for loop 5.
More informationThe American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011
The American University in Cairo Department of Computer Science & Engineering CSCI 106-07&09 Dr. KHALIL Exam-I Fall 2011 Last Name :... ID:... First Name:... Form I Section No.: EXAMINATION INSTRUCTIONS
More informationLECTURE 02 INTRODUCTION TO C++
PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 02 INTRODUCTION
More informationIntroduction to Programming EC-105. Lecture 2
Introduction to Programming EC-105 Lecture 2 Input and Output A data stream is a sequence of data - Typically in the form of characters or numbers An input stream is data for the program to use - Typically
More informationLaboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++
Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++ 0.1 Introduction This is a session to familiarize working with the Visual Studio development environment. It
More informationIntroduction to Programming using C++
Introduction to Programming using C++ Lecture One: Getting Started Carl Gwilliam gwilliam@hep.ph.liv.ac.uk http://hep.ph.liv.ac.uk/~gwilliam/cppcourse Course Prerequisites What you should already know
More informationGetting started with C++ (Part 2)
Getting started with C++ (Part 2) CS427: Elements of Software Engineering Lecture 2.2 11am, 16 Jan 2012 CS427 Getting started with C++ (Part 2) 1/22 Outline 1 Recall from last week... 2 Recall: Output
More informationProgramming. C++ Basics
Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++
More informationCSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York
CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this
More informationDefinition Matching (10 Points)
Name SOLUTION Closed notes and book. If you have any questions ask them. Write clearly and make sure the case of a letter is clear (where applicable) since C++ is case sensitive. There are no syntax errors
More information1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A.
Engineering Problem Solving With C++ 4th Edition Etter TEST BANK Full clear download (no error formating) at: https://testbankreal.com/download/engineering-problem-solving-with-c-4thedition-etter-test-bank/
More informationChapter 2 - I know what I want to do NOW WHAT? Student Learning Outcomes (SLOs)
Chapter 2 - I know what I want to do NOW WHAT? Student Learning Outcomes (SLOs) a. You should be able to list two significant characteristics for each of the basic data types (bool, int, double, and char).
More informationProgram Organization and Comments
C / C++ PROGRAMMING Program Organization and Comments Copyright 2013 Dan McElroy Programming Organization The layout of a program should be fairly straight forward and simple. Although it may just look
More informationDEPARTMENT OF MATHS, MJ COLLEGE
T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,
More informationAdd Subtract Multiply Divide
ARITHMETIC OPERATORS if AND if/else AND while LOOP Order of Operation (Precedence Part 1) Copyright 2014 Dan McElroy Add Subtract Multiply Divide + Add - Subtract * Multiply / Divide = gives the quotient
More informationChapter 1 INTRODUCTION
Chapter 1 INTRODUCTION A digital computer system consists of hardware and software: The hardware consists of the physical components of the system. The software is the collection of programs that a computer
More informationUNIT-2 Introduction to C++
UNIT-2 Introduction to C++ C++ CHARACTER SET Character set is asset of valid characters that a language can recognize. A character can represents any letter, digit, or any other sign. Following are some
More informationLab # 02. Basic Elements of C++ _ Part1
Lab # 02 Basic Elements of C++ _ Part1 Lab Objectives: After performing this lab, the students should be able to: Become familiar with the basic components of a C++ program, including functions, special
More informationIntroduction to the C++ Programming Language
LESSON SET 2 Introduction to the C++ Programming Language OBJECTIVES FOR STUDENT Lesson 2A: 1. To learn the basic components of a C++ program 2. To gain a basic knowledge of how memory is used in programming
More informationControl Structures. Control Structures Conditional Statements COMPUTER PROGRAMMING. Electrical-Electronics Engineering Dept.
EEE-117 COMPUTER PROGRAMMING Control Structures Conditional Statements Today s s Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate logical
More informationChapter 2 - Control Structures
Chapter 2 - Control Structures 1 Outline 2.1 Introduction 2.2 Algorithms 2.3 Pseudocode 2.4 Control Structures 2.5 if Selection Structure 2.6 if/else Selection Structure 2.7 while Repetition Structure
More informationAn Introduction to Programming with C++ Sixth Edition. Chapter 7 The Repetition Structure
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure Objectives Differentiate between a pretest loop and a posttest loop Include a pretest loop in pseudocode Include
More informationREPETITION CONTROL STRUCTURE LOGO
CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of
More informationOverview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program
Overview - General Data Types - Categories of Words - The Three S s - Define Before Use - End of Statement - My First Program a description of data, defining a set of valid values and operations List of
More informationLooping. Arizona State University 1
Looping CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 5 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University
More informationCOP 2000 Note Framework Chapter 5 - Repetition Page 1
COP 2000 Note Framework Chapter 5 - Repetition Page 1 The programming approach in which all problems are broken down using only three simple control structures, each of which has only one starting point
More informationBASIC ELEMENTS OF A COMPUTER PROGRAM
BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators
More informationPART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.
Unit - III CHAPTER - 9 INTRODUCTION TO C++ Choose the correct answer. PART I 1. Who developed C++? (a) Charles Babbage (b) Bjarne Stroustrup (c) Bill Gates (d) Sundar Pichai 2. What was the original name
More information