Introduction to C++ Programming

Size: px
Start display at page:

Download "Introduction to C++ Programming"

Transcription

1 2 Introduction to C++ Programming OBJECTIVES In this chapter you will learn: To write simple computer programs in C++. To write simple input and output statements. To use fundamental types. Basic computer memory concepts. To use arithmetic operators. The precedence of arithmetic operators. To write simple decision-making statements. Aristophanes

2

3 Chapter 2 Introduction to C++ Programming 3 Assignment Checklist Date: Section: Exercises Assigned: Circle assignments Date Due Prelab Activities Matching YES NO Fill in the Blank 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 Short Answer 26, 27, 28, 29, 30, 31, 32 Programming Output 33, 34, 35, 36, 37, 38, 39 Correct the Code 40, 41, 42, 43, 44, 45 Lab Exercises Exercise 1 Sum, Average, Product, Smallest and Largest YES Follow-Up Questions and Activities 1, 2 NO Exercise 2 Multiples YES NO Follow-Up Questions and Activities 1, 2, 3, 4 Exercise 3 Separating Digits YES NO Follow-Up Questions and Activities 1, 2, 3 Debugging YES NO Labs Provided by Instructor Postlab Activities Coding Exercises 1, 2, 3, 4, 5, 6, 7 Programming Challenges 1, 2, 3

4

5 Chapter 2 Introduction to C++ Programming 5 Prelab Activities Matching Date: Section: After reading Chapter 2 of C++ How to Program: Fifth Edition, answer the given questions. These questions are intended to test and reinforce your understanding of key concepts and may be done either before the lab or during the lab. For each term in the column on the left, write the corresponding letter for the description that best matches it from the column on the right. Term Description D H I G A L J E B C M K F 1. Integer division 2. Stream extraction operator 3. return 4. Modulus operator 5. A variable of type int 6. Comments 7. Stream insertion operator 8. Preprocessor directive 9. std::endl stream manipulator 10. Semicolon 11. Conditions in if statements 12. Newline escape sequence 13. Syntax error a) Holds whole number values. b) Outputs a newline and flushes the output buffer. c) Appears at the end of every statement. d) An operation that truncates any fractional part of its result. e) Instruction that is performed before the program is compiled. f) Prevents a program from compiling. g) An operation that yields the remainder after integer division. h) >>. i) One of several means to exit a function. j) <<. k) '\n'. l) Text that documents programs and improves their readability. m) Commonly formed by using equality operators and relational operators.

6

7 Chapter 2 Introduction to C++ Programming 7 Prelab Activities Fill in the Blank Fill in the Blank Date: Section: Fill in the blanks in each of the following statements: 14. Both comments and white space are ignored by the C++ compiler. 15. A backslash is combined with the next character to form a(n) escape sequence. 16. A(n) variable is a location in the computer s memory where a value can be stored for use by a program. 17. Output and input in C++ are accomplished with streams of characters. 18. Single-line comments begin with //. 19. main is the first function executed in a C++ program. 20. All variables in a C++ program must be declared before they are used. 21. cin represents the standard input stream. 22. cout represents the standard output stream. 23. The if statement allows a program to make a decision. 24. C++ evaluates arithmetic expressions in a precise sequence determined by the rules of operator precedence and associativity. 25. Equality operators and relational operators can be used in if conditions.

8

9 Chapter 2 Introduction to C++ Programming 9 Prelab Activities Short Answer Short Answer Date: Section: In the space provided, answer each of the given questions. Your answers should be as concise as possible; aim for two or three sentences. 26. What is the difference between stream insertion and stream extraction? What is each used for? Stream insertion is used to insert characters and values into a stream, such as the standard output stream to display data on the screen. Stream extraction is used to extract characters and values from a stream, such as the standard input stream to input data from the keyboard. 27. What is a syntax error? Give an example. A syntax error is a violation of C++ s language rules in the program code. Syntax errors are normally accompanied by error messages from the compiler to help the programmer locate and fix the incorrect code. The program cannot be executed until all syntax errors are corrected. Some examples of syntax errors include forgetting the semicolon at the end of a statement, placing two variable identifiers next to each other without an intervening operator and not closing a parenthetical expression with a right parentheses. 28. What is a logic error? Give an example. A logic error is a mistake in the program code that causes the program to produce incorrect results while executing. A logic error will not be reported by the compiler. Some examples of logic errors include using the incorrect variable in a calculation, using the assignment operator = instead of the equality operator == and spelling a word incorrectly in a message to the user. 29. What are operator precedence and associativity? How do they affect program execution? Operator precedence is the order in which the operations in a statement containing multiple operations will execute. For example, multiplication operations execute before addition operations, unless the addition operations are enclosed within parentheses. Associativity is the order in which multiple operations with the same precedence execute. For example, addition operations are performed from left to right, while assignment operations are performed from right to left. Operator precedence and associativity determine the order in which operations execute and therefore affect the values that are used for each operation. 30. What are redundant parentheses? When might a programmer use them? Redundant parentheses are parentheses in a complex arithmetic expression that do not alter the order of execution for the operations in that arithmetic expression. A programmer might use redundant parentheses to make the order of execution of the expression more clear. For example, parentheses could be placed around the multiplication operations in an arithmetic expression containing both multiplication and addition operations, even though the multiplication operations would be performed first anyway.

10 10 Introduction to C++ Programming Chapter 2 Prelab Activities Short Answer 31. Write an example of a preprocessor directive. #include <iostream> 32. What is a variable? How are they used in computer programs? A variable is a location in the computer s memory. Variables enable a computer program to store values, possibly the results of earlier calculations, for use later later in the program.

11 Chapter 2 Introduction to C++ Programming 11 Prelab Activities Programming Output Programming Output Date: Section: For each of the given program segments, read the code and write the output in the space provided below each program. [ Note: Do not execute these programs on a computer.] 33. What is the output of the following program? 1 #include <iostream> 2 3 using std::cout; 4 using std::endl; 5 6 int main() 7 { 8 int x; 9 int y; x = 30; 12 y = 2 ; 13 cout << x * y + 9 / 3 << endl; return 0 ; } // end main Your answer: What is output by the following line of code? 1 cout << ( 8 * 4 * ) / ; Your answer: 39

12 12 Introduction to C++ Programming Chapter 2 Prelab Activities Programming Output For Programming Output Exercises 35 and 36, use the program in Fig. L #include <iostream> 2 3 using std::cout; 4 using std::cin; 5 using std::endl; 6 7 int main() 8 { 9 int input; cout << "Please enter an integer: " ; 12 cin >> input; if ( input!= 7 ) 15 cout << "Hello" << endl; if ( input == 7 ) 18 cout << "Goodbye" << endl; return 0 ; } // end main Fig. L 2.1 Program used for Programming Output Exercises 35 and What is output by the program in Fig. L 2.1? Assume that the user enters 5 for input. Your answer: Hello 36. What is output by the program in Fig. L 2.1? Assume that the user enters 7 for input. Your answer: Goodbye

13 Chapter 2 Introduction to C++ Programming 13 Prelab Activities Programming Output For Programming Output Exercises 37 and 38, use the program in Fig. L #include <iostream> 2 3 using std::cout; 4 using std::cin; 5 using std::endl; 6 7 int main() 8 { 9 int input; cout << "Please enter an integer: " ; 12 cin >> input; if ( input >= 0 ) 15 cout << "Hello" << endl; cout << "Goodbye" << endl; return 0 ; } // end main Fig. L 2.2 Program used for Programming Output Exercises37 and What is output by the program in Fig. L 2.2? Assume the user enters 2 for input. Your answer: Hello Goodbye 38. What is output by the program in Fig. L 2.2? Assume the user enters -2 for input. Your answer: Goodbye

14 14 Introduction to C++ Programming Chapter 2 Prelab Activities Programming Output 39. What is output by the following program? 1 #include <iostream> 2 3 using std::cout; 4 using std::cin; 5 using std::endl; 6 7 int main() 8 { 9 int x = 3 ; 10 int y = 9 ; 11 int z = 77; if ( x == ( y / 3 ) ) 14 cout << "H" ; if ( z!= 77 ) 17 cout << "q"; if ( z == 77 ) 20 cout << "e"; if ( z * y + x < 0 ) 23 cout << "g"; if ( y == ( x * x ) ) 26 cout << "ll"; cout << "o!" << endl; return 0 ; } // end main Your answer: Hello!

