Answers to Selected Exercises

Size: px
Start display at page:

Download "Answers to Selected Exercises"

Transcription

1 DalePhatANS_complete 8/18/04 10:30 AM Page 1049 Answers to Selected Exercises Chapter 1 Exam Preparation Exercises 1. a. v, b. i, c. viii, d. iii, e. iv, f. vii, g. vi, h. ii. 2. Analysis and specification, general solution (algorithm), verify. 3. Concrete solution (program), test. 4. The analysis and specification step within the problem-solving phase. 5. The steps never end. Changing the last step to say, Repeat from first step until graduation, converts the sequence into an algorithm that eventually ends, assuming the person will graduate from school some day. We can make sure that this loop ends by specifying a condition that will definitely occur. For example, Repeat from first step until last day of classes. 6. a. vi, b. ii, c. v, d. i, e. vii, f. iv. 7. The program can be compiled on different computer systems without modification. 8. The control unit directs the actions of the other components in the computer to execute program instruction in the proper order. 9. False. The editor is software rather than hardware. 10. False. Peripheral devices are external to the CPU and its main memory. 11. Yes. If the software license restricts use to a single computer or a single user, then this is a case of piracy, even though you split the cost. 12. a. ii, b. v, c. iii, d. vii, e. i, f. vi, g. iv. Chapter 1 Programming Warm-Up Exercises 1. Branches: Steps n1, n2, and n3. There are two loops: steps p, q, and r; and steps t and u. Steps a, c, and e are references to subalgorithms defined elsewhere.

2 DalePhatANS_complete 8/18/04 10:30 AM Page Answers to Selected Exercises 2. follow separate algorithm for filling glass with water and placing on counter If right-handed, pick up toothpaste tube in left hand and unscrew cap by turning counter-clockwise place toothpaste cap on counter transfer toothpaste tube to right hand and pick up toothbrush in left hand, holding it by its handle place open end of toothpaste tube against tips of brush bristles and squeeze toothpaste tube just enough to create a 0.5-inch-long extrusion of toothpaste on brush pull toothpaste tube away from brush and place tube on counter transfer toothbrush to right hand, holding it by its handle open mouth and insert brush, placing toothpaste-covered bristles against one tooth scrub tooth with brush by moving brush up and down 10 times reposition brush to an unscrubbed tooth repeat previous two steps until all teeth have been brushed spit toothpaste into sink put toothbrush in sink pick up glass in right hand fill mouth with water from glass swish water in mouth for five seconds spit water from mouth into sink repeat previous three steps three times Otherwise (if left-handed) pick up toothpaste tube in right hand and unscrew cap by turning counter-clockwise place toothpaste cap on counter transfer toothpaste tube to left hand and pick up toothbrush in right hand, holding it by its handle place open end of toothpaste tube against tips of brush bristles and squeeze toothpaste tube just enough to create a 0.5-inch-long extrusion of toothpaste on brush pull toothpaste tube away from brush and place tube on counter transfer toothbrush to left hand, holding it by its handle open mouth and insert brush, placing toothpaste-covered bristles against one tooth scrub tooth with brush by moving brush up and down 10 times reposition brush to an unscrubbed tooth repeat previous two steps until all teeth have been brushed spit toothpaste into sink put toothbrush in sink pick up glass in left hand fill mouth with water from glass swish water in mouth for five seconds spit water from mouth into sink repeat previous three steps three times Place glass on counter Follow separate algorithm for cleaning up after brushing teeth

