Chapter 4 Control, Functions, and Classes

Total Page:16

File Type:pdf, Size:1020Kb

Chapter 4 Control, Functions, and Classes June 7, 1999 10:10 owltex Sheet number 17 Page number 99 magenta black Control, Functions, and Classes 4 If A equals success, then the formula is A = X + Y + Z. X is work. Y is play. Z is keep your mouth shut. Albert Einstein quoted in SIGACT News, Vol. 25, No. 1, March 1994 Your “if” is the only peacemaker; much virtue in “if.” William Shakespeare As You Like It, V, iv Leave all else to the gods. Horace Odes, Book I, Ode ix In the programs studied in Chapter 3, statements executed one after the other to produce output. This was true both when all statements were in main or when control was transferred from main to another function, as it was in SlicePrice in pizza.cpp, Program 3.5. However, code behind the scenes in gfly.cpp, Program 3.6, executed differently in response to the user’s input and to a simulated wind-shear effect. Many programs require nonsequential control. For example, transactions made at automatic teller machines (ATMs) process an identification number and present you with a screen of choices. The program controlling the ATM executes different code depending on your choice—for example, either to deposit money or to get cash. This type of control is called selection: a different code segment is selected and executed based on interaction with the user or on the value of a program variable. Another type of program control is repetition: the same sequence of C++ statements is repeated, usually with different values for some of the variables in the statements. For example, to print a yearly calendar your program could call a PrintMonth function twelve times: PrintMonth("January", 31); //... PrintMonth("November",30); PrintMonth("December",31); Here the name of the month and the number of days in the month are arguments passed to PrintMonth. Alternatively, you could construct the PrintMonth function to determine the name of the month as well as the number of days in the month given the year and the number of the month. This could be done for the year 2000 by repeatedly executing the following statement and assigning values of 1; 2;:::;12 to month: PrintMonth(month, 2000); 99 June 7, 1999 10:10 owltex Sheet number 18 Page number 100 magenta black 100 Chapter 4 Control, Functions, and Classes In this chapter we’ll study methods for controlling how the statements in a program are executed and how this control is used in constructing functions and classes. To do this we’ll expand our study of arithmetic operators, introduced in the last chapter, to include operators for other kinds of data. We’ll also study C++ statements that alter the flow of control within a program. Finally, we’ll see how functions and classes can be used as a foundation on which we’ll continue to build as we study how programs are used to solve problems. At the end of the chapter you’ll be able to write the function PrintMonth but you’ll also see a class that encapsulates the function so you don’t have to write it. 4.1 The Assignment Operator In the next three sections we’ll use a program that makes change using U.S. coins to study relational and assignment statements and conditional execution. We’ll use the same program as the basis for what could be a talking cash register. A run of change.cpp, Program 4.1, shows how change is made using quarters, dimes, nickels, and pennies. The program shows how values can be stored in variables using the assignment operator, =. In previous programs the user entered values for variables, but values can also be stored using the assignment operator. The code below assigns values for the circumference and area of a circle according to the radius’ value, then prints the values.1 double radius, area, circumference; cout << "enter radius: "; cin >> radius; area = 3.14159*radius*radius; circumference = 3.14159*2*radius; cout << "area="<<area << " circumference="<<circumference << endl; The assignment operator in Program 4.1 has two purposes, it assigns the number of each type of coin needed to the appropriate variable (e.g., quarters and dimes) and it resets the value of the variable amount so that change will be correctly calculated. The assignment operator = stores values in variables. The expres- Syntax: assignment operator = sion on the right-hand side of the variable = expression = is evaluated, and this value is stored in the memory location as- sociated with the variable named on the left-hand side of the =. The use of the equal sign to assign values to vari- ables can cause confusion, especially if you say “equals” when you read an expression like quarters = amount/25. Operationally, the value on the right is stored in quarters, and it would be better to write quarters ← amount / 25. The as- signment statement can be read as “The memory location of the variable quarters is 1The formula for the area of a circle is πr2, the formula for circumference is 2πr where r is the radius. June 7, 1999 10:10 owltex Sheet number 19 Page number 101 magenta black 4.1 The Assignment Operator 101 assigned the value of amount/25,” but that is cumbersome (at best). If you can bring yourself to say “gets” for =, you’ll find it easier to distinguish between = and == (the boolean equality operator). Verbalizing the process by saying “Quarters gets amount divided by twenty-five” will help you understand what’s happening when assignment statements are executed. Program 4.1 change.cpp #include <iostream> using namespace std; // make change in U.S. coins // Owen Astrachan, 03/17/99 int main() { int amount; int quarters, dimes, nickels, pennies; // input phase of program cout << "make change in coins for what amount: "; cin >> amount; // calculate number of quarters, dimes, nickels, pennies quarters = amount/25; amount = amount − quarters∗25; dimes = amount/10; amount = amount − dimes∗10; nickels = amount/5; amount = amount − nickels∗5; pennies = amount; // output phase of program cout << "# quarters =\t" << quarters << endl; cout << "# dimes =\t" << dimes << endl; cout << "# nickels =\t" << nickels << endl; cout << "# pennies =\t" << pennies << endl; return 0; } change.cpp June 7, 1999 10:10 owltex Sheet number 20 Page number 102 magenta black 102 Chapter 4 Control, Functions, and Classes int amount; int amount; 87 amount = amount - quarters*25; 12 87 - 3*25 Before execution After execution int quarters; 3 Figure 4.1 Updating a variable via assignment. OUTPUT prompt> change make change in coins for what amount: 87 # quarters = 3 # dimes = 1 # nickels = 0 # pennies = 2 prompt> change make change in coins for what amount: 42 # quarters = 1 # dimes = 1 # nickels = 1 # pennies = 2 The statement amount = amount - quarters*25 updates the value of the variable amount. The right-hand side of the statement is evaluated first. The value of this expression, amount - quarters*25, is stored in the variable on the left- hand side of the assignment statement—that is, the variable amount. This process is diagrammed in Fig. 4.1 when amount is 87. A sequence of assignments can be chained together in one statement: x=y=z=13; This statement assigns the value 13 to the variables x, y, and z. The statement is interpreted as x = (y = (z = 13)). The value of the expression (z = 13) is 13, the value assigned to z. This value is assigned to y, and the result of the assignment to y is 13. This result of the expression (y = 13) is then assigned to x. Parentheses aren’t needed in the statement x=y=z=13, because the assignment operator = is right-associative: in the absence of parentheses the rightmost = is evaluated first. June 7, 1999 10:10 owltex Sheet number 21 Page number 103 magenta black 4.2 Choices and Conditional Execution 103 Table 4.1 Escape sequences in C++ escape sequence name ASCII \n newline NL (LF) \t horizontal tab HT \v vertical tab VT \b backspace BS \r carriage return CR \f form feed FF \a alert (bell) BEL \\ backslash \ \? question mark ? \’ single quote (apostrophe) ’ \" double quote " In contrast, the subtraction operator is left-associative, so the expression 8-3-2 is equal to 3, because it is evaluated as (8-3)-2rather than 8-(3-2): here the leftmost subtraction is evaluated first. Most operators are left-associative; the associativity of all C++ operators is shown in Table A.4 in Howto A. Escape Sequences. The output of change.cpp is aligned using a tab character ’\t’. The tab character prints one tab position, ensuring that the amounts of each kind of coin line up. The backslash and t to print the tab character are an example of an escape sequence. Common escape sequences are given in Table 4.1. The table is repeated as Table A.5 in Howto A. Each escape sequence prints a single character. For example, the following statement prints the four-character string "\’". cout << "\"\\\’\"" << endl; 4.2 Choices and Conditional Execution I shall set forth from somewhere, I shall make the reckless choice Robert Frost The Sound of the Trees In this section we’ll alter Program 4.1 so that it only prints the coins used in giv- ing change. We’ll also move the output part of the program to a separate function. By parameterizing the output and using a function, we make it simpler to incorporate modifications to the original program. June 7, 1999 10:10 owltex Sheet number 22 Page number 104 magenta black 104 Chapter 4 Control, Functions, and Classes Program Tip 4.1: Avoid duplicating the same code in several places in the same program.
Recommended publications
  • Lexical Analysis with Flex Edition 2.5.35, 8 February 2013
    Lexical Analysis with Flex Edition 2.5.35, 8 February 2013 Vern Paxson, Will Estes and John Millaway The flex manual is placed under the same licensing conditions as the rest of flex: Copyright c 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2012 The Flex Project. Copyright c 1990, 1997 The Regents of the University of California. All rights reserved. This code is derived from software contributed to Berkeley by Vern Paxson. The United States Government has rights in this work pursuant to contract no. DE- AC03-76SF00098 between the United States Department of Energy and the University of California. Redistribution and use in source and binary forms, with or without modification, are per- mitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of con- ditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED “AS IS” AND WITHOUT ANY EXPRESS OR IM- PLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WAR- RANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. i Table of Contents 1 Copyright ................................. 1 2 Reporting Bugs............................ 2 3 Introduction ............................... 3 4 Some Simple Examples..................... 4 5 Format of the Input File ................... 6 5.1 Format of the Definitions Section ............................
    [Show full text]
  • CALI Round 03.Pdf
    California Academic Learning Initiative 2015 - 2016 Round 3 Written by Ankit Aggarwal, Hidehiro Anto, P.C. Chauhan, Jason Cheng, Boyang Jiao, Aseem Keyal, Eddie Kim, Bruce Lou, Charlie Mann, Kevin Wang, Corry Wang, Kion You TOSSUPS 1. T he Supreme Court has decided that tailored use of this practice is permissible for achieving so-called "critical mass," although Sandra Day O'Connor wrote that this practice would no longer be necessary in 25 years. In 2003 the Supreme Court ruled against a point-based version of this practice in G ratz v. Bollinger. In June 2015 the court agreed to rehear the case (*) Fisher v. Texas challenging this practice. In 1978 quota-based versions of this practice were ruled unconstitutional in B akke v. Regents of the University of California . For 10 points, name this practice of giving preference to historically disadvantaged racial minorities. ANSWER: affirmative action in the college admissions process [accept positive discrimination; prompt on "reverse discrimination" or "discrimination"] 2. A leader criticized this religion's contradictions in his essay Against the Galileans during the 4th century. According to legend, one of this religion's major holidays was specifically scheduled to upstage a festival led by the Sol Invictus cult. Julian the Apostate attempted to roll back the spread of this religion, whose members were systematically persecuted by (*) D iocletian ( "DIE"-oh-klee-shun). It was granted toleration in the Edict of Milan by Constantine the Great, who became the first Roman emperor to convert to it. For 10 points, Pontius Pilate crucified the founder of what religion? ANSWER: Christianity [accept specific forms of Christianity] 3.
    [Show full text]
  • C Programming and Data Structures May/June 2007
    C Programming and Data Structures May/June 2007 SET-2 1. (a) What is a string constant? How do string constants differ from character constants? Do string constants represent numerical values? A string constant is a sequence of characters enclosed in double quotes. The characters may be letters, numbers, special characters and blank spaces. Example: hai , 1982, etc; A character constant is not equivalent to the single character constant. A single character string constant does not have an equivalent integer whereas a character constant has an integer value (ASCII value). String constants do not represent equivalent numerical values. (b) Summarize the standard escape sequences in C. Describe them. Black slash characters are also called escape sequences. Constant Meaning \a Audible alert(bell) \b Back space \f Form feed \n New line \r Carriage return \t Tab space \v Vertical tab \ Single quote \ Double quote \? Question mark \\ Back slash \0 Null (c) What is a variable? How can variables be characterized? Give the rules for variable declaration. A variable is a data name that may be used to store a data value. A variable may take different values at different times during execution. Variables are characterized based on the value they hold. Depending on that they are classified into int, float, char, double, and so on. Rules for variable declaration: · They must begin with a letter. Some compilers permit underscore as the first character. · ANSI standard recognizes a length of 31 characters. However, the length should not be normally more than eight characters. Appendix-C.p65 12 7/29/08, 5:21 PM Solved Question Papers C.13 · Uppercase and lowercase are significant.
    [Show full text]
  • Introduction to Programming with C-19CSE23 Module 1
    Introduction to programming with C-19CSE23 Module 1 Hardware Components Processor, memoryand Input/Output devices, are the important components of adigital computer. Processor will have ALU (Arithmetic Logic Unit) and Control Unit(CU) as its components. Memory can be subdivided into primary and secondary memory. Input devices accept data and control signals from the user. Examples of input devices are keyboard, mouse, pen based systems, data scanners, game controllers, voice recognition systems etc. Output devices communicate the processed data to the user. Examples of output devices are Monitor, Printer, Plotter, sound system etc. Processor Central Processing Unit (CPU) -It is the brain of the computer. It performs the bulk ofthe data processing operations. The function of the processor is to fetch the instructionfrom memory, examine (decode) the instruction and execute the instructions. It consists of Control unit, Arithmetic Logic Unit (ALU) and registers. Control unit is responsible for fetching the instructions from memory and interpreting them. ALU performs arithmetic and logical operations. Registers are very high speed memory unitsfor storing very small amount of data. Program counter, Instruction register, Memoryaddress register, memory buffer register and accumulator are some examples of registers.Bus is a collection of wires. They may be unidirectional or bidirectional. Bus is usedto connect different parts of a computer. Bus may be serial or parallel. USB is anexample of a serial bus. Bus connecting computer and a dot matrix printer is normallya parallel bus. Parallel bus carries several bits at a time. These bits may indicateinstruction, data, address or commands. Bus width and Bus speed are the two major components for performance measure of a computer.
    [Show full text]
  • How To: Use Basic C++, Syntax and Operators A
    June 7, 1999 10:10 owltex Sheet number 22 Page number 705 magenta black How to: Use Basic C++, Syntax and Operators A In this How to we summarize the basic syntax of C++ and the rules and operators that are used in C++ expressions. This is a brief language reference for C++ as used in this book, not the entire language. We don’t cover the use of dynamic memory in this How to. A.1 Syntax A.1.1 The Function main C++ programs begin execution with a function main. The smallest C++ program is shown below. It doesn’t do anything, but it’s syntactically legal C++. int main() { return 0; } The return value is passed back to the “system,” a nonzero value indicates some kind of failure. Although not used in this book, the function main can have parameters, these are so-called command-line parameters, passed to the program when the function is run. A brief synopsis of command-line parameters is given in Section A.2.6. A.1.2 Built-in and OtherTypes The built-in types in C++ used in this book are int, double, bool, and char.A type void is used as a built-in “empty-type,” but we don’t treat void as an explicit type. A function declared as void does not return a value of type void, but returns no value. In addition to double, the type float can be used to represent floating point values; but float is less precise and we do not use it.
    [Show full text]
  • Rsyslog Doc Documentation Release 8.26.0
    Rsyslog Doc Documentation Release 8.26.0 foo bar Aug 24, 2017 Contents 1 Manual 3 2 Reference 301 3 Sponsors and Community 343 4 Related Links 345 i ii Rsyslog Doc Documentation, Release 8.26.0 Rsyslog is a rocket-fast system for log processing. It offers high-performance, great security features and a modular design. While it started as a regular syslogd, rsyslog has evolved into a kind of swiss army knife of logging, being able to • accept inputs from a wide variety of sources, • transform them, • and output the results to diverse destinations. Rsyslog has a strong enterprise focus but also scales down to small systems. It supports, among others, MySQL, Post- greSQL, failover log destinations, ElasticSearch, syslog/tcp transport, fine grain output format control, high precision timestamps, queued operations and the ability to filter on any message part. Contents 1 Rsyslog Doc Documentation, Release 8.26.0 2 Contents CHAPTER 1 Manual Configuration Rsyslogd is configured via the rsyslog.conf file, typically found in /etc. By default, rsyslogd reads the file /etc/ rsyslog.conf. This can be changed by a command line option. Note that configurations can be built interactively via the online rsyslog configuration builder tool. Basic Structure This section describes how rsyslog configuration basically works. Think of rsyslog as a big logging and event pro- cessing toolset. It can be considered a framework with some basic processing that is fixed in the way data flows, but is highly customizable in the details of this message flow. During configuration, this customization is done by defining and customizing the rsyslog objects.
    [Show full text]
  • Digraphs and Trigraphs
    Digraphs and trigraphs In computer programming, digraphs and trigraphs are sequences of two and three characters, respectively, that appear in source code and, according to a programming language's specification, should be treated as if they were single characters. Various reasons exist for using digraphs and trigraphs: keyboards may not have keys to cover the entire character set of the language, input of special characters may be difficult, text editors may reserve some characters for special use and so on. Trigraphs might also be used for some EBCDIC code pages that lack characters such as { and }. Contents History Implementations Language support ALGOL Pascal J C C++ RPL Application support Vim GNU Screen Lotus See also References External links History The basic character set of the C programming language is a subset of the ASCII character set that includes nine characters which lie outside the ISO 646 invariant character set. The ANSI C committee invented trigraphs as a way of entering source code using keyboards that support any version of the ISO 646 character set. Implementations Trigraphs are not commonly encountered outside compiler test suites.[1] Some compilers support an option to turn recognition of trigraphs off, or disable trigraphs by default and require an option to turn them on. Some can issue warnings when they encounter trigraphs in source files. Borland supplied a separate program, the trigraph preprocessor (TRIGRAPH.EXE), to be used only when trigraph processing is desired (the rationale was to maximise speed of compilation). Language support Different systems define different sets of digraphs and trigraphs, as described below.
    [Show full text]
  • Mmt-001 Programming and Data Structures
    Indira Gandhi National Open University MMT-001 School of Sciences PROGRAMMING AND DATA STRUCTURES 1Block INTRODUCTION TO THE C PROGRAMMING LANGUAGE UNIT 1 Getting Started 7 UNIT 2 Data Types in C 21 UNIT 3 Operators and Expressions in C 49 UNIT 4 Decision Structures in C 75 UNIT 5 Control Structures-I 101 Curriculum Design Committee Dr. B.D. Acharya Prof. O.P. Gupta Prof. C. Musili Dept. of Science & Technology Dept. of Financial Studies Dept. of Mathematics and Statistics New Delhi University of Delhi University of Hyderabad Prof. Adimurthi Prof. S.D. Joshi Prof. Sankar Pal School of Mathematics Dept. of Electrical Engineering ISI, Kolkata TIFR, Bangalore IIT, Delhi Prof. A.P. Singh Prof. Archana Aggarwal Dr. R. K. Khanna PG Dept. of Mathematics CESP, School of Social Sciences Scientific Analysis Group University of Jammu JNU, New Delhi DRDO, Delhi Faculty Members Prof. R. B. Bapat Prof. Susheel Kumar School of Sciences, IGNOU Indian Statistical Institute, New Delhi Dept. of Management Studies Dr. Deepika Prof. M.C. Bhandari IIT, Delhi Prof. Poornima Mital Dept. of Mathematics Prof. Veni Madhavan Dr. Atul Razdan IIT, Kanpur Scientific Analysis Group Prof. Parvin Sinclair Prof. Sujatha Varma Prof. R. Bhatia DRDO, Delhi Dr. S. Venkataraman Indian Statistical Institute, New Delhi Prof. J.C. Mishra Prof. A. D. Dharmadhikari Dept. of Mathematics Dept. of Statistics IIT, Kharagpur University of Pune Course Design Committee Prof. C.A. Murthy Faculty Members ISI, Kolkata School of Sciences, IGNOU Prof. S.B. Pal Dr. Deepika IIT, Kharagpur Prof. Poornima Mital Dr. Atul Razdan Dr. B.S. Panda Prof.
    [Show full text]
  • Block Introduction
    UNIT 1: Introductory Structure 1.0 Introduction 1.1 Objectives 1.2 An Overview 1.3 A C Program 1.4 Escape Sequences 1.5 Getting a "feel" for C 1.6 Summary 1.0 INTRODUCTION This Unit presents the basic features common to all C programs. Quite inevitably, use is made of operators and functions that are discussed at greater length in subsequent Units: for example, operator priorities and associativities, expressions, pointers and input/output form the subject of the following Unit; but they are implicitly used in the present Unit. You will find that it is possible, in fact easy, to write simple programs that make use of the many facilities that C provides, the more intricate features of which you may not perhaps fully comprehend right away. This shouldn't worry you. That knowledge will come with further reading, and practice. We would like you to create and execute the programs listed anyway, and experiment with different values for program variables. Try to see why you get the results that you do, and before you know it you'll have mastered the language! 1.1 OBJECTIVES After working through this Unit you should be able to -declare, define and compute the values of program variables via simple arithmetic operation -create and execute simple C programs -recognise examples of C strings, escape sequences, and program comments -use the simplest functions for input and output. 1.2 AN OVERVIEW C is a general purpose computer programming language. It was originally created by Dennis M. Ritchie (circa 1971) for the specific purpose of rewriting much of the Unix operating system.
    [Show full text]
  • Portable Paper
    Vol. 4, No. 6 The HP Portable/Portable Plus/Portable Vectra Users Newsletter November / December 1989 (; ~) PortableTHE Paper Publisher's Message .................. 3 Always Select Backlight Powerdown . .. 14 Letters Generate a Bullet ..................... 14 The Mac Portable And The HP Portables ....... 4 More LS/12 and Vectra Products On The Horizon 15 More On "tjctrl" . .. 4 News From Personalized Software The Editor Makes PAM and Time Manager easier .. 4 What we're working on . .. 15 Short note of appreciation . .. 4 Upgrade 256K Portable Plus into a 512K Plus. .. 16 Getting The 110 and a PC to Read the Same Disks 4 1 Meg RAMjROM and 2 Meg RAM Drawers Need Scientific Word Processor ............. 5 Shipping Again For Portable Plus ........... 16 A few useful hints... ..................... 5 VI Editor For HP An IBM-Compatible Computers 16 Likes Empowerer ....................... 5 World's Smallest MNP Modem ............. 17 Using Squish Plus With The Plus And Vectra Together 5 Subscribers Disks Only Available With Subscription 17 Squish Plus Extends Life Of Portable Plus . .. 5 1986-1989 Index Soon Available ............ 17 Suggestions To Improve Time Manager ........ 5 First Issue Of The UltraLite Connection Ships . .. 17 Likes MS-Word over WordPerfect ............ 39 Profiles 110% Portable Computing With The Plus ......... 22 LS/12 Still On HP Price List ... But not for Long .. 6 Frustrations - And Resolutions . .. 24 The 1990 Subscribers Disk . .. 6 The Savvy User Attention HP3000 Users: MPE On HP Portables! .. 6 Time Manager Solution . .. 27 Infocom Games ........................ 6 Using 1JCTRL With Memomaker . .. 28 What is ASCII.... .. .. .. .. .. .. .. .. .. ... 8 PAM Menu Overflows ................... 30 HPIL Switch Box ....................... 9 Webster's Pop Up Spelling Checker.
    [Show full text]
  • Sample C++ Programs
    ESCAPE sequences in C++ \n newline NL (LF) \t horizontal tab HT \v vertical tab VT \b backspace BS \r carriage return CR \f form feed FF \a alert (bell) BEL \\ backslash \ \? question mark ? \’ single quote (apostrophe) ’ \" double quote " Operator Symbols () Function call + Plus (binary addition) - Minus (binary subtraction) * Multiplication / Divide << Shift-left/stream insert >> Shift-right/stream extract == Equal != Not equal && Logical AND || Logical OR = Assignment += Arithmetic assignment -= Arithmetic assignment *= Arithmetic assignment /= Arithmetic assignment Program 1 // A simple C++ program #include <iostream> using namespace std; int main() { cout << "Programming is great fun!"; return 0; } Program 2 // A simple C++ program #include <iostream> using namespace std; int main() { cout << "Programming is " << "great fun!"; return 0; } Program 3 // A simple C++ program #include <iostream> using namespace std; int main() { cout << "Programming is "; cout << "great fun!"; return 0; } Program 4 // This program has a variable. #include <iostream> using namespace std; int main() { int number; number = 5; cout << "The value in number is " << number << endl; return 0; } Program 5 // This program shows three variables defined on the same line. #include <iostream> using namespace std; int main() { int floors, rooms, suites; floors = 15; rooms = 300; suites = 30; cout << "The Grande Hotel has " << floors << " floors\n"; cout << "with " << rooms << " rooms and " << suites; cout << " suites.\n"; return 0; } If Statement #include <iomanip> using namespace std; int main() { int score1, score2, score3; // To hold three test scores double average; // TO hold the average score // Get the three test scores. cout << "Enter 3 test scores and I will average them: "; cin >> score1 >> score2 >> score3; // Calculate and display the average score.
    [Show full text]
  • Pdf External()
    The CImg Library 2.9.9 Generated by Doxygen 1.8.17 i 1 Main Page 1 2 CImg Library Overview 3 2.1 Library structure............................................. 3 2.2 CImg version of "Hello world"....................................... 4 2.3 How to compile ? ............................................ 4 2.4 What's next ? .............................................. 5 3 FAQ 7 3.1 FAQ Summary.............................................. 7 3.2 1. General information and availability ................................. 7 3.2.1 1.1. What is the CImg Library ?................................. 7 3.2.2 1.2. What platforms are supported ? .............................. 8 3.2.3 1.3. How is CImg distributed ? ................................. 8 3.2.4 1.4. What kind of people are concerned by CImg ?....................... 8 3.2.5 1.5. What are the specificities of the CeCILL license ?..................... 8 3.2.6 1.6. Who is behind CImg ? ................................... 9 3.3 2. C++ related questions ........................................ 9 3.3.1 2.1 What is the level of C++ knowledge needed to use CImg ?................. 9 3.3.2 2.2 How to use CImg in my own C++ program ?........................ 9 3.3.3 2.3 Why is CImg entirely contained in a single header file ? .................. 9 3.4 3. Other resources ........................................... 10 3.4.1 3.1 Translations......................................... 10 4 Setting Environment Variables 11 5 How to use CImg library with Visual C++ 2005 Express Edition ? 13 5.1 How to use CImg library with Visual C++ 2005 Express Edition ? ................... 13 6 Tutorial : Getting Started. 15 7 Image Loops. 17 7.1 Loops over the pixel buffer........................................ 17 7.2 Loops over image dimensions...................................... 18 7.3 Loops over interior regions and borders.
    [Show full text]