15 Chapter 2 Introduction to C++ Programming 15 Prelab Activities Correct the Code Correct the Code Date: Section: For each of the given program segments, determine if there is an error in the code. If there is an error, specify whether it is a logic, syntax or compilation error, circle the error in the code and write the corrected code in the space provided after each problem. If the code does not contain an error, write no error. For code segments, assume the code appears in main and that using directives are provided for cin, cout and endl. [ Note : It is possible that a program segment may contain multiple errors.] 40. The following program should print an integer to the screen: 1 #include <iostream>; 2 3 using std::cout 4 using std::endl 5 6 int main() 7 { 8 int x = 30; 9 int y = 2 ; cout << x * y + 9 / 3 << endl; return 0 ; } // end main Your answer: 1 #include <iostream> 2 3 using std::cout; 4 using std::endl; 5 6 int main() 7 { 8 int x = 30; 9 int y = 2 ; cout << x * y + 9 / 3 << endl; return 0 ; } // end main Errors: Line 1: There should not be a semicolon after a #include preprocessor directive. Compilation error. Lines 3 4: There should be semicolons after using directives. Compilation error.

16 16 Introduction to C++ Programming Chapter 2 Prelab Activities Correct the Code 41. The following code should declare an integer variable and assign it the value 6. 1 int 1stPlace 2 1stPlace = 6 ; Your answer: 1 int firstplace ; 2 firstplace = 6 ; Errors: Lines 1 2: Variable names cannot begin with digits. The name of the variable must be changed. Compilation error. Line 1: A variable declaration should be followed by a semicolon. Compilation error. 42. The following code should determine whether variable x is less than or equal to 9. 1 int x = 9 ; 2 3 if ( x < = 9 ) 4 cout << "Less than or equal to."; Your answer: 1 int x = 9 ; 2 3 if ( x <= 9 ) 4 cout << "Less than or equal to."; Errors: Line 3: Placing a space between < and = is a syntax error. 43. The following code should determine whether q is equal to int q = 10 ; 2 3 cout << "q is: " << q << endl; 4 5 if ( q = 10 ) 6 cout << "q is equal to 10" ;

17 Chapter 2 Introduction to C++ Programming 17 Prelab Activities Correct the Code Your answer: 1 int q = 10 ; 2 3 cout << "q is: " << q << endl; 4 5 if ( q == 10 ) 6 cout << "q is equal to 10" ; Error: Line 5: Testing for equality is performed with the equality operator ==, not the assignment operator =. Logic error. 44. The following code segment should determine whether an integer variable s value is greater than zero and display an appropriate message. 1 int x = 9 ; 2 3 if ( x > 0 ); 4 cout << "Greater than zero"; Your answer: 1 int x = 9 ; 2 3 if ( x > 0 ) 4 cout << "Greater than zero"; Error: Line 3: Placing a semicolon after the if statement s condition causes the messsage "Greater than zero" to display even if the condition is false. Logic error.

18 18 Introduction to C++ Programming Chapter 2 Prelab Activities Correct the Code 45. The following program should print 302 to the screen: 1 #include <iostream> 2 3 using std::cout; 4 using std::end; 5 6 int ma in() 7 { 8 int x = 30; 9 int y = 2 ; cout << y << x << endl; return 0 ; } // end main Your answer: 1 #include <iostream> 2 3 using std::cout; 4 using std:: endl; 5 6 int main() 7 { 8 int x = 30; 9 int y = 2 ; cout << x << y << endl; return 0 ; } // end main Errors: Line 4: The stream manipulator endl is spelled incorrectly. Compilation error. Line 6: Placing a space in the middle of function name main is a syntax error. Line 11: To display 302, the value of x should be displayed, followed by the value of y. Logic error.

19 Chapter 2 Introduction to C++ Programming 19 Lab Exercises Lab Exercise 1 Sum, Average, Product, Smallest and Largest Date: Section: This problem is intended to be solved in a closed-lab session with a teaching assistant or instructor present. The problem is divided into six parts: 1. Lab Objectives 2. Description of the Problem 3. Sample Output 4. Program Template (Fig. L 2.3) 5. Problem-Solving Tips 6. Follow-Up Questions and Activities The program template represents a complete working C++ program, with one or more key lines of code replaced with comments. Read the problem description and examine the sample output; then study the template code. Using the problem-solving tips as a guide, replace the /* */ comments with C++ code. Compile and execute the program. Compare your output with the sample output provided. Then answer the follow-up questions. The source code for the template is available at and /deitel. Lab Objectives This lab was designed to reinforce programming concepts from Chapter 2 of C++ How To Program: Fifth Edition. In this lab, you will practice: Using cout to output text and variables. Using cin to input data from the user. Using if statements to make decisions based on the truth or falsity of a condition. Using the arithmetic operators to perform calculations. Using relational operators to compare values. The follow-up questions and activities also will give you practice: Comparing < to <=. Modifying existing code to perform the same task in a different manner. Description of the Problem Write a program that inputs three integers from the keyboard, and prints the sum, average, product, smallest and largest of these numbers. The screen dialogue should appear as follows: [ Note: 13, 27 and 14 are input by the user.] Sample Output Input three different integers: Sum is 54 Average is 18 Product is 4914 Smallest is 13 Largest is 27

20 20 Introduction to C++ Programming Chapter 2 Lab Exercises Lab Exercise 1 Sum, Average, Product, Smallest and Largest Template 1 // Lab 1: numbercompare.cpp 2 #include <iostream> // allows program to perform input and output 3 4 using std::cout; // program uses cout 5 using std::endl; // program uses endl 6 using std::cin; // program uses cin 7 8 int main() 9 { 10 int number1; // first integer read from user 11 int number2; // second integer read from user 12 int number3; // third integer read from user 13 int smallest; // smallest integer read from user 14 int largest; // largest integer read from user cout << "Input three different integers: "; // prompt 17 /* Write a statement to read in values for number1, number2 and 18 number3 using a single cin statement */ largest = number1; // assume first integer is largest /* Write a statement to determine if number2 is greater than 23 largest. If so assign number2 to largest */ /* Write a statement to determine if number3 is greater than 26 largest. If so assign number3 to largest */ smallest = number1; // assume first integer is smallest /* Write a statement to determine if number2 is less than 31 smallest. If so assign number2 to smallest */ /* Write a statement to determine if number3 is less than 34 smallest. If so assign number3 to smallest */ /* Write an output statement that prints the sum, average, 37 product, largest and smallest */ return 0 ; // indicate successful termination } // end main Fig. L 2.3 numbercompare.cpp. Problem-Solving Tips 1. Prompt the user to input three integer values. You will use a single cin statement to read all three values. 2. Sometimes it is useful to make an assumption to help solve or simplify a problem. For example, we assume number1 is the largest of the three values and assign it to largest. You will use if statements to determine whether number2 or number3 are larger. 3. Using an if statement, compare largest to number2. If the content of number2 is larger, then store the variable s value in largest. 4. Using an if statement, compare largest to number3. If the content of number3 is larger, then store the variable s value in largest. At this point you are guaranteed to have the largest value stored in largest.

21 Chapter 2 Introduction to C++ Programming 21 Lab Exercises Lab Exercise 1 Sum, Average, Product, Smallest and Largest Solution 5. Perform similar steps to those in Steps 2 4 to determine the smallest value. 6. Write a cout statement that outputs the sum, average, product (i.e., multiplication), largest and smallest values. 7. Be sure to follow the spacing and indentation conventions mentioned in the text. 8. If you have any questions as you proceed, ask your lab instructor for assistance. 1 // Lab 1: numbercompare.cpp 2 #include <iostream> // allows program to perform input and output 3 4 using std::cout; // program uses cout 5 using std::endl; // program uses endl 6 using std::cin; // program uses cin 7 8 int main() 9 { 10 int number1; // first integer read from user 11 int number2; // second integer read from user 12 int number3; // third integer read from user 13 int smallest; // smallest integer read from user 14 int largest; // largest integer read from user cout << "Input three different integers: " ; // prompt 17 cin >> number1 >> number2 >> number3; // read three integers largest = number1; // assume first integer is largest if ( number2 > largest ) // is number2 larger? 22 largest = number2; // number2 is now the largest if ( number3 > largest ) // is number3 larger? 25 largest = number3; // number3 is now the largest smallest = number1; // assume first integer is smallest if ( number2 < smallest ) // is number2 smaller? 30 smallest = number2; // number2 is now the smallest if ( number3 < smallest ) // is number3 smaller? 33 smallest = number3; // number3 is now the smallest cout << "Sum is " << number1 + number2 + number3 36 << "\naverage is " << ( number1 + number2 + number3 ) / 3 37 << "\nproduct is " << number1 * number2 * number3 38 << "\nsmallest is " << smallest 39 << "\nlargest is " << largest << endl; return 0 ; // indicate successful termination } // end main