3 DalePhatANS_complete 8/18/04 10:30 AM Page 1051 Answers to Selected Exercises The test for right- or left-handedness is a branch. Each branch contains two loops, one that iterates until all teeth are brushed and another that iterates rinsing four times. The first and last steps refer to separately defined subalgorithms. 4. Change step u to: u. Repeat step t nine times. Chapter 1 Case Study Follow-Up Exercises 1. a No b Yes c Yes d No 2. a Line = 6 b Line = 2 c Line = 7 d Line = 4 e Line = 4 3. Divide by 1000 and see if the remainder is I was not, but your answer may be different. 5. Keep adding 1 to the year and test it until you find the next leap year. Another algorithm would be to use the following: nextyear = year + (year % 4) divide the nextyear by 100 and if the remainder isn t 0, Write that nextyear is the next leap year Otherwise, divide the nextyear by 400 and if the remainder isn t 0 Write that (nextyear + 4) is the next leap year Otherwise nextyear is the next leap year 6. Line Number 1 if (year % 4!= 0) 2 return false; 3 else if (year % 100!= 0) 4 return true; 5 else if (year % 400!= 0) 6 return false; 7 else return true; Chapter 2 Exam Preparation Exercises 1. a. valid, b. invalid (hyphens not allowed), c. invalid (reserved words not allowed), d. valid, e. valid, f. valid, g. invalid (must begin with a letter), h. invalid (# is not allowed). 2. a. vi, b. ix, c. iv, d. v, e. vii, f. ii, g. i, h. x, i. iii, j. viii. 3. False.

4 DalePhatANS_complete 8/18/04 10:30 AM Page Answers to Selected Exercises 4. The template allows an identifier to begin with a digit. Identifiers can begin with a letter or an underscore, and digits may appear only in the second character position and beyond. 5. False. 6. True. 7. True. 8. Note that the second line concatenates two words without a separating space. Four score and seven years agoour fathers brought forth on this continent a new nation Bjarne Stroustrup named his new programming language C++ because it is a successor to the C programming language. 10. By preceding it with a backslash character (\ ). 11. If we forget the */ at the end of a comment, then any number of lines of program code can be inadvertently included in the comment. The // form avoids this by automatically terminating at the end of the line. 12. The // form of comment cannot span more than one line. It also cannot be inserted into the middle of a line of code because everything to the right of // becomes a comment. 13. << is the stream insertion operator, and is pronounced put to or is sent, as in cout is sent string No. The endl identifier is a manipulator, and is not a string value. 15. It tells the C++ preprocessor to insert the contents of a specified file at that point in the code. 16. std::cout << "Hello everybody!" << std::endl; 17. A block. 18. By splitting it into pieces that fit on a line, and joining them with the concatenation operator. 19. #include <iostream> #include <string> using namespace std; const string TITLE = "Dr."; int main() cout << "Hello " + TITLE + " Stroustrup!"; Chapter 2 Programming Warm-Up Exercises 1. Substitute the actual data in the following: cout << "July 4, 2004" << endl;

5 DalePhatANS_complete 8/18/04 10:30 AM Page 1053 Answers to Selected Exercises Note that the \" escape sequence is needed in six places here: cout << "He said, \"How is that possible?\"" << endl << "She replied, \"Using manipulators.\"" << endl << "\"Of course,\" he exclaimed!" << endl; 3. a. const string ANSWER = "True"; b. char middleinitial; c. string coursetitle; d. const char PERCENT = '%' 4. const string FIRST = "Your first name inserted here"; const string LAST = "Your last name inserted here"; // Insert your middle initial in place of A: const char MIDDLE = 'A'; 5. cout << PART1 << PART2 << PART1 << PART3; 6. PART1 + PART2 + PART1 + PART3 7. cout << "Yet the web of thought has no such creases" << endl; cout << "And is more like a weaver's masterpieces;" << endl; cout << "One step a thousand threads arise," << endl; cout << "Hither and thither shoots each shuttle," << endl; cout << "The threads flow on unseen and subtle," << endl; cout << "Each blow effects a thousand ties." << endl; 8. #include <iostream> #include <string> using namespace std; const string TITLE = "Rev."; const char FIRST = 'H'; const char MID 'G'; const char DOT = '.'; int main() cout << TITLE << FIRST << DOT << MID << DOT << " Jones"; 9. The solution to this problem is for the student to show that he or she has run the program correctly. It should output: *********************************** * * * Welcome to C++ Programming! * * * ***********************************

6 DalePhatANS_complete 8/18/04 10:30 AM Page Answers to Selected Exercises Chapter 2 Case Study Follow-Up 1. const string BLACK = "%%%%%%%%"; // Define a line of a black square 2. const string WHITE = "..."; // Define a line of a white square 3. Move the first five output statements to the end of the program. 4. const string BLACK = "**********"; // Define a line of a black square const string WHITE = " "; // Define a line of a white square 5. // Chessboard program // This program prints a chessboard pattern that is built up from // basic strings of white and black characters. #include <iostream> #include <string> using namespace std; const string BLACK = "********"; // Define a line of a black square const string WHITE = " "; // Define a line of a white square const string BLACK_BLANK = "** **"; // Define a constant of embedded // blanks int main () string whiterow; // A row beginning with a white square string blackrow; // A row beginning with a black square string blackblankrow; // A black first row with mixed squares string whiteblankrow; // A white first row with mixed squares // Create a white-black row by concatenating the basic strings whiterow = WHITE + BLACK + WHITE + BLACK + WHITE + BLACK + WHITE + BLACK; // Create a white-black row with interior blanks in the blacks whiteblankrow = WHITE + BLACK_BLANK + WHITE + BLACK_BLANK + WHITE + BLACK_BLANK + WHITE + BLACK_BLANK; // Create a black-white row with interior blanks in the blacks blackblankrow = BLACK_BLANK + WHITE + BLACK_BLANK + WHITE + BLACK_BLANK + WHITE + BLACK_BLANK + WHITE;

7 DalePhatANS_complete 8/18/04 10:30 AM Page 1055 Answers to Selected Exercises 1055 // Create a black-white row by concatenating the basic strings blackrow = BLACK + WHITE + BLACK + WHITE + BLACK + WHITE + BLACK + WHITE; // Print five white-black rows cout << whiterow << endl; cout << whiterow << endl; cout << whiteblankrow << endl; cout << whiteblankrow << endl; cout << whiterow << endl; // Print five black-white rows cout << blackrow << endl; cout << blackrow << endl; cout << blackblankrow << endl; cout << blackblankrow << endl; cout << blackrow << endl; // Print five white-black rows cout << whiterow << endl; cout << whiterow << endl; cout << whiteblankrow << endl; cout << whiteblankrow << endl; cout << whiterow << endl; // Print five black-white rows cout << blackrow << endl; cout << blackrow << endl; cout << blackblankrow << endl; cout << blackblankrow << endl; cout << blackrow << endl; // Print five white-black rows cout << whiterow << endl; cout << whiterow << endl; cout << whiteblankrow << endl; cout << whiteblankrow << endl; cout << whiterow << endl;

8 DalePhatANS_complete 8/18/04 10:30 AM Page Answers to Selected Exercises // Print five black-white rows cout << blackrow << endl; cout << blackrow << endl; cout << blackblankrow << endl; cout << blackblankrow << endl; cout << blackrow << endl; // Print five white-black rows cout << whiterow << endl; cout << whiterow << endl; cout << whiteblankrow << endl; cout << whiteblankrow << endl; cout << whiterow << endl; // Print five black-white rows cout << blackrow << endl; cout << blackrow << endl; cout << blackblankrow << endl; cout << blackblankrow << endl; cout << blackrow << endl; return 0; 6. There are 64 characters per line, except for the results of Exercise 4, which would have 80 characters per line. Chapter 3 Exam Preparation Exercises 1. They are simple data types. 2. char, short, int, long. 3. Integer overflow. 4. E signifies an exponent in scientific notation. The digits to the left of the E are multiplied by 10 raised to the power given by the digits to the right of the E.

9 DalePhatANS_complete 8/18/04 10:30 AM Page 1057 Answers to Selected Exercises integer / constant / floating variable a. const int TRACKS_ON_DISK = 17; integer constant b. float timeoftrack; floating variable c. const float MAX_TIME_ON_DISK = 74.0; floating constant d. short tracksleft; integer variable e. float timeleft; floating variable f. long samplesintrack; integer variable g. const double SAMPLE_RATE = ; floating constant 6. Integer division with an integer result, and floating division with a floating result. 7. a. 21, b. 21.6, c. 13.0, d. 18, e. 20, f. 22, g () unary - [ * / % ] [ + - ] 9. True. 10. a. vi, b. ii, c. vii, d. iv, e. i, f. v, g. iii. 11. The ++ operator. 12. You write the name of a data type, followed by an expression enclosed in parentheses. 13. main returns an int value False. When used alone they are equivalent, but used within a larger expression, they can give different results (this is explained more in Chapter 10). 16. string::size_type 17. a. 29 b. 1 c. "ought to start with logic" d. 0 e. "log" f. 1 g. string::npos 18. It tells the stream to print floating-point numbers without using scientific notation. Chapter 3 Programming Warm-Up Exercises 1. (hours * 60 + minutes) * 60 + seconds 2. a. days / 7 b. days % 7 3. dollars * quarters * 25 + dimes *10 + nickels * 5 + pennies 4. float(dollars * quarters * 25 + dimes *10 + nickels * 5 + pennies) / count = count + 3; 6. a. 3 * X + Y b. A * A + 2 * B + C c. ((A + B)/(C D)) * (X / Y) d. ((A * A + 2 * B + C)/D) / (X * Y)

10 DalePhatANS_complete 8/18/04 10:30 AM Page Answers to Selected Exercises e. sqrt(fabs(a B)) f. pow(x, -cos(y)) 7. string temp; temp = sentence; first = temp.find("and"); // Get first location // Remove first section of string temp = temp.substr(first + 3, temp.length() (first + 3)); // Find second location of "and" in shortened string second = temp.find("and"); // Remove next section of string temp = temp.substr(second + 3, temp.length() (second + 3)); // Adjust second to account for deleting first part of string second = second + first + 3; // Locate third "and" and adjust for prior deletions third = temp.find("and") + second + 3; 8. startofmiddle = name.find(' ') + 1; 9. cout << "$" << fixed << setprecision(2) << setw(8) << money; 10. cout << setprecision(5) << setw(15) << distance; 11. #include <climits> cout << "INT_MAX = " << INT_MAX << " INT_MIN = " << INT_MIN; 12. //********************************************** // Celsius program // This program outputs the Celsius temperature // corresponding to a given Fahrenheit temperature //********************************************** #include <iostream> using namespace std; int main() const float FAHRENHEIT = 72.0;

11 DalePhatANS_complete 8/18/04 10:30 AM Page 1059 Answers to Selected Exercises 1059 float celsius; celsius = 5/9 * (FAHRENHEIT 32); cout << fixed << "Celsius equivalent of Fahrenheit " << FAHRENHEIT << " is " << celsius << " degrees."; return 0; Chapter 3 Case Study Follow-Up 1. cout << fixed << setprecision(2) << "For a loan amount of " << LOAN_AMOUNT << " with an interest rate of " << setprecision(4) << YEARLY_INTEREST << " and a " << NUMBER_OF_YEARS << " year mortgage, " << endl; cout << "your monthly payments are $" << setprecision(2) << payment << "." << endl; 2. Change the NUMBER_OF_YEARS to NUMBER_OF_MONTHS with the value 84. Remove numberofpayments and substitute NUMBER_OF_MONTHS where numberofpayments occurs. Change... const float LOAN_AMOUNT = ; // Amount of the loan const float YEARLY_INTEREST = ; // Yearly interest rate const int NUMBER_OF_MONTHS = 84; // Total number of payments int main() // local variables float monthlyinterest; // Monthly interest rate float payment; // Monthly payment // Calculate values monthlyinterest = YEARLY_INTEREST / 12; payment = (LOAN_AMOUNT * pow(monthlyinterest + 1, NUMBER_OF_MONTHS) * monthlyinterest)/(pow(monthlyinterest + 1, NUMBER_OF_MONTHS) - 1 ); // Output results cout << fixed << setprecision(2) << "For a loan amount of " << LOAN_AMOUNT << " with an interest rate of " << setprecision(4) << YEARLY_INTEREST << " and a "

12 DalePhatANS_complete 8/18/04 10:30 AM Page Answers to Selected Exercises << NUMBER_OF_MONTHS << " month mortgage, " << endl; cout << "your monthly payments are $" << setprecision(2) << payment << "." << endl; const float LOAN_AMOUNT = ; // Amount of the loan const float YEARLY_INTEREST = 5.24; // Yearly interest rate const int NUMBER_OF_MONTHS = 84; // Total number of payments int main() // local variables float monthlyinterest; // Monthly interest rate float payment; // Monthly payment // Calculate values monthlyinterest = YEARLY_INTEREST * 0.01 / 12; payment = (LOAN_AMOUNT * pow(monthlyinterest + 1, NUMBER_OF_MONTHS) * monthlyinterest)/(pow(monthlyinterest + 1, NUMBER_OF_MONTHS) - 1 ); // Output results cout << fixed << setprecision(2) << "For a loan amount of " << LOAN_AMOUNT << " with an interest rate of " << YEARLY_INTEREST << " and a " << NUMBER_OF_MONTHS << " month mortgage, " << endl; cout << "your monthly payments are $" << payment << "." << endl; float oneplus; // Monthly interest plus 1 // Calculate values monthlyinterest = YEARLY_INTEREST * 0.01 / 12; oneplus = monthlyinterest + 1; payment = (LOAN_AMOUNT * pow(oneplus, NUMBER_OF_MONTHS) * monthlyinterest/(pow(oneplus, NUMBER_OF_MONTHS) - 1;...

13 DalePhatANS_complete 8/18/04 10:30 AM Page 1061 Answers to Selected Exercises 1061 If an expression is duplicated more than twice, it probably should be calculated and saved. If an expression is used only twice but is a complex expression, it probably should be calculated and saved. The duplicate expression in this program is simple and is used only twice; it probably isn t worth the extra storage. Chapter 4 Exam Preparation Exercises 1. False. The two statements input the values in reverse order with respect to the single statement s inputs. 2. a. The insertion operator cannot be used with cin. b. The extraction operator cannot be used with cout. c. The right operand of the extraction operator must be a variable. d. The arguments are in reverse order. e. The function name should not have a capital L, and the arguments are reversed. 3. a = 70, b = 80, c = 30, d = 40, e = 50, f = a = 70, b = 80, c = 30, d = 0, e = 20, f = a. string1 = "January", string2 = "25," b. The reading marker is on the space following the comma. 6. a. string1 = "January 25, 2005" b. The reading marker is at the start of the next line. 7. a. string1 = "January", int1 = 25, char1 = ',', string2 = "2005" b. The reading marker is on the newline character at the end of the line. 8. It returns \n. 9. The first argument is a maximum number of characters to skip over. The second argument specifies a character that the function searches for. If it finds the character before skipping the maximum number of characters, then it stops with the reading marker on the following character. 10. Some variation in the answer is acceptable, as long as it is clear that the prompt for the inexperienced user is much more detailed. a. cout << "Enter a date in the format of mm/dd/yyyy." << " For example, for October 18, 1989, enter 10/18/1989."; b. cout << "Enter date, format mm/dd/yyyy."; 11. Include the header file fstream. Declare the file stream. Prepare the file with open. Specify the name of the file stream in each I/O statement. 12. ifstream and ofstream. 13. The first statement declares infile to be an input file stream. The second statement opens infile, associating it with a file called datafile.dat by the operating system. 14. The correction is to convert the name into a C string. ifstream indata; string name; cout << "Enter the name of the file: "); cin >> name; infile.open(name.c_str());

