Chapter 2-3 Introduction to Problem Solving Methods in C++ (PDF)

Summary

This document introduces problem-solving methods using algorithms, flowcharts, and pseudocode. It details steps in computer problem solving and explains the C++ programming process. Examples of arithmetic operations are included.

Full Transcript

# CHAPTER TWO ## INTRODUCTION TO PROBLEM SOLVING METHODS ### 2.1 Programming and Problem Solving "The analytical engine has no pretensions whatever to originate anything. It can do whatever we instruct it to program. It can follow analysis: but it has no power of anticipating any analytical relation...

# CHAPTER TWO ## INTRODUCTION TO PROBLEM SOLVING METHODS ### 2.1 Programming and Problem Solving "The analytical engine has no pretensions whatever to originate anything. It can do whatever we instruct it to program. It can follow analysis: but it has no power of anticipating any analytical relations or truths. Its province is to assist in making available what we are acquainted with." - Ada Lovelace A computer is a very powerful and versatile machine, capable of performing different tasks, yet it has no intelligence or thinking power. The intelligence quotient (I.Q) of a computer is zero. A computer performs many tasks exactly in the same manner as it is instructed by user (programmer) to do. This places responsibility on the user to instruct the computer in a correct and precise manner, so that the machine is able to perform the required job in the proper way. An incorrect or ambiguous instruction may sometimes prove devastating. For a user to instruct a computer correctly, the user must have clear and patent understanding of the problem to be solved. Beside this, the user should be able to develop a method, in the form of series of sequential steps, to solve it. Once the problem is well-defined and a method of solving it is developed, then instructing the computer to solve the problem becomes a pretty easy task. Consequently, before any attempt to write a computer program to solve a given problem, it is necessary to formulate or define the problem in a precise manner. Once the problem is defined, the steps required to solve it, must be stated clearly in the required order. ### 2.2 Steps in computer problem solving A computer cannot solve a problem on its own. One has to present step-by-step solutions of the problem to the computer. In fact, the job of problem solving is not that of the computer. It is the programmer who has to write down the solution to the problem in terms of simple operations which the computer can understand and execute. In order to solve a problem by the computer, one has to pass though certain stages or steps. These are: - Understanding the problem (definition/specification) - Analyzing the problem - Algorithm Development - Coding - Testing and Debugging - Program Documentation - Program Integration - Understanding the problem/Defining the problem: Here the programmer tries to understand the problem to be solved before the next stage or, he or she must be absolutely sure of the objectives of the given problem. This he does by answering the following questions: what will the computer program do? What task will it perform? What kind of data will the program use and where will it get the data from? What will be the output of the program? etc. - Analyzing the problem: After thorough understanding of the problem to be solved, the programmer looks at different ways of solving the problem and evaluates each of these methods. This involves identifying the problem's input, that is, the data to work with; the output of the result; and any additional requirements or constraints on the solution. The end result of this stage is a broad overview of the sequence of operations that are to be carried out to solve the problem that has been identified. - Developing the solution: Here, the overview of the sequence of operations that was the result of the analysis stage is expanded to form a detailed step-by-step solution to the problem under consideration. - Coding and implementation: The last stage of the problem solving process is the conversion of the detailed sequence of operations into a language that the computer can understand. Here each step is converted to its equivalent instruction or instructions in the computer language that has been chosen for the implantation. - Testing and debugging: Testing means running the program, executing all its instructions/functions, and testing the logic by entering sample data to check the output. Debugging is the process of finding and correcting program code mistakes, such as: - syntax errors - runtime errors, and - logical errors - The other type of testing, that is, the field testing is realized by users that operate the software with the aim of locating problems. - ProgramDocumentation: At this stage, the program is documented both internally and externally. - Integration. The program is integrated in the process flow and used to solve problems. ### 2.3 Algorithm, Flowchart and Pseudo-code #### 2.3.1 Algorithm A set of sequential steps usually written in ordinary/plain language to solve a given problem is called Algorithm. It may be possible to solve a problem in more than one way, resulting in more than one algorithm. The choice of various algorithms depends on the factors like reliability, accuracy and ease of modification. The most important factor in the choice of algorithm is the time requirement of execution, after writing code in high-level language with the help of a computer. The algorithm which will need the least time when execution is considered the best. Steps involved in algorithm development - An algorithm can be defined as "a complete, unambiguous, definite, explicit, finite number of logical steps for solving a specific problem" - Identification of input: For an algorithm, there are parameters to be supplied called input and these are entered externally. The input is to be identified first for any specified problem. - Identification of output: From an algorithm, at least one quantity is produced as a result of execution. This is the output. - Identification of the processing operations: All the computations to be carried out in order to lead to output from the input are to be identified in an orderly manner. - Processing clarity: The instructions composing the algorithm must be clear, definite. There should not be any ambiguity in them. - Processing finiteness: If we go through the algorithm, then for all cases, the algorithm should terminate after a finite number of steps. - Possessing effectiveness: The instructions in the algorithm must be sufficiently basic, so as to be carried out easily. An algorithm must have the following attributes: - Finiteness: An algorithm must terminate in a finite number of steps. - Definiteness: Each step of the algorithm must be precisely and unambiguously stated. - Effectiveness: Each step must be effective, in the sense that it is primitive; i.e., each step should be easily convertible into a program statement) can be performed exactly in a finite amount of time. - Generality: The algorithm must be complete in itself so that it can be used to solve problems of a specific type for any input data. - Input/output: Each algorithm must take zero, one or more quantities as input data produce one or more output values. An algorithm can be written in English-like statements, or in any standard representation. An algorithm written in English-like form is called a pseudocode. #### 2.3.2 Flowcharts A flowchart is a step-by-step diagrammatic representation of the solution to a problem. It can also be described as a visual or graphical representation of an algorithm. The flowcharts are the pictorial representation of the methods to be used to solving a given problem, and help a great deal to analyze the problem and plan its solution in a systematic and orderly manner. A flowchart when translated into a proper computer language, results in a complete program. Symbols used in flowcharts - The symbols that we make use of while drawing flowcharts as given in Table 2.1, as per conventions followed by the International Standard Organization (ISO). - Table 2.1: Flowchart symbols Symbol | Function/Purpose ------- | -------- Oval | The oval symbol is used to indicate either START/STOP of the program. Parallelogram | Parallelograms are used to represent input and output operations. Statements like INPUT, READ and PRINT are represented in parallelograms. Rectangle | Rectangle is used to indicate any set of processing operations, such as for storing arithmetic operations. Diamond | The diamond is used for indicating the step of decision making and therefore known as decision box. Decision boxes are used to test the conditions or ask questions and depending upon the answers, the appropriate actions are taken by the computer. Flow lines | Flow lines indicate the direction being followed in the flowchart. In a Flowchart, every line must have an arrow on it to indicate the direction. The arrows may be in any direction. On-page connector | Circles are used to join the different parts of a flowchart and these circles are called on-page connectors. The use of these connectors give a neat shape to the flowchart. In a complicated problem; a flowchart may run into several pages. The parts of the flowchart on different pages are to be joined with each other. The parts to be joined are indicated by the circle. Off-page connector | This connector represents a break in the path of a flowchart which is too large to fit on a single page. It is similar to the on-page connector. The connector symbol marks where the algorithm ends on the first page and where it continues on the second page Let's consider an example: _Draw a flowchart to find the largest of the three unequal positive numbers. See solution on Figure 2.1._ Advantages of flowcharts - The flowchart shows the logic of a problem displayed in pictorial fashion which facilitates easier checking of an algorithm. - The flowchart is a good means of communication to other users. It is also a compact means of recording an algorithm's solution to a problem. - The flowchart allows the problem solver to break the problem into parts. These parts can be connected to make master charts. - The flowchart is a permanent record of the solution which can be consulted at a later time. #### 2.3.3 Pseudocode The pseudocode is neither an algorithm nor a program. It is an abstract form of a program. It consists of English-like statements which perform the specific operations. It does not use any graphical representation. In pseudocode, the program is represented in terms of words and phrases, but the syntax of program is not strictly followed. Advantages: - Easy to read; - Easy to understand; - Easy to modify. Example: _Write a pseudocode to perform the basic arithmetic operations._ _Solution_ - READ X1, X2 - SUM = X1 + X2 - DIFF = X1 - X2 - MULT = X1 * X2 - Quot = X1/X2 - Print SUM, DIFF, MULT, QUOT - End. ## CHAPTER THREE: ## BEGINNING WITH C++ ### 3.1 The process of writing a C++ program - Write the source codes (.cpp) and header files (.h). - Pre-process the source codes according to the preprocessor directives. Preprocessor directives begin with # (a hash sign) for example, #include and #define. They show how certain manipulations (such as including another file or replacement of symbols) are to be performed before compilation. - Compile the pre-processed source codes into object codes (.obj, .o). - Link the compiled object codes with other object codes and the library object codes (.lib, .a) to produce the executable code (.exe). - Load the executable code into computer memory. - Run the executable code, with the input to produce the desired output. These steps are graphed in Figure 3.1: [Figure 3.1: Simple Flowchart for C++ Program writing Steps] - Creating and linking the source code (Figure 3.2) [Figure 3.2: Code linking flowchart] - Executing a Program (Figure 3.3) [Figure 3.3: Code execution flow] ### 3.2 Creating your first program You can write a C++ program using a text editor in the same way you write any other document such as, a shopping list. The program is kept in a file just like any other text document you prepare using a text editor. #### 3.2.1 Why use C++? C++ is the development language of choice for the majority of professional programmers because it presents fast, small programs developed in a robust and portable environment. Today's C++ tools make creating complex and powerful commercial applications an attractive straightforward exercise. #### 3.2.2 Parts of a C++program Before we jump into the details of C++ classes, variables, and so on, let's take some time to get a sense of how aC++ program fits together. The simple program HELLO.CPP in Listing 3.1has many interesting parts. We will look at this program in detail. Listing 3.1: HELLO.CPP,demonstrates the parts of a C++ program - #include <iostream.h> - intmain() - { - cout<<"Hello World!\n"; - return 0; - } Output: Hello World! Examining the #include, character by character - The first character is the # symbol, which is a signal to the preprocessor. The job of the preprocessor is to read through your source code looking for lines that begin with the poundor number sign or hashtag symbol (#), and when it finds one, to modify the code. - The include is a preprocessor instruction that says, "whatfollows is a filename. Find that file and read it in right here." The angle brackets (<, >) around the filename tell the preprocessor, "look in all the usual places for this file." If your compiler is set up correctly, the angle brackets will cause the preprocessor to look for the file iostream.h in the directory that holds all the files for your compiler. The file iostream.h(Input-Output-Stream) is used by cout, which assists with writing to the screen. The effect of line 1 is to include the file iostream.hinto this program, as if you had typed it in yourself. Line by Line Analysis - Line 3 begins the actual program with a function named main(). Every C++ program has a main() function. In general, a function is a block of code that performs one or more actions. Functions are invoked, (some programmers say they are called) by other functions, but main() is special. When your program starts, main() is called automatically. main(), like all functions, must state what type of value it will return. Once again, main() is special, it will always return int. Returning a value from a function will be discussed in detail later in this manual. All functions begin with an opening brace ({) and end with a closing brace ()). The braces for the main() function are on lines 4 and 7. Everything between the opening and closing braces is considered a part of the function. cout is used to print a message to the screen. The final two characters, \n, tell cout to put a new line after the words Hello World!' On line 6 we call return 0. This returns control to the operating system (Windows). The main() function ends on line 7 with the closing brace. Comments - A commentis text you add to explain (to yourself or other programmers) what is happening in your code. The comment has no effect; it serves only as documentation. There are two types of comments in C++. The double-slash (//) comment, which will be referred to as a C++-style comment, tells the compiler to ignore everything that follows the slashes until the end of the line. The C- style slash-star (/*) comment mark, tells the compiler to ignore everything that follows until it finds a star-slash (*/) comment mark. Standard form of a C++ program - {preprocessor directives and header files) - (e.g. <#include statements>) //(<stdio.h> and <iostream.h> are necessary here) - {<global variable declaration section>} - function A://declaration of functions - function B; - main() { //can be int main or void main - {<local variable declaration section>} - {<executable-statements>} - return 0//if int main is used - } - A; - {<executable-statements>} - B; - {<executable-statements>} ## CHAPTER FOUR ## VARIABLES AND CONSTANTS ### 4.1 What is variable? - A variable is a location in computer memory where we can store and retrieve a value. Our computer's memory can be thought of as a series of pigeonholes lined up in a long row. Each pigeonhole is numbered in sequence. The number of each pigeonhole is its memory address. Variables have addresses and are given names that explain their purpose. In a program to sum two numbers, you could create a variable named SUM to hold the sum of the two numbers and variables named A and B to to store the first and second numbers respectively. A variable is a label on a pigeonhole so that it can be accessed without knowing the actual memory address (Figure 4.1). [Figure 4.1: Variables like pigeonholes] ### 4.1.1 Variable types - In addition to integer variables, C++ types cover floating-point values and characters of text. - Floating-point variables have values that can be expressed as decimal values. - Character variables hold a single byte representing 1 of the 256 characters and symbols in the standard ASCII character set. Variable types supported by C++ programs are shown in Table 4.1. - Table 4.1: Variable types and range of values Type | Size | Typical range of values ------|------|------------------------- char | 1 byte | -128 to 127 or 0 to 255 unsigned char | 1 byte | 0 to 255 signed char | 1 byte | -128 to 127 int | 4 bytes | -2147483648 to 2147483647 unsigned int | 4 bytes | 0 to 4294967295 signed int | 4 bytes | -2147483648 to 2147483647 short int | 2 bytes | -32768 to 32767 unsigned short int | 2 bytes | 0 to 65,535 signed short int | 2 bytes | -32768 to 32767 long int | 8 bytes | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 signed long int | 8 bytes | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 unsigned long int | 8 bytes | 0 to 18,446,744,073,709,551,615 float | 4 bytes | +/- 3.4e +/- 38 (~7 digits) double | 8 bytes | +/- 1.7e +/- 308 (~15 digits) long double | 8 bytes | +/- 1.7e +/- 308 (~15 digits) Size of integers - A char variable (used to hold characters) is most often 1 byte long. A short integer, Short is 2 bytes on most computers, a long intis usually 8 bytes, and an int (without the keyword short or long) is usually 4 bytes (it may also be 2 bytes). If you are running Windows 95, Windows 98, or Windows NT, you can count on your int being 4 bytes as long as you use a modern compiler. This is demonstrated in Listing 4.1. ### 4.1.2 Names: Identifiers - To make your program easy to understand, you should always use meaningful names for variables. - The name of a variable or other item you might define in a program is called identifier. - Identifiers are used as name for variables and other items in C++ programs. - An identifier must start with either a letter or the underscore symbol ('_') and the remaining characters must all be letters, digits, or the underscore symbol. - For example, the following are all valid identifiers: X, X1, X_1_abc, abc23fv, sun Rate ### 4.1.3 Defining and assigning values to variables - All variablesmust be declared before they are used. - The syntax for variable declarations is as follows: - Syntax: - Type_Name Variable_Name_1. Variable_Name_2, ...; - intfirst_Number, second_Number; - We can define more than one variable in the same statement, provided they share the same type. - The names of the variables should be separated by commas. The firstNumber and secondNumber variables are both integers. - A variable name can be the combination of uppercase and lowercase letters, numbers and underscore characters () without any spaces. - Legal variable names include A, driver9, and secondNumber. - C++ is case sensitive, so the firstNumber variable differs from ones named firstnumber or FIRSTNUMBER. Syntax: - The syntax for a programming language or any other language is the set of grammar rules for that language. - Example, when we talk about the syntax for a variable declaration as in section 4.3 above, we are referring to a rule for writing a well-formed variable declaration. - If you follow all the syntax rules for C++, then the compiler will accept your program. ### 4.1.4 Assignment Statement An assignment statement is an order to the computer saying "set the value of this variable to what I have written down." - Example of an assignment statement: - area_of_rectangle = length * breadth; In an assignment statement, first the expression on the right-hand side of the equal sign is evaluated and then the variable on the left-hand equal sign is set equal to this value. Syntax: - Variable = Expression; Example: - Distance = rate * time; - count = count + 2; ### 4.1.5 Assigning values to variables A variable is assigned a value using the '=' operator, which is called the assignment operator. The following statements show it in action to create an integer namedfirstNumber with the value 104: - unsignedintfirstNumber; - firstNumber = 104; A variable has no meaningful value until a program gives it one. For example, if a variable maximum_value has not been given a value, either as the left-hand side of an assignment statement or by some other means, such as been given an input value with thecin-statement, then the following expression is an error: - difference = maximum_number-20; This is because maximum_number has no meaningful value, and so the entire expression on the right-hand side of the equal sign has no meaningful value. A variable like maximum_numberthat has not been given a value is said to be uninitialized. A variable can be assigned an initial value when it is created: - unsignedintfirstNumber = 104; ### 4.2 Constants Like variables, constantsare data storage locations. However, while variables vary, constants, as you may have guessed, do not vary. You must initialize a constant when you create it, and you cannot assign a new value later; once a constant is initialized its value is, in the word, constant. ### 4.2.1 Literal Constants C++ has two types of constants: literal and symbolic.A literal constant is a value typed directly into your program wherever it is needed. For example intmyAge = 39; - myAge is a variable, of type int; 39 is a literal constant. You cannot re-assign a value to myAge, and its value cannot be changed. ### 4.2.2 Symbolic constants A symbolic constant is a constant that is represented by a name, just as a variable is. Unlike a variable, however, after a constant is initialized, its value cannot be changed. If your program has one integer variable named students and another named classes, you can compute how many students you have, given a known number of classes; if you knew there were 15 students per class: - students = classes * 15; ### 4.2.3 Definition of constants To define a constant the old-fashioned way, you would enter for example: - #define studentsPerClass 15; Notice that studentsPerClass is of no particular type (int, char, and so on). #define does a simple text substitution. Every time the preprocessor sees the word studentsPerClass, it puts 15 in the text. Because the preprocessor runs before the compiler, your compiler never sees your constant; it sees the number 15. Definingconstantswithconst Although #define works, there is a new, and betterway to define constants in C++: - const unsigned short intstudentsPerClass = 15; This example also declares a symbolic constant named studentsPerClass, but this time studentsPerClass is typed as an unsigned short int. Constants can also be defined with a preprocessor directive as follows. - #define Max 10; - #define Pi 3.1415926535; - #define Small 1e-20; Initialization of values - Most times the values are initialized at the beginning of the program. - Variables can also be assigned values or initialized at the beginning but could be subject to change later. - Example: - intcounter = 50; - charch = 'F'; Enumerated constants - Enumerated constants create a set of constants with a range of values. - For example, you can declare COLOR to be an enumeration, and you can define that there are five values for COLOR: RED, BLUE, GREEN, WHITE, and BLACK. - The syntax for enumerated constants is to write the keyword enum, followed by the type name, an open brace, each of the legal values separated by a comma, and finally a closing brace and a semicolon. Here is an example: - enum COLOR { RED, BLUE, GREEN, WHITE, BLACK }; This statement performs two tasks: - It makes COLOR the name of an enumeration, that is, a new type. - It makes RED a symbolic constant with the value 0, BLUE a symbolic constant with the value 1, GREEN a symbolic constant with the value 2, and so on. Every enumerated constant has an integer value. If you do not specify otherwise, the first constant will have the value 0, and the rest will count up from there. Any one of the constants can be initialized with a particular value, however, those that are not initialized will count upward from the ones before them. Thus, if you write: - enum Color { RED=100, BLUE, GREEN=500, WHITE, BLACK=700 }; Then RED will have the value 100; BLUE, the value 101; GREEN, the value 500; WHITE, the value 501; and BLACK, the value 700. ### 4.3 Scopes and variable lifetimes - There are scope rules that govern the visibility and lifetime of objects. The two major scopes are: global and local. The global scope exists outside all other scopes. A name declared in the global scope is known throughout the program. For example, a global variable is available for use by all functions in the program. Global variables stay in existence the entire duration of the program. A local scope is defined by a statement block. That is, a local scope is begun by an opening brace and ends with its closing brace. A name declared within a local scope is known only within that scope; because blocks can be nested (blocks inside other blocks), local scopes, too, can be nested. Of course, the most common local scope is the one defined by a function. Local variables are created when their block is entered, and destroyed when their block is exited. This means that, local variables do not hold their values between function calls. A global variable must be declared outside of all functions, including outside the main() function. Global variables are generally placed at the top of the file, prior to main( ), for ease of reading, and because a variable must be declared before it is used. ### 4.4 Statements, expressions and operators #### 4.4.1 Statements - Statements are lines of codes which could be compiled by the compiler prior to execution. There are various types of statements e.g. comment statements, assignment statement, conditional statements etc. - As stated earlier, comments are statements that are non-executable, but are only used for code maintenance and documentation. Assignment Statements - X = A[1] + 3; - Y = A*X*X + B*X + C; - Flag = TRUE; - Name = "Fran"; Comments - // This is a single-line comment. - /* This is a multi-line comment.*/ #### 4.4.2 Operators - These are symbols used in constructing valid statements in a program. The various types of operators in C++ are given in Tables 4.2-4.4. Table 4.2: Arithınetic Operations Symbol | Operation -------- | -------- + | Addition - | Subtraction * | Multiplication / | Division % | Remainder (Integer) Table 4.3: Relational Operators Symbol | Operation -------- | -------- == | Equal to != | Not equal to < | Less than > | Greater than <= | Less than or equal to >= | Greater than or equal to Table 4.4: Logical Operators Symbol | Operation -------- | -------- ! | NOT (i.e. Complement or negation) && | AND (i.e. True if both operands are true) || | OR (i.e. True if either or both operands are true) Assignment Operators - The '=' is used as an assignment operator whereby the values on the right hand side are assigned to the identifier on the left hand side. - The assignment operators are: - = - *= - /= - %= - += - <<= - >>= - &= - ^= - |= - The '=' operator is the only simple assignment operator; the others are compound assignment operators. - In the expression E1 = E2, E1 must be a modifiable lvalue (left value). - The assignment expression itself is not an lvalue. The expression - E1 op= E2 has the same effect as E1 = E1 op E2 except the Ivalue, El is evaluated only once. - For example, E1 += E2 is the same as El = E1 + E2. - The expression's value is El after the expression evaluates. - For both simple and compound assignment, the operands El and E2 must obey one of the following rules: - El is a qualified or unqualified arithmetic type and E2 is an arithmetic type. - El has a qualified or unqualified version of a structure or union type, compatible with the type of E2. - El and E2 are pointers to qualified or unqualified versions of compatible types, and the type pointed to by the left has all the qualifiers of the type pointed to by the right. - Either El or E2 is a pointer to an object or incomplete type and the other is a pointer to a qualified or unqualified version of void. The type pointed to by the left has all the qualifiers of the type pointed to by the right. - El is a pointer and E2 is a null pointer constant. Note: - Spaces separating compound operators (+<space>=) will generate errors. Table 4.5: Operator Precedence Precedence | Operators -------- | -------- Highest | () [] -> :: . ! ~ ++ -- * & sizeof new delete typeid type-casts - *->* - * - / - % - + - - - << - >> - < - > - <= - >= - == - != - & - ^ - | - && - || - ? : - = - += - -= - *= - /= - %= - >>= - <<= - &= - ^= - |= Lowest | ## CHAPTER FIVE ## PREPROCESSOR DIRECTIVES AND LIBRARIES ### 5.1 Introduction There are several inbuilt functions and libraries in C++, from input/output functions, preprocessor directives to header files. These are treated in the subsequent sections. ### 5.2 Input and Output - scanf: (%i to read int, %f to read float, %lf to read double) - (Variable name must be preceded by ampersand '&') Examples: - scanf ("%i %f", &x, &y); - scanf ("%lf", &A[i,j]); - printf: (%i to print int, %f to print float or double) - (a.b between % and flag indicate: - Minimum field width - Precision of number) - printf ("\n"); // Prints a blank line - printf ("x = %i y = %5.4f\n", x, y); - printf ("A(i,j) = %15.5f", A[i,j]); However, cin and cout are used predominantly for input and output in C++. ### 5.3 Preprocessor directives in C++ - Preprocessor directives are usually placed at the beginning of your source code, but they can legally appear at any point in a program. - The Turbo C++ for Windows preprocessor detects preprocessor directives (also known as control lines) and parses the tokens embedded in them. Turbo C++ for Windows supports these preprocessor directives: - # (null directive), #ifdef, #define, #ifndef, #elif, #includ, #else, #line, #endif, #pragma, #error, #undef, #if. - Any line with a leading # is taken as a preprocessor directive, unless the # is within a string literal, in a character constant, or embedded in a comment. The initial # can be preceded or followed by whitespace (excluding new lines). ### 5.4 Header files summary Header files, also called include files, provide function prototype declarations for library functions. Data types and symbolic constants used with the library functions are also defined in them, along with global variables defined by Turbo C++ for Windows and by the library functions. The Turbo C++ for Windows library follows the ANSI C standard on names of header files and their contents. Note: - The middle column indicates C++ header files and header files defined by ANSI C. Appendix A shows a list of C++ header files and their functions. Practical Example 5.1 _Write a C++ program to generate the results as shown below:_ _Results:_ * ======Quizzes==== - Enter the score of the first quiz: 90 - Enter the score of the second quiz: 75 - Enter the score of the third quiz: 91 * =======Mid-term===== - Enter the score of the mid-term: 80 * =======Final========== - Enter the score of the final: 89 _Quiz Total:_ - 256 _Mid-term:_ - 80 _Final:_ - 89 _Total:_ - 425 _Solution:_ - #include <stdlib.h> - #include <iostream.h> - #include<iomanip.h> - using namespace std; - int main(intargc, char *argv[]) - { - float q1, q2, q3; - float qtotal, midterm, final, total; - cout<<"==========QUIZZES=========== ==\n"; - cout<<"Enter the score of the first quizz:"; cin>>q1; - cout<<"\n"; - cout<<"Enter the score of the second quizz:"; cin>>q2; - cout<<"\n"; - cout<<"Enter the score of the third quizz:"; cin>>q3; - cout<<"\n"; - cout<<"==========MID-TERM==============\n"; - cout<<"Enter the score of the mid-term:"; cin>>midterm; - cout<<"\n"; - cout<<"===========FINAL========= ==\n"; - cout<<"Enter the score of the final:"; cin>>final; - cout<<"\n"; - qtotal=q1+q2+q3; - total=qtotal+midterm+final; - cout<<"Quizz Total:"<<right<<setw(5)<<qtotal; - cout<<"\n"; - cout<<"Midterm:"<<