22 22 Introduction to C++ Programming Chapter 2 Lab Exercises Lab Exercise 1 Sum, Average, Product, Smallest and Largest Follow-Up Questions and Activities 1. Modify your solution to use three separate cin statements rather than one. Write a separate prompt for each cin. 1 // Lab 1: numbercompare.cpp 2 #include <iostream> // allows program to perform input and output 3 4 using std::cout; // program uses cout 5 using std::endl; // program uses endl 6 using std::cin; // program uses cin 7 8 int main() 9 { 10 int number1; // first integer read from user 11 int number2; // second integer read from user 12 int number3; // third integer read from user 13 int smallest; // smallest integer read from user 14 int largest; // largest integer read from user cout << "Input first integer: " ; // prompt 17 cin >> number1; // read an integer 18 cout << "Input second integer: " ; // prompt 19 cin >> number2; // read a second integer 20 cout << "Input third integer: " ; // prompt 21 cin >> number3; // read a third integer largest = number1; // assume first integer is largest if ( number2 > largest ) // is number2 larger? 26 largest = number2; // number2 is now the largest if ( number3 > largest ) // is number3 larger? 29 largest = number3; // number3 is now the largest smallest = number1; // assume first integer is smallest if ( number2 < smallest ) // is number2 smaller? 34 smallest = number2; // number2 is now the smallest if ( number3 < smallest ) // is number3 smaller? 37 smallest = number3; // number3 is now the smallest cout << "Sum is " << number1 + number2 + number3 40 << "\naverage is " << ( number1 + number2 + number3 ) / 3 41 << "\nproduct is " << number1 * number2 * number3 42 << "\nsmallest is " << smallest 43 << "\nlargest is " << largest << endl; return 0 ; // indicate successful termination } // end main

23 Chapter 2 Introduction to C++ Programming 23 Lab Exercises Lab Exercise 1 Sum, Average, Product, Smallest and Largest Input first integer: 13 Input second integer: 27 Input third integer: 14 Sum is 54 Average is 18 Product is 4914 Smallest is 13 Largest is Does it matter whether < or <= is used when making comparisons to determine the smallest integer? Which did you use and why? In this program, it does not matter whether < or <= is used when making comparisons to determine the smallest integer. The only instance when using < as opposed to <= makes a difference is if smallest and the number it is being compared to are equal, in which case either value can be used as the smallest with the same result.

24

25 Chapter 2 Introduction to C++ Programming 25 Lab Exercises Lab Exercise 2 Multiples Lab Exercise 2 Multiples Date: Section: This problem is intended to be solved in a closed-lab session with a teaching assistant or instructor present. The problem is divided into six parts: 1. Lab Objectives 2. Description of the Problem 3. Sample Output 4. Program Template (Fig. L 2.4) 5. Problem-Solving Tips 6. Follow-Up Questions and Activities The program template represents a complete working C++ program, with one or more key lines of code replaced with comments. Read the problem description and examine the sample output; then study the template code. Using the problem-solving tips as a guide, replace the /* */ comments with C++ code. Compile and execute the program. Compare your output with the sample output provided. Then answer the follow-up questions. The source code for the template is available at and /deitel. Lab Objectives This lab was designed to reinforce programming concepts from Chapter 2 of C++ How To Program: Fifth Edition. In this lab, you will practice: Using cout to output text and values. Using cin to input data from the user. Using if statements to make decisions based on the truth or falsity of a condition. Using the modulus operator ( % ) to determine the remainder of an integer division operation. The follow-up questions and activities also will give you practice: Understanding the modulus operator. Recognizing common mistakes with the if statement. Adapting a program to solve a similar problem. Description of the Problem Write a program that reads in two integers and determines and prints whether the first is a multiple of the second. [ Hint : Use the modulus operator.] Sample Output Enter two integers: is not a multiple of 8

26 26 Introduction to C++ Programming Chapter 2 Lab Exercises Lab Exercise 2 Multiples Template 1 // Lab 2: multiples.cpp 2 #include <iostream> // allows program to perform input and output 3 4 using std::cout; // program uses cout 5 using std::endl; // program uses endl 6 using std::cin; // program uses cin 7 8 int main() 9 { 10 /* Write variables declarations here */ cout << "Enter two integers: " ; // prompt 13 /* Write a cin statement to read data into variables here */ // using modulus operator 16 if ( /* Write a condition that tests whether number1 is a multiple of 17 number2 */ ) 18 cout << number1 << " is a multiple of " << number2 << endl; if ( /* Write a condition that tests whether number1 is not a multiple 21 of number2 */ ) 22 cout << number1 << " is not a multiple of " << number2 << endl; return 0 ; // indicate successful termination } // end main Fig. L 2.4 multiples.cpp. Problem-Solving Tips 1. The input data consists of two integers, so you will need two int variables to store the input values. 2. Use cin to read the user input into the int variables. 3. Use an if statement to determine whether the first number input is a multiple of the second number input. Use the modulus operator, %. If one number divides into another evenly, the modulus operation results in 0. If the result is 0, display a message indicating that the first number is a multiple of the second number. 4. Use an if statement to determine whether the first number input is not a multiple of the second number input. If one number does not divide into another evenly, the modulus operation results in a non-zero value. If non-zero, display a message indicating that the first number is not a multiple of the second. 5. Be sure to follow the spacing and indentation conventions mentioned in the text. 6. If you have any questions as you proceed, ask your lab instructor for assistance. Solution 1 // Lab 2: multiples.cpp 2 #include <iostream> // allows program to perform input and output 3 4 using std::cout; // program uses cout 5 using std::endl; // program uses endl 6 using std::cin; // program uses cin