14 DalePhatANS_complete 8/18/04 10:30 AM Page Answers to Selected Exercises 15. The input operation is ignored. 16. False. The file immediately enters the fail state, and I/O operations on it are simply ignored. 17. False. If the file doesn t exist, it can open in the fail state. 18. The answer can vary, but should at least include vehicle, customer, and agency. A little more thought might add garage, repair shop, contract, and so on. 19. The class. 20. a. A step for which the implementation details are fully specified. b. A step for which some implementation details remain to be specified. c. A self-contained series of steps that solves a given problem or subproblem. d. A module that performs the same operation as the abstract step it defines. e. A property of a module in which the concrete steps are all directed to solving just one problem, and any significant subproblems are written as abstract steps. 21. The function. 22. a. no, b. yes, c. yes, d. no, e. no. 23. True. Chapter 4 Programming Warm-Up Exercises 1. cin >> int1 >> int2 >> int3; 2. cout << "Enter a name in the format: first middle last:"; cin >> first >> middle >> last; 3. cout << "Enter a name in the format: first middle last:"; getline(cin, name); 4. float number1; float number2; float number3; float average; cout << "Enter the first number and press return: "; cin >> number1; cout << "Enter the second number and press return: "; cin >> number2; cout << "Enter the third number and press return: "; cin >> number3; average = (number1 + number2 + number3) / 3.0; cout << "The average is: " << average << endl; 5. float number1; float number2; float number3; float average; cout << "Enter the three numbers separated by spaces: "; cin >> number1 >> number2 >> number3;

15 DalePhatANS_complete 8/18/04 10:30 AM Page 1063 Answers to Selected Exercises 1063 average = (number1 + number2 + number3) / 3.0; cout << "The average is: " << average << endl; 6. The names of the variables may differ from those shown here. Instead of using the ignore function to skip a single character, reading into a dummy char variable may also be used. a. int int1; char char1; float float1; cin >> int1 >> char1 >> float1; b. string string1; string string2; int int1; int int2; cin >> string1 >> int1 >> string2 >> int2; c. int int1; int int2; float float1; cin >> int1; cin.ignore(1, ','); cin >> int2; cin.ignore(1, ','); cin >> float1; d. char char1; char char2; char char3; char char4; cin >> char1; cin.ignore(1, ' '); cin >> char2; cin.ignore(1, ' '); cin >> char3; cin.ignore(1, ' '); cin >> char4; cin.ignore(1, ' '); e. float float1; cin.ignore(1, '$'); cin >> float1;

16 DalePhatANS_complete 8/18/04 10:30 AM Page Answers to Selected Exercises 7. In this solution the comma is included as part of the city name. cin >> streetnum >> street1 >> street2 >> town >> state >> zip; 8. #include <fstream> fstream temps; temps.open("temperatures.dat"); 9. An alternative approach is to declare one temp variable that is reused for each of six input statements, and keep a running total of the input values. float temp1; float temp2; float temp3; float temp4; float temp5; float temp6; float average; temps >> temp1 >> temp2 >> temp3 >> temp4 >> temp15 >> temp6; average = (temp1 + temp2 + temp3 + temp4 + temp5 + temp6) / 6.0; cout << "The average temperature is: " << average; 10. #include <iostream> #include <fstream> using namespace std; fstream indata; fstream outdata; const float PI = ; float radius; float circumference; float area; int main() indata.open("indata.dat"); outdata.open("outdata.dat"); indata >> radius; circumference = radius * 2 * PI; area = radius * radius * PI; cout << "For the first circle, the circumference is " << circumference << " and the area is " << area << endl; outdata << radius << " " << circumference << " " << area << endl; indata >> radius;

17 DalePhatANS_complete 8/18/04 10:30 AM Page 1065 Answers to Selected Exercises 1065 circumference = radius * 2 * PI; area = radius * radius * PI; cout << "For the second circle, the circumference is " << circumference << " and the area is " << area << endl; outdata << radius << " " << circumference << " " << area << endl; 11. Changed lines are underlined. #include <iostream> #include <fstream> using namespace std; fstream indata; fstream outdata; const float PI = ; float radius; float circumference; float area; string filename; int main() indata.open("indata.dat"); cout << "Enter the name of the file to open: "; cin >> filename; outdata.open(filename.c_str()); // The remainder of the program is unchanged 12. infile >> int1 >> int2 >> int3; 13. cout << "Enter the name of the file to open: "; cin >> filename; userfile.open(filename.c_str()); 14. Top level: Write letter Mail letter

18 DalePhatANS_complete 8/18/04 10:30 AM Page Answers to Selected Exercises Level 2 Write letter Write return address and date Write company address Write salutation Write body of letter Write closing Sign letter Mail letter Address envelope Write return address Attach stamp to envelope Fold letter in thirds Insert letter in envelope Seal envelope Place envelope in mail box 15. Letter and envelope are the main objects. Other objects include: return address, company address, salutation, letter body, closing, signature, stamp, and mail box. Chapter 4 Case Study Follow-Up 1. The answer will vary with each student. 2. // Output information in required formats outdata << socialnum << endl; outdata << " " << firstname << ' ' << middlename << ' ' << lastname << ' ' << endl; outdata << " " << lastname << ", " << firstname << ' ' << middlename << ' ' << endl; outdata << " " << lastname << ", " << firstname << ' ' << initial << ' ' << endl; outdata << " " << firstname << ' ' << initial << ' ' << lastname; 3. #include <iostream> // Access cin and cout #include <fstream> // Access open... // Declare and open files ifstream indata; ofstream outdata; string filename; cout << "Enter the name of the input file: ";

19 DalePhatANS_complete 8/18/04 10:30 AM Page 1067 Answers to Selected Exercises cin >> filename; indata.open(filename.c_str()); outdata.open("name.out"); 4. #include <iostream> // Access cin and cout #include <fstream> // Access open... // Declare and open files ifstream indata; ofstream outdata; string filename; cout << "Enter the name of the input file: "; cin >> filename; indata.open(filename.c_str()); cout << "Enter the name of the output file: "; cin >> filename; outdata.open(filename.c_str()); // Mortgage Payment Calculator program // This program determines the monthly payments on a mortgage given // the loan amount, the yearly interest, and the number of years. #include <iostream> #include <cmath> #include <iomanip> using namespace std; int main() // Input variables float loanamount; float yearlyinterest; int numberofyears; // local variables float monthlyinterest; int numberofpayments; float payment;

20 DalePhatANS_complete 8/18/04 10:30 AM Page Answers to Selected Exercises // Prompt for and read input values cout << "Input the total loan amount (ex: )" << endl; cin >> loanamount; cout << "Input the interest rate (ex: 6.25)" << endl; cin >> yearlyinterest; cout << "Enter the number of years for the loan (ex: 15)" << endl; cin >> numberofyears; // Calculate values monthlyinterest = yearlyinterest * 0.01/ 12.0; numberofpayments = numberofyears * 12; payment = (loanamount * pow(1 + monthlyinterest, numberofpayments) * monthlyinterest)/ ( pow(1 + monthlyinterest, numberofpayments) - 1 ); // Output results cout << fixed << setprecision(2) << "For a loan amount of " << loanamount << " with an interest rate of " << yearlyinterest << " and a " << numberofyears << " year mortgage, " << endl; cout << fixed << setprecision(2) << "your monthly payments are $" << payment << "." << endl; return 0; Chapter 5 Exam Preparation Exercises 1. The order in which the computer executes statements in a program. 2. False. They are predefined constants. 3. False. It is >=. 4. Because, in the collating sequence of the character set, the uppercase letters all come before the lowercase letters. 5. a. true b. true c. true d. false e. false

21 DalePhatANS_complete 8/18/04 10:31 AM Page 1069 Answers to Selected Exercises 1069 f. true g. true 6. a. true b. true c. true d. true e. true f. false g. false 7. Because conditional or short-circuit evaluation prevents the second part of the expression from being evaluated when someint is True. 9. False. The parentheses are required. 10. It outputs The data doesn't make sense." 11. It outputs The word may be "The" 12. Nothing. 13. Because the test is written with = instead of ==, so the expression is always false. 14. It outputs Very good 15. Very goodexcellent 16. Add braces to enclose the If-Then statement. 17.!inData 18. There is no limit, although a human reader finds it difficult to follow too many levels. Chapter 5 Programming Warm-Up Exercises 1. moon == "blue" moon == "Blue" 2.!inFile1 &&!infile2 3. if (infile) cin >> somestring; 4. if (year1 < year2 && month1 < month2 && day1 < day2) cout << month1 << "/" << day1 << "/" year1 << " comes before " << month2 << "/' << day2 << "/" << year2; else cout << month1 << "/" << day1 << "/" year1 << " does not come before " << month2 << "/' << day2 << "/" << year2; 5. if (year1 < year2 && month1 < month2 && day1 < day2) cout << month1 << "/" << day1 << "/" year 1 << " comes before " << month2 << "/' << day2 << "/" << year2; else cout << month1 << "/" << day1 << "/" year1 << " does not come before "

22 DalePhatANS_complete 8/18/04 10:31 AM Page Answers to Selected Exercises << month2 << "/' << day2 << "/" << year2; month1 = month2; day1 = day2; year1 = year2; 6. bool1 bool2 &&!(bool1 && bool2) 7. if (score < 0 score > 100) cout << "Score is out of range"; 8. if (score < 0 score > 100) cout << "Score is out of range"; else scoretotal = scoretotal + score; scorecount++; 9. infile1 >> value1; infile2 >> value2; if (!infile1 &&!infile2) cout << "File error."; else if (!infile1!infile2) if (infile1) outfile << value1; else outfile << value2; else if (value1 < value2); outfile << value1; infile1 >> value1; else outfile << value2; infile2 >> value2; 10. if (score > 100) cout << "Duffer."; else if (score > 80) cout << "Weekend regular."; else if (score > 72) cout << "Competitive player."; else if (score > 68) cout << "Turn pro!"; else