27 Chapter 2 Introduction to C++ Programming 27 Lab Exercises Lab Exercise 2 Multiples 7 8 int main() 9 { 10 int number1; // first integer read from user 11 int number2; // second integer read from user cout << "Enter two integers: " ; // prompt 14 cin >> number1 >> number2; // read two integers from user // using modulus operator 17 if ( number1 % number2 == 0 ) 18 cout << number1 << " is a multiple of " << number2 << endl; if ( number1 % number2!= 0 ) 21 cout << number1 << " is not a multiple of " << number2 << endl; return 0 ; // indicate successful termination } // end main Follow-Up Questions and Activities 1. Can the modulus operator be used with non-integer operands? Can it be used with negative numbers? Assume that the user entered the sets of numbers in Fig. L 2.5. For each set, what does the expression in the third column output? If there is an error, explain why. Integer 1 Integer 2 Expression Output cout << 73 % 22; cout << 0 % 100; cout << 100 % 0; error 3 3 cout << -3 % 3; cout << 9 % 4.5; error 16 2 cout << 16 % 2; 0 Fig. L 2.5 Determine the output of the cout statements in the third column. The modulus operator cannot be used with non-integer operands. It can be used with negative numbers. An error occurs in cout << 100 % 0; because you cannot divide by 0. An error occurs in cout << 9 % 4.5; because you cannot use modulus with a double value.

28 28 Introduction to C++ Programming Chapter 2 Lab Exercises Lab Exercise 2 Multiples 2. Place a semicolon at the end of the if statement in your solution that corresponds to the if statement in lines in the template. What happens? Explain. The line cout << number1 << " is a multiple of " << number2 << endl; always executes, even if number1 is not a multiple of number2, because the semicolon is treated as the empty statement and is considered to be the if s body. The output statement is just another statement that will execute after the if statement executes. 3. Rewrite the cout statement in your solution that corresponds to the cout statement in line 18 in the template. This statement should now look as follows: cout << number1; cout << " is a multiple of " ; cout << number2 << endl; Rerun the program and observe the differences. Why is the output different? The output is different because only the first cout statement is considered to be the if body. The second and third cout statements are now just regular statements that will be executed after the if statement is finished. 4. Modify the program to determine whether a number entered is even or odd. [ Note: Now, the user needs to enter only one number.] 1 // Lab 2: multiples.cpp 2 #include <iostream> // allows program to perform input and output 3 4 using std::cout; // program uses cout 5 using std::endl; // program uses endl 6 using std::cin; // program uses cin 7 8 int main() 9 { 10 int number; // integer read from user cout << "Enter an integer: " ; // prompt 13 cin >> number; // read an integer from user // using modulus operator 16 if ( number % 2 == 0 ) 17 cout << number1 << " is even" << endl; if ( number % 2!= 0 ) 20 cout << number1 << " is odd" << endl; return 0 ; // indicate successful termination } // end main Enter an integer: is even

29 Chapter 2 Introduction to C++ Programming 29 Lab Exercises Lab Exercise 3 Separating Digits Lab Exercise 3 Separating Digits Date: Section: This problem is intended to be solved in a closed-lab session with a teaching assistant or instructor present. The problem is divided into six parts: 1. Lab Objectives 2. Description of the Problem 3. Sample Output 4. Program Template (Fig. L 2.6) 5. Problem-Solving Tips 6. Follow-Up Questions and Activities The program template represents a complete working C++ program, with one or more key lines of code replaced with comments. Read the problem description and examine the sample output; then study the template code. Using the problem-solving tips as a guide, replace the /* */ comments with C++ code. Compile and execute the program. Compare your output with the sample output provided. Then answer the follow-up questions. The source code for the template is available at and /deitel. Lab Objectives This lab was designed to reinforce programming concepts from Chapter 2 of C++ How To Program: Fifth Edition. In this lab, you will practice: Using the modulus operator ( % ) to determine the remainder of a division operation. Integer division, which differs from floating-point division because integer division truncates the decimal portion of the result. The follow-up questions and activities also will give you practice: Using the division and modulus operators. Examining what happens during program execution when the user enters invalid input. Adapting a program to solve a similar problem. Problem Description Write a program that inputs a five-digit number, separates the number into its individual digits and prints the digits separated from one another by three spaces each. [ Hint: Use integer division and the modulus operator.] For example, if the user inputs 42339, the program should print what is shown in the sample output. Sample Output

30 30 Introduction to C++ Programming Chapter 2 Lab Exercises Lab Exercise 3 Separating Digits Template 1 // Lab 3: digits.cpp 2 #include <iostream> // allows program to perform input and output 3 4 using std::cout; // program uses cout 5 using std::endl; // program uses endl 6 using std::cin; // program uses cin 7 8 int main() 9 { 10 int number; // integer read from user cout << "Enter a five-digit integer: " ; // prompt 13 cin >> number; // read integer from user /* Write a statement to print the left-most digit of the 16 5-digit number */ 17 /* Write a statement that changes number from 5-digits 18 to 4-digits */ 19 /* Write a statement to print the left-most digit of the 20 4-digit number */ 21 /* Write a statement that changes number from 4-digits 22 to 3-digits */ 23 /* Write a statement to print the left-most digit of the 24 3-digit number */ 25 /* Write a statement that changes number from 3-digits 26 to 2-digits */ 27 /* Write a statement to print the left-most digit of the 28 2-digit number */ 29 /* Write a statement that changes number from 2-digits 30 to 1-digit */ 31 cout << number << endl; return 0 ; // indicate successful termination } // end main Fig. L 2.6 digits.cpp. Problem-Solving Tips 1. The input data consists of one integer, so you will use an int variable ( number ) to represent it. Note that the description indicates that one five-digit number is to be input not five separate digits. 2. You will use a series of statements to break down the number into its individual digits using modulus ( % ) and division ( / ) calculations. 3. After the number has been input using cin, divide the number by to get the leftmost digit. Why does this work? Because the number input is five digits long, it is divided by to obtain the leftmost digit. In C++, dividing an integer by an integer results in an integer. For example, /10000 evaluates to 4 because divides evenly into four times. The remainder 2339 is truncated. 4. Change the number to a 4-digit number using the modulus operator. The number modulus evaluates to the integer remainder in this case, the right-most four digits. For example, %10000 results in Assign the result of this modulus operation to the variable that stores the five-digit number input.

31 Chapter 2 Introduction to C++ Programming 31 Lab Exercises Lab Exercise 3 Separating Digits Solution 5. Repeat this pattern of division and modulus reducing the divisor by a factor of 10 each time (i.e., 1000, 100, 10 ). After the number is changed to a four-digit number, divide/modulus by After the number is changed to a three-digit number, divide/modulus by 100. And so on. 6. Be sure to follow the spacing and indentation conventions mentioned in the text. 7. If you have any questions as you proceed, ask your lab instructor for assistance. 1 // Lab 3: digits.cpp 2 #include <iostream> // allows program to perform input and output 3 4 using std::cout; // program uses cout 5 using std::endl; // program uses endl 6 using std::cin; // program uses cin 7 8 int main() 9 { 10 int number; // integer read from user cout << "Enter a five-digit integer: " ; // prompt 13 cin >> number; // read integer from user cout << number / << " " ; 16 number = number % 10000; 17 cout << number / 1000 << " " ; 18 number = number % 1000; 19 cout << number / 100 << " " ; 20 number = number % 100; 21 cout << number / 10 << " " ; 22 number = number % 10 ; 23 cout << number << endl; return 0 ; // indicate successful termination } // end main Follow-Up Questions and Activities 1. What are the results of the following expressions? 24 / 5 = 4 18 % 3 = 0 13 % 9 = 4 13 / 2 % 2 = 0 2. What happens when the user inputs a number which has fewer than five digits? Why? What is the output when 1763 is entered? If the user inputs a number which has fewer than five digits, then the missing digits (the leftmost digits) are displayed as 0. This is because any number with fewer than five digits must be less than so dividing by will result in 0. Thus when 1763 is entered, the output is:

32 32 Introduction to C++ Programming Chapter 2 Lab Exercises Lab Exercise 3 Separating Digits 3. The program you completed in this lab exercise inputs a number with multiple digits and separates the digits. Write the inverse program, a program which asks the user for three one-digit numbers and combines them into a single three-digit number. [ Hint: Use multiplication and addition to form the three-digit number.] 1 // Lab 3: digits.cpp 2 #include <iostream> // allows program to perform input and output 3 4 using std::cout; // program uses cout 5 using std::endl; // program uses endl 6 using std::cin; // program uses cin 7 8 int main() 9 { 10 int number; // three-digit number 11 int digit1; // hundred's digit 12 int digit2; // ten's digit 13 int digit3; // one's digit cout << "Enter the hundred's digit: " ; // prompt 16 cin >> digit1; // read digit from user 17 cout << "Enter the ten's digit: " ; // prompt 18 cin >> digit2; // read digit from user 19 cout << "Enter the one's digit: " ; // prompt 20 cin >> digit3; // read digit from user number = digit3; // start with just the one's digit 23 number = number + digit2 * 10 ; // add the ten's digit * number = number + digit1 * 100; // add the hundred's digit * cout << number << endl; return 0 ; // indicate successful termination } // end main Enter the hundred s digit: 4 Enter the ten s digit: 2 Enter the one s digit: 7 427

33 Chapter 2 Introduction to C++ Programming 33 Lab Exercises Debugging Debugging Date: Section: The program in this section does not run properly. Fix all the syntax errors so that the program will compile successfully. Once the program compiles, compare the output with the sample output, and eliminate any logic errors that may exist. The sample output demonstrates what the program s output should be once the program s code has been corrected. debugging02.cpp (Fig. L 2.7) is available at and at Sample Output Enter two integers to compare: 5 2 5!= 2 5 > 2 5 >= 2 Enter two integers to compare: 2 7 2!= 7 2 < 7 2 <= 7 Enter two integers to compare: == 4 4 <= 4 4 >= 4 Broken Code 1 // Debugging 2 include <iostream> 3 4 using std::cout; 5 using std::endl; 6 using std::cin; 7 8 int main() 9 { int number1; 12 int number2; cout << "Enter two integers to compare: " ; 15 cout >> number1 >> number2; 16 Fig. L 2.7 debugging02.cpp. (Part 1 of 2.)

34 34 Introduction to C++ Programming Chapter 2 Lab Exercises Debugging 17 if ( number1 == number2 ) 18 cout << number1 << ' == ' << number2 << endl; if ( number1 <> number2 ) 21 cout << number1 << " <> " << number2 << endl; if ( number2 < number1 ) 24 cout << number1 << " < " << number2 << endl; if number1 > number2 ) 27 cout << number1 << " > " << number2 << endl; if ( number1 < number2 ) 30 cout << number1 << " <= " << number2 << endl; if ( number1 >= number2 ) 33 cout << number1 << " >= " << number2 << endl return 0; } // end main Fig. L 2.7 debugging02.cpp. (Part 2 of 2.) Debugging Solution 1 // Debugging 2 # include <iostream> 3 4 using std::cout; 5 using std::endl; 6 using std::cin; 7 8 int main() 9 { int number1; 12 int number2; cout << "Enter two integers to compare: " ; 15 cin >> number1 >> number2; if ( number1 == number2 ) 18 cout << number1 << " == " << number2 << endl; if ( number1!= number2 ) 21 cout << number1 << "!= " << number2 << endl; if ( number1 < number2 ) 24 cout << number1 << " < " << number2 << endl; if ( number1 > number2 ) 27 cout << number1 << " > " << number2 << endl; if ( number1 < = number2 ) 30 cout << number1 << " <= " << number2 << endl;