23 DalePhatANS_complete 8/18/04 10:31 AM Page 1071 Answers to Selected Exercises 1071 cout << "Time to go on tour!"; 11. if (count1 <= count2 && count1 <= count3) cout << count1; if (count1 == count2) cout << count2; if (count1 == count3) cout << count3; else if (count2 <= count3) cout << count2; if (count2 == count3) cout << count3; else cout << count3; 12. The conditional tests are using = instead of ==. Both branches have the error, but the second one doesn t output the message because the result of the assignment expression is 0, which is treated as false by the branch. maximum = 75; minimum = 25; if (maximum == 100) cout << "Error in maximum: " << maximum << endl; if (minimum == 0) cout << "Error in minimum: " << minimum << endl; 13. if (area < 0) area = -area; root = sqrt(area); else root = sqrt(area); 14. Values of temp that should be tried are: 213, 212, 211, 33, 32, Combinations of values for month, day, and year that should be tested are as follows: Month Day Year Tests first condition of first branch not taken Tests second condition of first branch not taken Tests first branch taken, second branch taken Tests first branch taken, second not taken Tests first branch taken, second not taken, third taken

24 DalePhatANS_complete 8/18/04 10:31 AM Page Answers to Selected Exercises Chapter 5 Case Study Follow-Up 1. You could plug the BMI cut-off value and a value for weight into the formula and solve it for the height; however, the body mass index is calculated using real arithmetic. The number of decimal places must be very accurate to get the exact BMI value for which you are looking. A better choice is to round the BMI value so that you are testing two integers. 2. There is no unique answer, but the following values will work. 120, , , , // BMI Program // This program calculates the body mass index (BMI) given a weight // in pounds and a height in inches and prints a health message // based on the BMI. Input in metric measures. #include <iostream> using namespace std; int main() float weight; // Weight in kilograms float height; // Height in meters float bodymassindex; // Appropriate BMI bool dataareok; // True if data non-negative // Prompt for and input weight and height cout << "Enter your weight in kilograms. " << endl; cin >> weight; cout << "Enter your height in meters. " << endl; cin >> height; // Test Data if (weight < 0 height < 0) dataareok = false; else dataareok = true;

25 DalePhatANS_complete 8/18/04 10:31 AM Page 1073 Answers to Selected Exercises 1073 if (dataareok) // Calculate body mass index bodymassindex = weight / (height * height); // Print message indicating status cout << "Your body mass index is " << bodymassindex << ". " << endl; cout << "Interpretation and instructions. " << endl; if (bodymassindex < 18.5) cout << "Underweight: Have a milkshake." << endl; else if (bodymassindex < 25.0) cout << "Normal: Have a glass of milk." << endl; else if (bodymassindex < 30.0) cout << "Overweight: Have a glass of iced tea." << endl; else cout << "Obese: See your doctor." << endl; else cout << "Invalid data; weight and height must be positive." << endl; return 0; 4. // BMI Program // This program calculates the body mass index (BMI) given a weight // in pounds and a height in feet and inches and prints a health // based message on the BMI. Input in English measures. #include <iostream> using namespace std; int main() const int BMI_CONSTANT = 703; float weight; float inches; float feet; float height; float bodymassindex; bool dataareok; // Constant in nonmetric formula // Weight in pounds // Remainder of height in inches // Height in feet // Complete height in inches // Appropriate BMI // True if data non-negative

26 DalePhatANS_complete 8/18/04 10:31 AM Page Answers to Selected Exercises // Prompt for and input weight and height cout << "Enter your weight in pounds: " ; cin >> weight; cout << "Enter your height in feet and inches. " << endl; cout << "Feet: " ; cin >> feet; cout << "Inches: " ; cin >> inches; height = feet * 12 + inches; // Test Data if (weight < 0 height < 0) dataareok = false; else dataareok = true; if (dataareok) // Calculate body mass index bodymassindex = weight * BMI_CONSTANT / (height * height); // Print message indicating status cout << "Your body mass index is " << bodymassindex << ". " << endl; cout << "Interpretation and instructions. " << endl; if (bodymassindex < 18.5) cout << "Underweight: Have a milkshake." << endl; else if (bodymassindex < 25.0) cout << "Normal: Have a glass of milk." << endl; else if (bodymassindex < 30.0) cout << "Overweight: Have a glass of iced tea." << endl; else cout << "Obese: See your doctor." << endl; else cout << "Invalid data; weight and height " << "must be positive." << endl; return 0;

27 DalePhatANS_complete 8/18/04 10:31 AM Page 1075 Answers to Selected Exercises The weight and height are checked to be sure they are not negative before the BMI is calculated in this program. There are several other things that could be done. For example, if the weight is less than the height, then there is an error. In fact, if the weight is less than one and a half times the height, there is a good chance that there is an error. This condition produces very low BMIs. What about weights that are six or seven times the height? These produce very high BMIs. Another approach would be to put a check on the BMI itself. If it is below 10 or greater than 60, there is a good chance of input errors. Chapter 6 Exam Preparation Exercises 1. False. 2. False. 3. True. 4. a. ii, b. ix, c. iv, d. viii, e. vi, f. i, g. v, h. vii, i. iii. 5. Twelve times Twelve times. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 7. Twelve times. $1.00 $2.00 $3.00 $4.00 $5.00 $6.00 $7.00 $8.00 $9.00 $10.00 $11.00 $12.00

28 DalePhatANS_complete 8/18/04 10:31 AM Page Answers to Selected Exercises 8. The @@@@@@@@@@@ 9. The output is: The code fails to process the first value on the file. The corrected code is: sum = 0; indata >> number; while (indata) sum = sum + number; indata >> number; 11. You could choose anything that s not a name. A blank line would be one possibility. If the program must read the name in three parts, then a series of nonalphabetic characters, separated appropriately, would work. For example: The output is: The corrected code is: number = 0; while (number < 10)

29 DalePhatANS_complete 8/18/04 10:31 AM Page 1077 Answers to Selected Exercises 1077 cout << number * 2 1 << " "; number++; 13. False. 14. What is the condition that ends the loop? How should the condition be initialized? How should the condition be updated? What is the process being repeated? How should the process be initialized? How should the process by updated? What is the state of the program on exiting the loop? 15. The sum is not reinitialized at the start of each inner loop, so it simply keeps accumulating the input values. The count isn t updated, so the flow of control doesn t leave the inner loop until the end-of-file condition is encountered. Here is the corrected code. while (indata) count = 1; sum = 0; while (count <= 5 && indata) cin >> number; sum = sum + number; count++; cout << sum / count << endl; Chapter 6 Programming Warm-Up Exercises 1. count = -10; while (count <= 10) cout << count << endl; count++; 2. count = 1; sum = 0; while (sum <= 10000) sum = sum + count; count++; cout << count 1;

30 DalePhatANS_complete 8/18/04 10:31 AM Page Answers to Selected Exercises 3. count = 0; sum = 0; indata >> score; while (indata && count < 20) sum = sum + score; count++; indata >> score; if (count == 0) cout << "No data on file."; else cout << "Average is " << sum / count << endl; 4. count = 0; getline(chapter6, line); while (chapter6) if (line.find("code segment") < string::npos) count++; getline(chapter6, line); cout << "The string was found " << count << " times." 5. cin >> response; while (!(response == "Yes" response == "yes" response == "No" response == "no")) cout << "Invalid response. Please enter \"Yes\" or \"No\"."; cin >> response; yes = response == "Yes" response == "yes"; 6. cout << "Sun Mon Tue Wed Thu Fri Sat" << endl; count = 1; while (count <= startday) //Print blanks in first week cout << " "; count++; daynumber = 1; while (daynumber <= days) //Print day numbers for month while (count <= 7) //Print for one week in month if (daynumber <= days)