35 Chapter 2 Introduction to C++ Programming 35 Lab Exercises Debugging if ( number1 >= number2 ) 33 cout << number1 << " >= " << number2 << endl; return 0 ; } // end main Errors: Line 2: The program must #include the iostream header file. Line 15: Input from the keyboard requires the use of cin not cout. Line 18: A string literal must be enclosed with double-quotes ( " ); single-quotes ( ' ) can only be used for a single character literal. Lines 20 21: The inequality operator is!=, not <>. Line 23: number2 and number1 were switched in the less than conditional expression. Line 26: The left parentheses in the if condition was missing. Line 29: The < should be <= to match the cout statement on the next line. Line 33: Every statement must end with a semicolon.

36

37 Chapter 2 Introduction to C++ Programming 37 Postlab Activities Coding Exercises Date: Section: These coding exercises reinforce the lessons learned in the lab and provide additional programming experience outside the classroom and laboratory environment. They serve as a review after you have completed the Prelab Activities and Lab Exercises successfully. For each of the following problems, write a program or a program segment that performs the specified action. 1. Write the preprocessor directive which includes the iostream file in a program. Also write the appropriate using directives for cin, cout and endl. 1 #include <iostream> 2 3 using std::cin; 4 using std::cout; 5 using std::endl; 2. Define a main function which declares three integer variables. Remember to terminate the main function with a return statement. 1 #include <iostream> 2 3 using std::cin; 4 using std::cout; 5 using std::endl; 6 7 int main() 8 { 9 int number1; 10 int number2; 11 int number3; return 0 ; 14 } // end main function

38 38 Introduction to C++ Programming Chapter 2 Postlab Activities Coding Exercises 3. Write a single line of code that reads values into the three integer variables from Coding Exercise 2. 1 #include <iostream> 2 3 using std::cin; 4 using std::cout; 5 using std::endl; 6 7 int main() 8 { 9 int number1; 10 int number2; 11 int number3; cin >> number1 >> number2 >> number3; return 0 ; 16 } // end main function 4. Write a line of code that prints all three integer values from Coding Exercise 3 separated by hyphens, -. 1 #include <iostream> 2 3 using std::cin; 4 using std::cout; 5 using std::endl; 6 7 int main() 8 { 9 int number1; 10 int number2; 11 int number3; cin >> number1 >> number2 >> number3; cout << number1 << "-" << number2 << "-" << number3 << endl; return 0 ; 18 } // end main function

39 Chapter 2 Introduction to C++ Programming 39 Postlab Activities Coding Exercises 5. Modify your solution to Coding Exercise 4 to write a C++ program that determines which variable s value is the largest. Use variable largest to store the largest value. 1 #include <iostream> 2 3 using std::cin; 4 using std::cout; 5 using std::endl; 6 7 int main() 8 { 9 int number1; 10 int number2; 11 int number3; cin >> number1 >> number2 >> number3; cout << number1 << "-" << number2 << "-" << number3 << endl; int largest; largest = number1; if ( number2 > largest ) 22 largest = number2; if ( number3 > largest ) 25 largest = number3; return 0 ; 28 } // end main function 6. Modify your solution to Coding Exercise 5 to write a C++ program that determines which integer variable s value is the smallest. Use variable smallest to store the smallest value. 1 #include <iostream> 2 3 using std::cin; 4 using std::cout; 5 using std::endl; 6 7 int main() 8 { 9 int number1; 10 int number2; 11 int number3; cin >> number1 >> number2 >> number3; cout << number1 << "-" << number2 << "-" << number3 << endl; int largest; largest = number1; 20

40 40 Introduction to C++ Programming Chapter 2 Postlab Activities Coding Exercises 21 if ( number2 > largest ) 22 largest = number2; if ( number3 > largest ) 25 largest = number3; int smallest; smallest = number1; if ( number2 < smallest ) 32 smallest = number2; if ( number3 < smallest ) 35 smallest = number3; return 0 ; 38 } // end main function 7. Modify your solution to Coding Exercise 6 to test if any of the variable s values are equal and if so print that they are equal. For example, if two variables have the same value, 5, print 5and 5are equal. 1 #include <iostream> 2 3 using std::cin; 4 using std::cout; 5 using std::endl; 6 7 int main() 8 { 9 int number1; 10 int number2; 11 int number3; cin >> number1 >> number2 >> number3; cout << number1 << "-" << number2 << "-" << number3 << endl; int largest; largest = number1; 20 if ( number2 > largest ) 21 largest = number2; 22 if ( number3 > largest ) 23 largest = number3; int smallest; smallest = number1; 28

41 Chapter 2 Introduction to C++ Programming 41 Postlab Activities Coding Exercises 29 if ( number2 < smallest ) 30 smallest = number2; if ( number3 < smallest ) 33 smallest = number3; if ( number1 == number2 ) 36 cout << number1 << " and " << number2 << " are equal." << endl; if ( number1 == number3 ) 39 cout << number1 << " and " << number3 << " are equal." << endl; if ( number2 == number3 ) 42 cout << number2 << " and " << number3 << " are equal." << endl; return 0 ; 45 } // end main function

42

43 Chapter 2 Introduction to C++ Programming 43 Postlab Activities Programming Challenges Programming Challenges Date: Section: The Programming Challenges are more involved than the Coding Exercises and may require a significant amount of time to complete. Write a C++ program for each of the problems in this section. The answers to these problems are available at and Pseudocode, hints and/or sample outputs are provided to aid you in your programming. 1. Write a program that prints the numbers 1 to 4 on the same line with each pair of adjacent numbers separated by one space. Write the program using the following methods: Hints: a) Using one output statement with one stream-insertion operator. b) Using one output statement with four stream-insertion operators. c) Using four output statements. Use comments to separate your program into three clearly marked sections, one for each part (i.e., a c) of the problem. For Part a) the entire output should be contained within one string. Use either endl or "\n" after each part to separate their output. Your output should look like: Solution 1 // Programming Challenge 1: threeoutputs.cpp 2 #include <iostream> 3 4 using std::cin; 5 using std::cout; 6 using std::endl; 7 8 int main() 9 { 10 // part a - one output statement with one stream-insertion operator 11 cout << " \n"; // part b - one output statement with four stream-insertion operators 14 cout << "1 " << "2 " << "3 " << "4\n"; 15

44 44 Introduction to C++ Programming Chapter 2 Postlab Activities Programming Challenges 16 // part c - four output statememts 17 cout << "1 " ; 18 cout << "2 " ; 19 cout << "3 " ; 20 cout << "4\n"; return 0 ; 23 } // end main function 2. Write a program that asks the user to enter two integers, obtains the numbers from the user, then prints the larger number followed by the words is larger. If the numbers are equal, print the message These numbers are equal. Hints: The user should input both integers at once, i.e., cin >> x >> y; Remember to print spaces after printing integers to the screen. A typical run of your program might look as follows: Enter two integers: is larger. Solution 1 // Programming Challenge 2: larger.cpp 2 #include <iostream> 3 4 using std::cin; 5 using std::cout; 6 using std::endl; 7 8 int main() 9 { 10 int number1; // first input 11 int number2; // second input cout << "Enter two integers: " ; // prompt 14 cin >> number1 >> number2; // enter integers if ( number1 > number2 ) // is number1 larger? 17 cout << number1 << " is larger." << endl; if ( number2 > number1 ) // is number2 larger? 20 cout << number2 << " is larger." << endl; if ( number1 == number2 ) // are they equal? 23 cout << "These numbers are equal." << endl; return 0 ; 26 } // end main function

45 Chapter 2 Introduction to C++ Programming 45 Postlab Activities Programming Challenges 3. Write a program that reads in five integers and determines and prints the largest and the smallest integers in the group. Use only the programming techniques you learned in Chapter 2 of C++ How to Program: Fifth Edition. Hints: This program requires seven variables: five for user input and two to store the largest and the smallest, respectively. As soon as the user inputs the values, assign the largest and smallest variables the value of the first input. If instead, largest was initially assigned to zero, this would be a logic error because negative numbers could be input by the user. Ten separate if statements are required to compare each input to largest and smallest. A typical run of your program might look as follows: Enter five integers: Largest integer: 10 Smallest integer: -4 Solution 1 // Programming Challenge 3: fiveintegers.cpp 2 #include <iostream> 3 4 using std::cin; 5 using std::cout; 6 using std::endl; 7 8 int main() 9 { 10 int number1; // first input 11 int number2; // second input 12 int number3; // third input 13 int number4; // fourth input 14 int number5; // fifth input 15 int largest; // the largest integer 16 int smallest; // the smallest integer cout << "Enter five integers: " ; // prompt 19 cin >> number1 >> number2 >> number3 >> number4 >> number5; // read integers largest = number1; // first assume that number1 is the largest 22 smallest = number1; // first assume that number1 is the smallest if ( number2 > largest ) // is number2 larger? 25 largest = number2; if ( number2 < smallest ) // is number2 smaller? 28 smallest = number2; if ( number3 > largest ) // is number3 larger? 31 largest = number3; 32

46 46 Introduction to C++ Programming Chapter 2 Postlab Activities Programming Challenges 33 if ( number3 < smallest ) // is number3 smaller? 34 smallest = number3; if ( number4 > largest ) // is number4 larger? 37 largest = number4; if ( number4 < smallest ) // is number4 smaller? 40 smallest = number4; if ( number5 > largest ) // is number5 larger? 43 largest = number5; if ( number5 < smallest ) // is number5 smaller? 46 smallest = number5; cout << "Largest integer: " << largest << endl; 49 cout << "Smallest integer: " << smallest << endl; return 0 ; 52 } // end main function

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

Chapter One Introduction to Programming

Chapter One Introduction to Programming Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of

More information

JavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved.

JavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved. 1 6 JavaScript: Introduction to Scripting 2 Comment is free, but facts are sacred. C. P. Scott The creditor hath a better memory than the debtor. James Howell When faced with a decision, I always ask,

More information

Computer Programming C++ Classes and Objects 15 th Lecture

Computer Programming C++ Classes and Objects 15 th Lecture Computer Programming C++ Classes and Objects 15 th Lecture 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University Copyrights 2013 Eom, Hyeonsang All Rights Reserved Outline

More information

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be... What is a Loop? CSC Intermediate Programming Looping A loop is a repetition control structure It causes a single statement or a group of statements to be executed repeatedly It uses a condition to control

More information

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 3: Input/Output

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 3: Input/Output C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 3: Input/Output Objectives In this chapter, you will: Learn what a stream is and examine input and output streams Explore

More information

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved. 1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays

More information

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements 9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending

More information

Appendix K Introduction to Microsoft Visual C++ 6.0

Appendix K Introduction to Microsoft Visual C++ 6.0 Appendix K Introduction to Microsoft Visual C++ 6.0 This appendix serves as a quick reference for performing the following operations using the Microsoft Visual C++ integrated development environment (IDE):

More information

C++ Language Tutorial

C++ Language Tutorial cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain

More information

Chapter 2: Elements of Java

Chapter 2: Elements of Java Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction

More information

Passing 1D arrays to functions.

Passing 1D arrays to functions. Passing 1D arrays to functions. In C++ arrays can only be reference parameters. It is not possible to pass an array by value. Therefore, the ampersand (&) is omitted. What is actually passed to the function,

More information

if and if-else: Part 1

if and if-else: Part 1 if and if-else: Part 1 Objectives Write if statements (including blocks) Write if-else statements (including blocks) Write nested if-else statements We will now talk about writing statements that make

More information

MS Visual C++ Introduction. Quick Introduction. A1 Visual C++

MS Visual C++ Introduction. Quick Introduction. A1 Visual C++ MS Visual C++ Introduction 1 Quick Introduction The following pages provide a quick tutorial on using Microsoft Visual C++ 6.0 to produce a small project. There should be no major differences if you are

More information

JavaScript: Control Statements I

JavaScript: Control Statements I 1 7 JavaScript: Control Statements I 7.1 Introduction 2 The techniques you will learn here are applicable to most high-level languages, including JavaScript 1 7.2 Algorithms 3 Any computable problem can

More information

Basics of I/O Streams and File I/O

Basics of I/O Streams and File I/O Basics of This is like a cheat sheet for file I/O in C++. It summarizes the steps you must take to do basic I/O to and from files, with only a tiny bit of explanation. It is not a replacement for reading

More information

VB.NET Programming Fundamentals

VB.NET Programming Fundamentals Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements

More information

F ahrenheit = 9 Celsius + 32

F ahrenheit = 9 Celsius + 32 Problem 1 Write a complete C++ program that does the following. 1. It asks the user to enter a temperature in degrees celsius. 2. If the temperature is greater than 40, the program should once ask the

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

More information

Sequential Program Execution