31 DalePhatANS_complete 8/18/04 10:31 AM Page 1079 Answers to Selected Exercises 1079 cout << setw(3) << daynumber << " "; count++; daynumber++; cout << endl; count = 1; 7. a. startday = (startday + days) % 7; b. We would need the number of days in each successive month. 8. char onechar; int ecount; int charcount; ecount = 0; textdata >> onechar; charcount = 0; while (textdata) charcount++; if (onechar == 'z') ecount++; textdata >> onechar; cout << "Percentage of letter 'z': " << float(ecount) / charcount * 100; 9. char onechar; int ecount; int charcount; ecount = 0; textdata >> onechar; charcount = 0; while (textdata && charcount < 10000) charcount++; if (onechar == 'z') ecount++; textdata >> onechar; cout << "Percentage of letter 'z': " << float(ecount) / charcount * 100; 10. first = 1; second = 1; cout << first << endl << second << endl; while (second < 30000)

32 DalePhatANS_complete 8/18/04 10:31 AM Page Answers to Selected Exercises next = first + second; first = second; second = next; cout << second << endl; 11. first = 1; second = 1; cout << setw(5) << 1 << setw(8) << first << endl << setw(5) << 1 << setw(8) << second << endl; position = 2; while (second < 30000) next = first + second; first = second; second = next; position++; cout << setw(5) << position << setw(8) << second << endl; 12. cout << "Enter number of stars: "; cin >> number; count = 1; while (count <= number) cout << '*'; count++; ) cout << endl; 13. The loop ends when the specified number of stars has been printed. The condition is initialized by getting the number of stars, and setting the loop iteration counter to 1. The condition is updated by incrementing the iteration counter at the end of each iteration. The process being repeated is the printing of a single star. The process does not require any initialization or update. Upon exiting the loop, the specified number of stars has been printed, and the iteration counter is equal to the number plus one. 14. indata >> number; while (indata) count = 1; while (count <= number) cout << '*'; count++;

33 DalePhatANS_complete 8/18/04 10:31 AM Page 1081 Answers to Selected Exercises 1081 cout << endl; indata >> number; 15. The code should be tested with an empty file, a file that contains one value, and a file that contains multiple values. The values should include a negative integer, zero, and positive integers. Chapter 6 Case Study Follow-Up 1. if (current >= high) // Check for new high 2. if (preceding <= low) 3. Yes; a priming read is used because the first value read is special and needs to be processed outside the loop. Normally, a priming read is not used with a count-controlled loop. 4. Count-controlled. 5. Changing the input to come from the keyboard is easy: cout replaces all references to the file name in output statements and all other references to the file are removed. However, because the output is also going to the screen, it will be intermingled with the prompts and the input. If you are careful, you can make the screen readable, but if the input is from the keyboard, it is better for the output to go to a file. 6. Often the amount of data determines whether it should be entered into a file rather than entered at the keyboard. Another factor is where the data is coming from. In this case, values are being recorded by a machine, so it is logical to have them go directly to a file. 7. We should try data sets that present the highest value and lowest dip in different places and in different orders. For example, we should try one set with the highest reading as the first value and another set with it as the last. We should try test data with no dips (all the readings equal), with multiple dips, and with the lowest dip before, after, and between other dips. Finally, we should try the program on some typical sets of readings and check the output with results we ve determined by hand. Chapter 7 Exam Preparation Exercises 1. It uses the keyword void instead of int, the function is not called main, and it does not contain a return statement. 2. False. The parameter name is optional. 3. Control returns after the last statement has executed, and returns to the statement immediately following the call. 4. a. v, b. iii, c. vi, d. i, e. iv, f. viii, g. ii, h. vii. 5. name and salary are reference parameters. age and level are value parameters. 6. The call must have six arguments, unless default parameters are used (we do not cover their use in this book, but they are mentioned). 7. The value parameter stores the new value but the argument is unaffected. The reference parameter stores the new value directly into the argument. 8. The type must come before the name of each parameter instead of after it. The & should be appended to the type instead of to the parameter name. The prototype should end with a semicolon.

34 DalePhatANS_complete 8/18/04 10:31 AM Page Answers to Selected Exercises 9. False. Arguments must appear in the same order as the corresponding parameters. 10. Hiding a module implementation in a separate block with a formally specified interface. 11. Flow out, or in and out. 12. It should not contain a return statement. 13. The result is not passed back to the caller it should be a reference parameter instead of a local variable. 14. The result is not passed back to the caller result should be a reference parameter instead of a value parameter. 15. The x and y parameters should be value parameters their data flow is inward only. In the case of the y parameter, the value of the argument will be set to zero when the function returns. 16. False. Like any other variable declaration, it can be accessed only by statements within the block that follows its declaration. 17. True. 18. That the file contains valid data (only integers), and that it has at least one value (the mean is undefined for an empty data set). Chapter 7 Programming Warm-Up Exercises 1. void Max (/* in */ int num1, /* in */ int num2, /* out */ int& greatest) 2. void Max (int, int, int&); 3. void Max (/* in */ int num1, /* in */ int num2, /* out */ int& greatest) if (num1 > num2) greatest = num1; else greatest = num2; 4. void GetLeast (/* inout */ ifstream& infile, /* out */ int& lowest) 5. void GetLeast (ifstream&, int&); 6. void GetLeast (/* inout */ ifstream& infile, /* out */ int& lowest) int number; infile >> number; // Get a number lowest = INT_MAX; // Initially use greatest int while (infile) if (number < lowest)

35 DalePhatANS_complete 8/18/04 10:31 AM Page 1083 Answers to Selected Exercises 1083 lowest = number; infile >> number; // Remember lower number // Get next number 7. // Precondition: // File infile has been opened AND // header file climits has been included // File infile is at end-of-file AND // if the file is empty, lowest contains INT_MAX; // else smallest number on file infile is in lowest 8. void Reverse ( /* in */ string original, /* out */ string& lanigiro ) 9. void Reverse ( string, string& ); 10. void Reverse ( /* in */ string original, /* out */ string& lanigiro ) int count; count = 1; lanigiro = ""; while (count <= original.length()) lanigiro = lanigiro + original.substr(original.length() - count, 1); count++; ) 11. // Precondition: // Original must have a value // lanigiro contains the reverse of the string in original 12. void LowerCount ( /* out */ int& count) char inchar; count = 0; cin >> inchar; while (cin && inchar!= '\n') if (islower(inchar)) count++; cin >> inchar;

36 DalePhatANS_complete 8/18/04 10:31 AM Page Answers to Selected Exercises 13. // Precondition: // The program has included the header cctype // A line has been read from cin AND // the number of lowercase letters on the line is in count 14. void GetNonemptyLine ( /* inout */ ifstream& infile, /* out */ string& line) getline(infile, line); while (infile && line == "") getline(infile, line); 15. void SkipToEmptyLine ( /* inout */ ifstream& infile, /* out */ int& skipped) skipped = 0; getline(infile, line); while (infile && line!= "") skipped++; getline(infile, line); 16. void TimeAdd ( /* inout */ int& days, /* inout */ int& hours, /* inout */ int& minutes, /* in */ int adddays, /* in */ int addhours, /* in */ int addminutes) int extrahour; int extraday; minutes = (minutes + addminutes) % 60; extrahour = (minutes + addminutes) / 60; hours = (hours + addhours + extrahour) % 24; extraday = (hours + addhours + extrahour) / 24; days = days + adddays + extraday; 17. void TimeAdd ( /* inout */ int& days, /* inout */ int& hours, /* inout */ int& minutes, /* inout */ int& seconds,