Sequential Program Execution Sequential Program Execution Quick Start Compile step once always g++ -o Realtor1 Realtor1.cpp mkdir labs cd labs Execute step mkdir 1 Realtor1 cd 1 cp../0/realtor.cpp Realtor1.cpp Submit step cp /samples/csc/155/labs/1/*.

More information

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void 1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of

More information

Moving from C++ to VBA

Moving from C++ to VBA Introduction College of Engineering and Computer Science Mechanical Engineering Department Mechanical Engineering 309 Numerical Analysis of Engineering Systems Fall 2014 Number: 15237 Instructor: Larry

More information

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language Simple C++ Programs Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input and Output Basic Functions from

More information

Conditions & Boolean Expressions

Conditions & Boolean Expressions Conditions & Boolean Expressions 1 In C++, in order to ask a question, a program makes an assertion which is evaluated to either true (nonzero) or false (zero) by the computer at run time. Example: In

More information

C++ Input/Output: Streams

C++ Input/Output: Streams C++ Input/Output: Streams 1 The basic data type for I/O in C++ is the stream. C++ incorporates a complex hierarchy of stream types. The most basic stream types are the standard input/output streams: istream

More information

6. Control Structures

6. Control Structures - 35 - Control Structures: 6. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose,

More information

Common Beginner C++ Programming Mistakes

Common Beginner C++ Programming Mistakes Common Beginner C++ Programming Mistakes This documents some common C++ mistakes that beginning programmers make. These errors are two types: Syntax errors these are detected at compile time and you won't

More information

1 Description of The Simpletron

1 Description of The Simpletron Simulating The Simpletron Computer 50 points 1 Description of The Simpletron In this assignment you will write a program to simulate a fictional computer that we will call the Simpletron. As its name implies

More information

Chapter 8 Selection 8-1

Chapter 8 Selection 8-1 Chapter 8 Selection 8-1 Selection (Decision) The second control logic structure is selection: Selection Choosing between two or more alternative actions. Selection statements alter the sequential flow

More information

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures The C++ Language Loops Loops! Recall that a loop is another of the four basic programming language structures Repeat statements until some condition is false. Condition False True Statement1 2 1 Loops

More information

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement? 1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members

More information

.NET Standard DateTime Format Strings

.NET Standard DateTime Format Strings .NET Standard DateTime Format Strings Specifier Name Description d Short date pattern Represents a custom DateTime format string defined by the current ShortDatePattern property. D Long date pattern Represents

More information

UEE1302 (1102) F10 Introduction to Computers and Programming

UEE1302 (1102) F10 Introduction to Computers and Programming Computational Intelligence on Automation Lab @ NCTU UEE1302 (1102) F10 Introduction to Computers and Programming Programming Lecture 03 Flow of Control (Part II): Repetition while,for & do..while Learning

More information

Member Functions of the istream Class

Member Functions of the istream Class Member Functions of the istream Class The extraction operator is of limited use because it always uses whitespace to delimit its reads of the input stream. It cannot be used to read those whitespace characters,

More information

Visual Logic Instructions and Assignments

Visual Logic Instructions and Assignments Visual Logic Instructions and Assignments Visual Logic can be installed from the CD that accompanies our textbook. It is a nifty tool for creating program flowcharts, but that is only half of the story.

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]

More information

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall-2015 1

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall-2015 1 QUIZ-II Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the numbers, the operator, and the result. (For

More information

Java Basics: Data Types, Variables, and Loops

Java Basics: Data Types, Variables, and Loops Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables

More information

Formatting Numbers with C++ Output Streams

Formatting Numbers with C++ Output Streams Formatting Numbers with C++ Output Streams David Kieras, EECS Dept., Univ. of Michigan Revised for EECS 381, Winter 2004. Using the output operator with C++ streams is generally easy as pie, with the only

More information

Deitel Dive-Into Series: Dive Into Microsoft Visual C++ 6

Deitel Dive-Into Series: Dive Into Microsoft Visual C++ 6 1 Deitel Dive-Into Series: Dive Into Microsoft Visual C++ 6 Objectives To understand the relationship between C++ and Visual C++. To be able to use Visual C++ to create, compile and execute C++ console

More information

13 Classes & Objects with Constructors/Destructors

13 Classes & Objects with Constructors/Destructors 13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.

More information

Variables, Constants, and Data Types

Variables, Constants, and Data Types Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class: L&L, 2.1-2.3, App C 1 Primitive Data There are eight

More information

An Introduction to Number Theory Prime Numbers and Their Applications.

An Introduction to Number Theory Prime Numbers and Their Applications. East Tennessee State University Digital Commons @ East Tennessee State University Electronic Theses and Dissertations 8-2006 An Introduction to Number Theory Prime Numbers and Their Applications. Crystal

More information

7.7 Case Study: Calculating Depreciation

7.7 Case Study: Calculating Depreciation 7.7 Case Study: Calculating Depreciation 1 7.7 Case Study: Calculating Depreciation PROBLEM Depreciation is a decrease in the value over time of some asset due to wear and tear, decay, declining price,

More information

Chapter 3. Input and output. 3.1 The System class

Chapter 3. Input and output. 3.1 The System class Chapter 3 Input and output The programs we ve looked at so far just display messages, which doesn t involve a lot of real computation. This chapter will show you how to read input from the keyboard, use

More information

CISC 181 Project 3 Designing Classes for Bank Accounts

CISC 181 Project 3 Designing Classes for Bank Accounts CISC 181 Project 3 Designing Classes for Bank Accounts Code Due: On or before 12 Midnight, Monday, Dec 8; hardcopy due at beginning of lecture, Tues, Dec 9 What You Need to Know This project is based on

More information

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share. LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.

More information

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More information

Introduction to Visual C++.NET Programming. Using.NET Environment

Introduction to Visual C++.NET Programming. Using.NET Environment ECE 114-2 Introduction to Visual C++.NET Programming Dr. Z. Aliyazicioglu Cal Poly Pomona Electrical & Computer Engineering Cal Poly Pomona Electrical & Computer Engineering 1 Using.NET Environment Start

More information

Appendix M: Introduction to Microsoft Visual C++ 2010 Express Edition

Appendix M: Introduction to Microsoft Visual C++ 2010 Express Edition Appendix M: Introduction to Microsoft Visual C++ 2010 Express Edition This book may be ordered from Addison-Wesley in a value pack that includes Microsoft Visual C++ 2010 Express Edition. Visual C++ 2010

More information

MULTIPLICATION AND DIVISION OF REAL NUMBERS In this section we will complete the study of the four basic operations with real numbers.

MULTIPLICATION AND DIVISION OF REAL NUMBERS In this section we will complete the study of the four basic operations with real numbers. 1.4 Multiplication and (1-25) 25 In this section Multiplication of Real Numbers Division by Zero helpful hint The product of two numbers with like signs is positive, but the product of three numbers with

More information

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand: Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of

More information

Lecture 2 Notes: Flow of Control

Lecture 2 Notes: Flow of Control 6.096 Introduction to C++ January, 2011 Massachusetts Institute of Technology John Marrero Lecture 2 Notes: Flow of Control 1 Motivation Normally, a program executes statements from first to last. The

More information

Lecture 1 Introduction to Java

Lecture 1 Introduction to Java Programming Languages: Java Lecture 1 Introduction to Java Instructor: Omer Boyaci 1 2 Course Information History of Java Introduction First Program in Java: Printing a Line of Text Modifying Our First

More information

C++ Outline. cout << "Enter two integers: "; int x, y; cin >> x >> y; cout << "The sum is: " << x + y << \n ;

C++ Outline. cout << Enter two integers: ; int x, y; cin >> x >> y; cout << The sum is:  << x + y << \n ; C++ Outline Notes taken from: - Drake, Caleb. EECS 370 Course Notes, University of Illinois Chicago, Spring 97. Chapters 9, 10, 11, 13.1 & 13.2 - Horstman, Cay S. Mastering Object-Oriented Design in C++.

More information

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T) Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating

More information

While Loop. 6. Iteration

While Loop. 6. Iteration While Loop 1 Loop - a control structure that causes a set of statements to be executed repeatedly, (reiterated). While statement - most versatile type of loop in C++ false while boolean expression true

More information

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit Decimal Division Remember 4th grade long division? 43 // quotient 12 521 // divisor dividend -480 41-36 5 // remainder Shift divisor left (multiply by 10) until MSB lines up with dividend s Repeat until

More information

1. The First Visual C++ Program

1. The First Visual C++ Program 1. The First Visual C++ Program Application and name it as HelloWorld, and unselect the Create directory for solution. Press [OK] button to confirm. 2. Select Application Setting in the Win32 Application

More information

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority) Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

More information

Comp151. Definitions & Declarations

Comp151. Definitions & Declarations Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const

More information

Some Scanner Class Methods

Some Scanner Class Methods Keyboard Input Scanner, Documentation, Style Java 5.0 has reasonable facilities for handling keyboard input. These facilities are provided by the Scanner class in the java.util package. A package is a

More information

Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++)

Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++) Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++) (Revised from http://msdn.microsoft.com/en-us/library/bb384842.aspx) * Keep this information to

More information

PREPARATION FOR MATH TESTING at CityLab Academy

PREPARATION FOR MATH TESTING at CityLab Academy PREPARATION FOR MATH TESTING at CityLab Academy compiled by Gloria Vachino, M.S. Refresh your math skills with a MATH REVIEW and find out if you are ready for the math entrance test by taking a PRE-TEST

More information

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC Introduction to Programming (in C++) Loops Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC Example Assume the following specification: Input: read a number N > 0 Output:

More information

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification: Example Introduction to Programming (in C++) Loops Assume the following specification: Input: read a number N > 0 Output: write the sequence 1 2 3 N (one number per line) Jordi Cortadella, Ricard Gavaldà,

More information

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0 VISUAL GUIDE to RX Scripting for Roulette Xtreme - System Designer 2.0 UX Software - 2009 TABLE OF CONTENTS INTRODUCTION... ii What is this book about?... iii How to use this book... iii Time to start...

More information

ALGORITHMS AND FLOWCHARTS

ALGORITHMS AND FLOWCHARTS ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe solution of problem this sequence of steps

More information

Math Workshop October 2010 Fractions and Repeating Decimals

Math Workshop October 2010 Fractions and Repeating Decimals Math Workshop October 2010 Fractions and Repeating Decimals This evening we will investigate the patterns that arise when converting fractions to decimals. As an example of what we will be looking at,

More information

Visual Studio 2008 Express Editions

Visual Studio 2008 Express Editions Visual Studio 2008 Express Editions Visual Studio 2008 Installation Instructions Burning a Visual Studio 2008 Express Editions DVD Download (http://www.microsoft.com/express/download/) the Visual Studio

More information

Chapter 5. Selection 5-1

Chapter 5. Selection 5-1 Chapter 5 Selection 5-1 Selection (Decision) The second control logic structure is selection: Selection Choosing between two or more alternative actions. Selection statements alter the sequential flow

More information

PIC 10A. Lecture 7: Graphics II and intro to the if statement

PIC 10A. Lecture 7: Graphics II and intro to the if statement PIC 10A Lecture 7: Graphics II and intro to the if statement Setting up a coordinate system By default the viewing window has a coordinate system already set up for you 10-10 10-10 The origin is in the

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

Creating a Simple Visual C++ Program

Creating a Simple Visual C++ Program CPS 150 Lab 1 Name Logging in: Creating a Simple Visual C++ Program 1. Once you have signed for a CPS computer account, use the login ID and the password password (lower case) to log in to the system.

More information

We can express this in decimal notation (in contrast to the underline notation we have been using) as follows: 9081 + 900b + 90c = 9001 + 100c + 10b

We can express this in decimal notation (in contrast to the underline notation we have been using) as follows: 9081 + 900b + 90c = 9001 + 100c + 10b In this session, we ll learn how to solve problems related to place value. This is one of the fundamental concepts in arithmetic, something every elementary and middle school mathematics teacher should

More information

Decimal form. Fw.d Exponential form Ew.d Ew.dEe Scientific form ESw.d ESw.dEe Engineering form ENw.d ENw.dEe Lw. Horizontal

Decimal form. Fw.d Exponential form Ew.d Ew.dEe Scientific form ESw.d ESw.dEe Engineering form ENw.d ENw.dEe Lw. Horizontal Fortran Formats The tedious part of using Fortran format is to master many format edit descriptors. Each edit descriptor tells the system how to handle certain type of values or activity. Each value requires

More information

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2 Unix Shell Scripts Norman Matloff July 30, 2008 Contents 1 Introduction 1 2 Invoking Shell Scripts 2 2.1 Direct Interpretation....................................... 2 2.2 Indirect Interpretation......................................

More information

Answers to Review Questions Chapter 7

Answers to Review Questions Chapter 7 Answers to Review Questions Chapter 7 1. The size declarator is used in a definition of an array to indicate the number of elements the array will have. A subscript is used to access a specific element

More information

Accentuate the Negative: Homework Examples from ACE

Accentuate the Negative: Homework Examples from ACE Accentuate the Negative: Homework Examples from ACE Investigation 1: Extending the Number System, ACE #6, 7, 12-15, 47, 49-52 Investigation 2: Adding and Subtracting Rational Numbers, ACE 18-22, 38(a),

More information

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

SQL - QUICK GUIDE. Allows users to access data in relational database management systems. http://www.tutorialspoint.com/sql/sql-quick-guide.htm SQL - QUICK GUIDE Copyright tutorialspoint.com What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating

More information

Ch 7-1. Object-Oriented Programming and Classes

Ch 7-1. Object-Oriented Programming and Classes 2014-1 Ch 7-1. Object-Oriented Programming and Classes May 10, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497;

More information

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Objectives After completing this lesson, you should be able to do the following: List the capabilities of SQL SELECT statements Execute a basic SELECT statement

More information

Chapter 14: Boolean Expressions Bradley Kjell (Revised 10/08/08)

Chapter 14: Boolean Expressions Bradley Kjell (Revised 10/08/08) Chapter 14: Boolean Expressions Bradley Kjell (Revised 10/08/08) The if statements of the previous chapters ask simple questions such as count

More information

PL / SQL Basics. Chapter 3

PL / SQL Basics. Chapter 3 PL / SQL Basics Chapter 3 PL / SQL Basics PL / SQL block Lexical units Variable declarations PL / SQL types Expressions and operators PL / SQL control structures PL / SQL style guide 2 PL / SQL Block Basic

More information

In this Chapter you ll learn:

In this Chapter you ll learn: Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then stop. Lewis

More information

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c Lecture 3 Data structures arrays structs C strings: array of chars Arrays as parameters to functions Multiple subscripted arrays Structs as parameters to functions Default arguments Inline functions Redirection

More information

I PUC - Computer Science. Practical s Syllabus. Contents

I PUC - Computer Science. Practical s Syllabus. Contents I PUC - Computer Science Practical s Syllabus Contents Topics 1 Overview Of a Computer 1.1 Introduction 1.2 Functional Components of a computer (Working of each unit) 1.3 Evolution Of Computers 1.4 Generations

More information

Introduction to Python

Introduction to Python WEEK ONE Introduction to Python Python is such a simple language to learn that we can throw away the manual and start with an example. Traditionally, the first program to write in any programming language

More information

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012 Binary numbers The reason humans represent numbers using decimal (the ten digits from 0,1,... 9) is that we have ten fingers. There is no other reason than that. There is nothing special otherwise about

More information

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro, to your M: drive. To do the second part of the prelab, you will need to have available a database from that folder. Creating a new

More information

William Paterson University Department of Computer Science. Microsoft Visual C++.NET Tutorial Spring 2006 Release 1.0

William Paterson University Department of Computer Science. Microsoft Visual C++.NET Tutorial Spring 2006 Release 1.0 William Paterson University Department of Computer Science Microsoft Visual C++.NET Tutorial Spring 2006 Release 1.0 Microsoft Visual C++.NET Tutorial Spring 2006 Release 1.0 I. Introduction This tutorial

More information

CS 1133, LAB 2: FUNCTIONS AND TESTING http://www.cs.cornell.edu/courses/cs1133/2015fa/labs/lab02.pdf

CS 1133, LAB 2: FUNCTIONS AND TESTING http://www.cs.cornell.edu/courses/cs1133/2015fa/labs/lab02.pdf CS 1133, LAB 2: FUNCTIONS AND TESTING http://www.cs.cornell.edu/courses/cs1133/2015fa/labs/lab02.pdf First Name: Last Name: NetID: The purpose of this lab is to help you to better understand functions:

More information

Arithmetic in MIPS. Objectives. Instruction. Integer arithmetic. After completing this lab you will:

Arithmetic in MIPS. Objectives. Instruction. Integer arithmetic. After completing this lab you will: 6 Objectives After completing this lab you will: know how to do integer arithmetic in MIPS know how to do floating point arithmetic in MIPS know about conversion from integer to floating point and from

More information

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals: Numeral Systems Which number is larger? 25 8 We need to distinguish between numbers and the symbols that represent them, called numerals. The number 25 is larger than 8, but the numeral 8 above is larger

More information

Example of a Java program

Example of a Java program Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);

More information

Curriculum Map. Discipline: Computer Science Course: C++

Curriculum Map. Discipline: Computer Science Course: C++ Curriculum Map Discipline: Computer Science Course: C++ August/September: How can computer programs make problem solving easier and more efficient? In what order does a computer execute the lines of code

More information

An Incomplete C++ Primer. University of Wyoming MA 5310

An Incomplete C++ Primer. University of Wyoming MA 5310 An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages

More information

Q&As: Microsoft Excel 2013: Chapter 2

Q&As: Microsoft Excel 2013: Chapter 2 Q&As: Microsoft Excel 2013: Chapter 2 In Step 5, why did the date that was entered change from 4/5/10 to 4/5/2010? When Excel recognizes that you entered a date in mm/dd/yy format, it automatically formats

More information

Arrays. number: Motivation. Prof. Stewart Weiss. Software Design Lecture Notes Arrays

Arrays. number: Motivation. Prof. Stewart Weiss. Software Design Lecture Notes Arrays Motivation Suppose that we want a program that can read in a list of numbers and sort that list, or nd the largest value in that list. To be concrete about it, suppose we have 15 numbers to read in from

More information