37 DalePhatANS_complete 8/18/04 10:31 AM Page 1085 Answers to Selected Exercises 1085 /* in */ int adddays, /* in */ int addhours, /* in */ int addminutes, /* in */ int addseconds) int extraminute; int extrahour; int extraday; seconds = (seconds + addseconds) % 60; extraminute = (seconds + addseconds) / 60; minutes = (minutes + addminutes + extraminute) % 60; extrahour = (minutes + addminutes + extraminute) / 60; hours = (hours + addhours + extrahour) % 24; extraday = (hours + addhours + extrahour) / 24; days = days + adddays + extraday; 18. void SeasonPrint (/* in */ int month, /* in */ int day); if (month == 12 && day >= 21) cout << "Winter"; else if ((month == 9 and day >= 21) month > 9) cout << "Fall"; else if ((month == 6 and day >= 21) month > 6) cout << "Summer"; else if ((month == 3 and day >= 21) month > 3) cout << "Spring"; else cout << "Winter"; Chapter 7 Case Study Follow-Up Exercises 1. //***************************************************************** // Mortgage Payment Tables program // This program prints a table showing loan amount, interest rate, // length of loan, monthly payments, and total cost of a mortgage. #include <iostream> #include <cmath> #include <iomanip> #include <fstream> using namespace std;

38 DalePhatANS_complete 8/18/04 10:31 AM Page Answers to Selected Exercises // Function prototypes void PrintHeading(ofstream&); void GetLoanAmount(float&); void GetRestOfData(float&, int&); void DeterminePayment(float, int, float, float&); void PrintResults(ofstream&, float, int, float, float); int main() // Input variables float loanamount; float yearlyrate; int numberofyears; float payment; ofstream dataout; dataout.open("mortgage.out"); PrintHeading(dataOut); // Prompt for and read input values GetLoanAmount(loanAmount); while (loanamount > 0.0) GetRestOfData(yearlyRate, numberofyears); DeterminePayment(loanAmount, numberofyears, yearlyrate, payment); PrintResults(dataOut, loanamount, numberofyears, yearlyrate, payment); GetLoanAmount(loanAmount); dataout.close(); return 0; void PrintHeading(ofstream& dataout) dataout << fixed << setprecision(2) << setw(12) << "Loan Amount" << setw(12) << "No. Years" << setw(15) << "Interest Rate" << setw(12) << "Payment" << setw(12) << "Total Paid" << endl;

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

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

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

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 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

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

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

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

Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

More information

Introduction to Python

Introduction to Python Caltech/LEAD Summer 2012 Computer Science Lecture 2: July 10, 2012 Introduction to Python The Python shell Outline Python as a calculator Arithmetic expressions Operator precedence Variables and assignment

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

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

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

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

The University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 01 Test #4 November 20, 2002. True or False (2 points each)

The University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 01 Test #4 November 20, 2002. True or False (2 points each) True or False (2 points each) The University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 01 Test #4 November 20, 2002 1. Using global variables is better style than using local

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

Ubuntu. Ubuntu. C++ Overview. Ubuntu. History of C++ Major Features of C++

Ubuntu. Ubuntu. C++ Overview. Ubuntu. History of C++ Major Features of C++ Ubuntu You will develop your course projects in C++ under Ubuntu Linux. If your home computer or laptop is running under Windows, an easy and painless way of installing Ubuntu is Wubi: http://www.ubuntu.com/download/desktop/windowsinstaller

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

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage

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

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London

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

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

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

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

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

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

Chapter 5 Functions. Introducing Functions

Chapter 5 Functions. Introducing Functions Chapter 5 Functions 1 Introducing Functions A function is a collection of statements that are grouped together to perform an operation Define a function Invoke a funciton return value type method name

More information

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard INPUT & OUTPUT I/O Example Using keyboard input for characters import java.util.scanner; class Echo{ public static void main (String[] args) { Scanner sc = new Scanner(System.in); // scanner for the keyboard

More information

The Payroll Program. Payroll

The Payroll Program. Payroll The Program 1 The following example is a simple payroll program that illustrates most of the core elements of the C++ language covered in sections 3 through 6 of the course notes. During the term, a formal

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

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

Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Chapter 2 Elementary Programming 2.1 Introduction You will learn elementary programming using Java primitive data types and related subjects, such as variables, constants, operators, expressions, and input

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

Exercise 4 Learning Python language fundamentals

Exercise 4 Learning Python language fundamentals Exercise 4 Learning Python language fundamentals Work with numbers Python can be used as a powerful calculator. Practicing math calculations in Python will help you not only perform these tasks, but also

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

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

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

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

VISUAL ALGEBRA FOR COLLEGE STUDENTS. Laurie J. Burton Western Oregon University

VISUAL ALGEBRA FOR COLLEGE STUDENTS. Laurie J. Burton Western Oregon University VISUAL ALGEBRA FOR COLLEGE STUDENTS Laurie J. Burton Western Oregon University VISUAL ALGEBRA FOR COLLEGE STUDENTS TABLE OF CONTENTS Welcome and Introduction 1 Chapter 1: INTEGERS AND INTEGER OPERATIONS

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

6.170 Tutorial 3 - Ruby Basics

6.170 Tutorial 3 - Ruby Basics 6.170 Tutorial 3 - Ruby Basics Prerequisites 1. Have Ruby installed on your computer a. If you use Mac/Linux, Ruby should already be preinstalled on your machine. b. If you have a Windows Machine, you

More information

Computer Science 217

Computer Science 217 Computer Science 217 Midterm Exam Fall 2009 October 29, 2009 Name: ID: Instructions: Neatly print your name and ID number in the spaces provided above. Pick the best answer for each multiple choice question.

More information

Chapter 9 Text Files User Defined Data Types User Defined Header Files

Chapter 9 Text Files User Defined Data Types User Defined Header Files Chapter 9 Text Files User Defined Data Types User Defined Header Files 9-1 Using Text Files in Your C++ Programs 1. A text file is a file containing data you wish to use in your program. A text file does

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

1) (-3) + (-6) = 2) (2) + (-5) = 3) (-7) + (-1) = 4) (-3) - (-6) = 5) (+2) - (+5) = 6) (-7) - (-4) = 7) (5)(-4) = 8) (-3)(-6) = 9) (-1)(2) =

1) (-3) + (-6) = 2) (2) + (-5) = 3) (-7) + (-1) = 4) (-3) - (-6) = 5) (+2) - (+5) = 6) (-7) - (-4) = 7) (5)(-4) = 8) (-3)(-6) = 9) (-1)(2) = Extra Practice for Lesson Add or subtract. ) (-3) + (-6) = 2) (2) + (-5) = 3) (-7) + (-) = 4) (-3) - (-6) = 5) (+2) - (+5) = 6) (-7) - (-4) = Multiply. 7) (5)(-4) = 8) (-3)(-6) = 9) (-)(2) = Division is

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

Fondamenti di C++ - Cay Horstmann 1

Fondamenti di C++ - Cay Horstmann 1 Fondamenti di C++ - Cay Horstmann 1 Review Exercises R10.1 Line 2: Can't assign int to int* Line 4: Can't assign Employee* to Employee Line 6: Can't apply -> to object Line 7: Can't delete object Line

More information

Part 1 Foundations of object orientation

Part 1 Foundations of object orientation OFWJ_C01.QXD 2/3/06 2:14 pm Page 1 Part 1 Foundations of object orientation OFWJ_C01.QXD 2/3/06 2:14 pm Page 2 1 OFWJ_C01.QXD 2/3/06 2:14 pm Page 3 CHAPTER 1 Objects and classes Main concepts discussed

More information

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

More information

FACTORING OUT COMMON FACTORS

FACTORING OUT COMMON FACTORS 278 (6 2) Chapter 6 Factoring 6.1 FACTORING OUT COMMON FACTORS In this section Prime Factorization of Integers Greatest Common Factor Finding the Greatest Common Factor for Monomials Factoring Out the

More information

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner java.util.scanner java.util.scanner is a class in the Java API used to create a Scanner object, an extremely versatile object that you can use to input alphanumeric characters from several input sources

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

A brief introduction to C++ and Interfacing with Excel

A brief introduction to C++ and Interfacing with Excel A brief introduction to C++ and Interfacing with Excel ANDREW L. HAZEL School of Mathematics, The University of Manchester Oxford Road, Manchester, M13 9PL, UK CONTENTS 1 Contents 1 Introduction 3 1.1

More information

Programming Languages CIS 443

Programming Languages CIS 443 Course Objectives Programming Languages CIS 443 0.1 Lexical analysis Syntax Semantics Functional programming Variable lifetime and scoping Parameter passing Object-oriented programming Continuations Exception

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

Advanced BIAR Participant Guide

Advanced BIAR Participant Guide State & Local Government Solutions Medicaid Information Technology System (MITS) Advanced BIAR Participant Guide October 28, 2010 HP Enterprise Services Suite 100 50 West Town Street Columbus, OH 43215

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

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java

More information

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is preceded by an equal sign d. its name has undereline 2. Associations

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

Python Lists and Loops

Python Lists and Loops WEEK THREE Python Lists and Loops You ve made it to Week 3, well done! Most programs need to keep track of a list (or collection) of things (e.g. names) at one time or another, and this week we ll show

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

Microsoft Access 3: Understanding and Creating Queries

Microsoft Access 3: Understanding and Creating Queries Microsoft Access 3: Understanding and Creating Queries In Access Level 2, we learned how to perform basic data retrievals by using Search & Replace functions and Sort & Filter functions. For more complex

More information

Iteration CHAPTER 6. Topic Summary

Iteration CHAPTER 6. Topic Summary CHAPTER 6 Iteration TOPIC OUTLINE 6.1 while Loops 6.2 for Loops 6.3 Nested Loops 6.4 Off-by-1 Errors 6.5 Random Numbers and Simulations 6.6 Loop Invariants (AB only) Topic Summary 6.1 while Loops Many

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

CS 241 Data Organization Coding Standards

CS 241 Data Organization Coding Standards CS 241 Data Organization Coding Standards Brooke Chenoweth University of New Mexico Spring 2016 CS-241 Coding Standards All projects and labs must follow the great and hallowed CS-241 coding standards.

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

If A is divided by B the result is 2/3. If B is divided by C the result is 4/7. What is the result if A is divided by C?

If A is divided by B the result is 2/3. If B is divided by C the result is 4/7. What is the result if A is divided by C? Problem 3 If A is divided by B the result is 2/3. If B is divided by C the result is 4/7. What is the result if A is divided by C? Suggested Questions to ask students about Problem 3 The key to this question

More information

The little endl that couldn t

The little endl that couldn t This is a pre-publication draft of the column I wrote for the November- December 1995 issue of the C++ Report. Pre-publication means this is what I sent to the Report, but it may not be exactly the same

More information

MAT 2170: Laboratory 3

MAT 2170: Laboratory 3 MAT 2170: Laboratory 3 Key Concepts The purpose of this lab is to familiarize you with arithmetic expressions in Java. 1. Primitive Data Types int and double 2. Operations involving primitive data types,

More information

SOME EXCEL FORMULAS AND FUNCTIONS

SOME EXCEL FORMULAS AND FUNCTIONS SOME EXCEL FORMULAS AND FUNCTIONS About calculation operators Operators specify the type of calculation that you want to perform on the elements of a formula. Microsoft Excel includes four different types

More information

CS106A, Stanford Handout #38. Strings and Chars

CS106A, Stanford Handout #38. Strings and Chars CS106A, Stanford Handout #38 Fall, 2004-05 Nick Parlante Strings and Chars The char type (pronounced "car") represents a single character. A char literal value can be written in the code using single quotes

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

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

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

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

Python Loops and String Manipulation

Python Loops and String Manipulation WEEK TWO Python Loops and String Manipulation Last week, we showed you some basic Python programming and gave you some intriguing problems to solve. But it is hard to do anything really exciting until

More information

Engineering Problem Solving and Excel. EGN 1006 Introduction to Engineering

Engineering Problem Solving and Excel. EGN 1006 Introduction to Engineering Engineering Problem Solving and Excel EGN 1006 Introduction to Engineering Mathematical Solution Procedures Commonly Used in Engineering Analysis Data Analysis Techniques (Statistics) Curve Fitting techniques

More information

Glossary of Object Oriented Terms

Glossary of Object Oriented Terms Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction

More information

Negative Integral Exponents. If x is nonzero, the reciprocal of x is written as 1 x. For example, the reciprocal of 23 is written as 2

Negative Integral Exponents. If x is nonzero, the reciprocal of x is written as 1 x. For example, the reciprocal of 23 is written as 2 4 (4-) Chapter 4 Polynomials and Eponents P( r) 0 ( r) dollars. Which law of eponents can be used to simplify the last epression? Simplify it. P( r) 7. CD rollover. Ronnie invested P dollars in a -year

More information

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions. Unit 1 Number Sense In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions. BLM Three Types of Percent Problems (p L-34) is a summary BLM for the material

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

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction

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

Introduction to Java. CS 3: Computer Programming in Java

Introduction to Java. CS 3: Computer Programming in Java Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods

More information

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

More information

While Loops and Animations

While Loops and Animations C h a p t e r 6 While Loops and Animations In this chapter, you will learn how to use the following AutoLISP functions to World Class standards: 1. The Advantage of Using While Loops and Animation Code

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

MS Access: Advanced Tables and Queries. Lesson Notes Author: Pamela Schmidt

MS Access: Advanced Tables and Queries. Lesson Notes Author: Pamela Schmidt Lesson Notes Author: Pamela Schmidt Tables Text Fields (Default) Text or combinations of text and numbers, as well as numbers that don't require calculations, such as phone numbers. or the length set by

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Access Queries (Office 2003)

Access Queries (Office 2003) Access Queries (Office 2003) Technical Support Services Office of Information Technology, West Virginia University OIT Help Desk 293-4444 x 1 oit.wvu.edu/support/training/classmat/db/ Instructor: Kathy

More information

Hypercosm. Studio. www.hypercosm.com

Hypercosm. Studio. www.hypercosm.com Hypercosm Studio www.hypercosm.com Hypercosm Studio Guide 3 Revision: November 2005 Copyright 2005 Hypercosm LLC All rights reserved. Hypercosm, OMAR, Hypercosm 3D Player, and Hypercosm Studio are trademarks

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

Chapter 3 Operators and Control Flow

Chapter 3 Operators and Control Flow Chapter 3 Operators and Control Flow I n this chapter, you will learn about operators, control flow statements, and the C# preprocessor. Operators provide syntax for performing different calculations or

More information

Time Clock Import Setup & Use

Time Clock Import Setup & Use Time Clock Import Setup & Use Document # Product Module Category CenterPoint Payroll Processes (How To) This document outlines how to setup and use of the Time Clock Import within CenterPoint Payroll.

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