Chapter 1 INTRODUCTION

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

Download "Chapter 1 INTRODUCTION"

Transcription

1 Chapter 1 INTRODUCTION A digital computer system consists of hardware and software: The hardware consists of the physical components of the system. The software is the collection of programs that a computer can execute and a program is a sequence of step-by-step instructions that a computer executes in order to solve a problem or to perform a task. This chapter discusses the concepts of a computer system hardware and software, computer programs, basic elements of a high-level language, structure of a high-level language program, functions, header files and the preprocessor, library functions, and the processing of a C/C++ language program. 1.1 Computer System Hardware A computer system hardware consists of four major components: the Central Processing Unit (CPU), the Main (or Primary) Memory, the input system, and the output system. The general structure of a digital computer system hardware is shown in figure 1.1. Main Memory The main memory (also called primary memory) is a collection of two-state devices. The states of each of these devices are used to represent binary digits or bits (0 or 1): one state represents 0 and the other represents 1. Consecutive bits in the main memory are grouped into units of 8 called bytes. A byte is characterized by two things: its address and its content. The address of a byte corresponds to its relative position in the main memory: the first byte is at address 0, the second at address 1,..., etc. The content of a byte is the bit pattern that it represents. For example The main memory holds the data to be processed by the computer and the program that it must execute in order to process it. Central Processing Unit The central processing unit (CPU) is the center of activities in a computer: it controls the operations of the other components of a computer, and also interprets and executes the instructions of a program. It consists of the Control Unit (CU), the Arithmetic and Logic Unit (ALU) and the registers. The Control Unit (CU) controls the operations of the different components of a computer, and also interprets (or decodes) each instruction of a program. The Arithmetic and Logic Unit (ALU) executes the instructions of a program. It can only perform the basic arithmetic operations of addition, subtraction, multiplication, and division, and logical operations 2017 Gilbert Ndjatou Page 1

2 such as comparing two numbers or the Boolean operations (AND, OR, or NOT). Registers are high-speed memory locations within the CPU that are used to hold certain data. Figure 1.1 General Structure of a Digital Computer System Hardware CPU CU Registers ALU Controller Controller Main Memory Input Device Output Device Controller Drive Secondary Storage The arrows indicate the flow of data between the computer system hardware components. Input/Output Systems The Input system consists of the Input devices and their controllers. Examples of input devices are keyboards, microphones, scanners, and mice. An input device is used to transmit information from the outside world to the computer. The output system consists of the output devices and their controllers. Examples of output devices are printers, monitors, and speakers. An output device is used to transmit information from the computer to the outside world. There is a controller between the CPU and each input/output device. For an output device, the controller accepts incoming data (as a sequence of bits) from the computer that it converts into the signals used by that device Gilbert Ndjatou Page 2

3 For an input device, the controller accepts signals from the device that it converts into sequences of bits to be used inside the computer. A device controller is also used for communication with the CPU: it accepts commands from the CPU and also lets the CPU know what is happening with the device. Secondary Storage A Secondary storage is used to permanently save data and programs for future use inside a computer. Examples of secondary storages are flash drives, hard disks, tapes, CDs, and DVDs. A secondary storage can be used on a computer only if that computer has a drive that can read and/or write on that secondary storage. There is also a controller between the CPU and each drive: this controller converts signals from the secondary storage drive into bits that are sent to the main memory and vice versa. The collection of input devices, output devices, and the drives are referred to as system peripherals. System Interconnection The system interconnection consists of the wiring and the devices that allow data and control codes to move from one part of the computer system hardware to another. It is in general referred to as the system bus. Exercise 1.1 Part I Fill in the blanks with the most appropriate answers. 1. A is a sequence of step-by-step instructions that a computer executes in order to solve a problem or to perform a task. 2. A digital computer system consists of and. 3. The consists of the physical components of a digital computer system. 4. The is the collection of programs that a computer can execute. 5. A is a group of 8 consecutive bits. 6. The of a byte corresponds to its relative position in the main memory. 7. The of a byte is the bit pattern that it represents. 8. The holds the data to be processed by the computer, and the program that it must execute in order to process it. 9. The controls the operations of the different components of a computer system, and interprets and executes the instructions of a program. 10. The controls the operations of the different components of a computer, and also interprets (or decodes) each instruction of a program. 11. The executes the instructions of a program Gilbert Ndjatou Page 3

4 12. are special high-speed memory locations within the CPU that are used by programmers or the CPU to hold certain data. 13. The input system consists of the and their. 14. The output system consists of the and their. 15. An output device accepts incoming data (as a sequence of bits) from the computer that it converts into the signals used by that device. 16. An input device accepts signals from the device that it converts into sequences of bits to be used inside the computer. 17. A is used to permanently save data and programs for future use inside the computer. 18. In order to use a particular secondary storage on a computer, that computer must be equipped with a for that type of secondary storage and a for the communication between the computer and the drive. 19. A computer system is the collection of input devices, output devices, and the drives on that computer system. 20. The consists of the wiring and the devices that allow data and control codes to move from one part of the computer system hardware to another. Part II. A. What are the four major components of a digital computer system hardware? B. What are the three major components of a CPU? C. Provide three examples of each of the following components of a digital computer system hardware: a. input devices b. output devices c. secondary storage D. What are the major functions of each of the following components of a digital computer system hardware? a. main memory b. input device c. output device d. CPU e. secondary storage 1.2 Computer Software A computer software is the collection of programs that it can execute. There are two major classes of computer software: system programs and application programs. An application program is a program that is executed by a computer in order to perform a specific task or to solve a particular problem for its user. Examples of application programs are word-processors, data base management systems, spreadsheet programs, and web browsers. A word-processors is a program that lets its users create documents with formatting features. A data base management system is a program that lets its users create tables of information, and also provides for easy access and update of information in those tables. A spreadsheet program lets its users create electronic spreadsheets Gilbert Ndjatou Page 4

5 A web browser is used to display web pages. A system program is a program that is used for the operation of a computer. Examples of system programs are editors, compilers, linkers, and operating systems. An editor reads characters from the keyboard and places them into a file. Every compiler software package comes with an editor that you can use to type and edit your programs. An operating system performs the following tasks: Manages all the computer resources making sure that resources such as the CPU, the main memory, the printer, the hard disk,..., etc are used properly. Provides an interface to the hardware that is easy to understand and use in other programs. Examples of operating systems running on IBM PC and compatible computers are MS Windows XP, MS Windows vista, MS Windows 7, MS Windows 8, and LINUX. UNIX is the operating system running on most minicomputers. Some operating system software packages also include programs called shells or command interpreters that provide the access of the computer system to users. Exercise 1.2 Fill in the blanks with the most appropriate answers. 1. An is a program that is used to perform a specific task or to solve a particular problem for its user. 2. A is a program that is used for the operation of the computer. 3. A is a program that lets its users create documents with formatting features. It also inserts hidden codes in a document in order to obtain certain features such as boldfacing, underlining, italic,... etc. 4. A is a program that lets its users create tables of information, and also provides for easy access and update of information in those tables. 5. A is a program that lets its users create electronic spreadsheets. 6. An is a program that reads characters from the keyboard and places them into a file. 7. An is a program that manages all the computer resources, making sure that resources such as the main memory, the printer, the hard disk,..., etc are used properly. 8. An is a program that provides an interface to the hardware that is easy to understand and use in other programs. 9. A is a program that provides the access of the computer system to users Gilbert Ndjatou Page 5

6 1.3 Computers and Programming As shown in figure 1.2, the three major functions of a digital computer system are to input data, to process it, and to output the result(s) of the computation. The input data is represented inside the main memory as a sequence of bits. The computer processes data by execution the step-by-step instructions of a program. A program and its input data must be in the main memory before it can be executed by the CPU. Figure 1.2 Computer System data Process data Result(s) As shown in figure 1.3, data are represented (held) in memory locations inside the main memory. The size of a memory location (in bytes) depends on the type of data that it holds. For example, on IBM PC and compatible computer systems, one byte is used to hold a character, and four consecutive bytes are used to hold positive and negative integer values. The address of a memory location is the address of its first byte. Figure 1.3 Examples of Memory locations Address: This figure illustrates three memory locations: - the first memory location has two bytes and its address is the second has one byte and its address is the third has four bytes and its address is bytes at addresses, 151, 153 and 154 are not used Gilbert Ndjatou Page 6

7 A computer can execute a program only if it is written as sequences of bits in a language called machine language. An example of a machine language instruction for the IBM PC and compatible computers follows: Each type of computer has its own set of machine language instructions called its machine language. For example, a program written for the IBM PC cannot be executed on Apple Macintosh computers because they have different machine languages. Most programmers write programs in languages usually referred to as high-level languages. It is easier to write programs and correct mistakes (debug) in a high-level language than in a machine language. Examples of high-level languages are FORTRAN, JavaScript, PHP, BASIC, C++, Ada, and Java. A high-level language program must first be translated into the machine language of a computer before it can be executed by that computer. The compiler is a system program that translates a high-level language program into a program in the machine language of a particular type of computer. There is a compiler for each high-level programming language and for each type of computer: for example, a C++ compiler for the IBM PC and compatible computers; a C++ compiler for the SUN microsystem computer; a FORTRAN compiler for the Apple Macintosh computers. Some high-level programming languages such as PHP, Java, and JavaScript have a system program called interpreter that takes a program in that language and its input data as input, executes the program on a computer, and produces the output of that program. The functions of a compiler and those of an interpreter are illustrated in figure 1.4. Figure 1.4 (a) Functions of a Compiler Program Program ( in high-level language) Compiler (in machine language) (b) Functions of an Interpreter Program ( in high-level language) Output (of the program) Input Data Interpreter (of the program) 2017 Gilbert Ndjatou Page 7

8 Exercise What are the three major functions of a digital computer system? 2. Where is the input data represented inside the main memory? 3. How are data represented inside a computer? 4. What is the size of the memory location used to hold each of the following types of data inside an IBM PC? a. a character. b a positive or negative integer value. 5. What is the address of a memory location? 6. A program is executed by a computer only if it is written in what language? 7. How is a machine language instruction of a computer specified? 8. Can a program in the machine language of the IBM PC be executed by the SUN Microsystem computer? Why? 9. Provide three examples of high-level programming languages. 10. You have written a program in C++. What do you have to do in order to execute it on the IBM PC? 11. You have a C++ compiler for the IBM PC. Can you use this compiler on the SUN Microsystem computer? Why? 12. What is the difference between a compiler and an interpreter? 13. Name a programming language that has an interpreter? 1.4 High-Level Language Programs When you write a program in a high level language, you do not know where the data will be held in memory. For this reason, you use a variable to represent a memory location in a high level language program. Also, the only things that you can write in a C++ program are: comments, statements and preprocessor directives. An example of a C++ program is shown in figure 1.5. Figure 1.5 An Example of C++ Program Line # Statements /Comments 1 /* A Sample Program */ 2 /* read a character and an integer value from the keyboard, 3 compute the double of the value, and print the results */ 4 /* Prepared by: <enter your name here> */ 5 6 #include <iostream> 7 using namespace std; 8 9 int main() int num; // to hold an integer value 12 int result; // to hold the result of the computation 13 char letter; // to hold a character cout << endl << Hello World ; Gilbert Ndjatou Page 8

9 17 /* read a character and an integer value */ 18 cout << endl << Enter a character please: ; 19 cin >> letter; 20 cout << endl << Enter an integer value: ; 21 cin >> num; /* compute the double of the value and print the results */ 24 result = 2 * num; 25 cout << endl << The character is: 26 << letter; 27 cout << endl << The double of the value is: ; 28 cout << result; 29 cout << endl << Bye bye ; 30 return (0); 31 Comments A comment is a note or a remark for a human being reading the program. It is ignored by the compiler and may appear anywhere in a program. You can write comments in two different ways: 1. Any sequence of character between the characters /* and */ Example: /* A Sample Program */ 2. Any sequence of characters that follows the characters // and that ends at the end of the line. Example: // to hold an integer value A comment is in general used to accomplish the following things: 1. To specify the object of a program. Examples: lines 2 to 3 of the program in figure To specify a computation step of a program. Examples: lines 17 and 23 of the program in figure To clarify the meaning of a sequence of one or more statements. Examples: lines 11, 12, and 13 of the program in figure 1.5. Statements You can write two types of statement in a C++ program: 1. Statements to instruct or provide information about the program to the compiler. These statements are not translated into machine language. For example, statements in lines 11, 12, and 13 of the program in figure Statements that are translated into machine language instructions. These statements are usually referred to as executable statements. Every C++ statement ends with a semicolon Gilbert Ndjatou Page 9

10 A statement may be written over more than one line. For example the statement in lines 25 and 26 of the program in figure 1.5. You may also leave one or more blank lines between statements and comments. The C++ programming language has the following basic statements: 1. Declaration statement. 2. Input statement. 3. Output statement. 4. Assignment statement. Declaration Statement In a C++ program, you have to make a request for a memory location (variable) to the compiler before you can use it to hold data. You make a request for a memory location (variable) by using a declaration statement. Examples of declaration statements in the program in figure 1.5: Line 11 Line 12 Line 13 int num; int result; char letter; In a declaration statement, you specify the data type of a variable followed by its name. The data type of a variable tells the compiler the type of data that will be stored in the corresponding memory location. The compiler uses the data type of a variable to figure out how many bytes to reserve for the corresponding memory location. The following are the basic data types in C++: int char float double bool for integer values for a single character value for a single precision floating point value for a double precision floating point value for true or false You can also specify the initial value of a memory location in a declaration statement as in the following example: int num = 15; 15 will be stored in the corresponding memory location Gilbert Ndjatou Page 10

11 Input Statement You use an input statement to read (or input) data into a program. An input statement to read data from the keyboard starts with the keyword cin which is followed by the names of one or more variables preceded by the stream extraction operator ( >> ). The following input statements are from the program in figure 1.5: line 19 cin >> letter; Line 21 cin >> num; After the execution of a cin statement, the computer stops and waits for you to type an input value for each variable listed in the statement. Type each value followed by the Enter key. The value that you type for a variable is stored in the corresponding memory location. For example, if you type: K Enter 25 Enter Then K will be stored in the memory location letter and 25 in the memory location num. Two or more variable names can also be specified in a cin statement as in the following example: cin >> letter >> num; When two or more variables are specified in a cin statement, you must type a value for each of these variables: you can press the Enter key after each value or after you have typed all the values separated with one of more spaces as follows: K 25 Enter Assignment statement You use an assignment statement to store a value into a memory location. It starts with the name of the variable followed by the assignment operator ( = ), which is then followed by the value that you want to store in that memory location. Example Suppose that we have three variables letter, num, and result declared in a program as follows: char letter; int num; int result; letter = 'a'; num = 25; says to store the character a in the memory location letter. says to store 25 in the memory location num. result = 2 * num; says to take the value in memory location num (25), multiply it by 2 and to store the result in the memory location result Gilbert Ndjatou Page 11

12 Output statement You use a cout statement to display (or print) information on the screen. It starts with the keyword cout followed by one or more data to be displayed, or by a stream manipulator. Each data to be displayed or a stream manipulator is preceded by the stream insertion operator ( << ). The string manipulator endl causes the cursor to move to the beginning of the next line before the next data is printed. Example Suppose that we have three variables letter, num, and result declared in a program as follows: char letter; int num; int result; and that we have the following assignment statements: letter = 'a'; num = 25; says to store the character a in the memory location letter. says to store 25 in the memory location num. result = 2 * num; says to take the value in memory location num (25), multiply it by 2 and to store the result in the memory location result. Each of the following output statements will produce the specified output. Statement Output cout << endl << Hello Word ; Hello Word cout << endl << The character is: << letter; The character is: a cout << endl << The double of the value is: ; cout << result; The double of the value is:50 cout << endl << 100 << letter << num; 100a25 cout << endl << letter = << letter; letter = a cout << endl << result = << result; result = 50 NOTES 1. The next information to be displayed is printed starting at the current cursor position. 2. Any sequence of characters between double quotes is displayed without the double quotes. 3. Any variable name that appears in an output statement is replaced by the current value of the corresponding memory location Gilbert Ndjatou Page 12

13 Exercise The following program reads two integer values, computes their sum, and prints the result. Insert comments in this program in order to accomplish the following: a) specify the object of the program.. b) Explain the use of variables. c) specify the steps of the computation. Line # 1 #include <iostream> 2 using namespace std; 3 int main() 4 5 int num1; 6 int num2; 7 int result; Statements /Comments 8 cout << endl << Enter two integer values, please: ; 9 cin >> num1; 10 cin >> num2; 11 result = num1 + num2; 12 cout << endl << their sum is: << result; 13 return 0; Explain what will happen after each of the following statements is processed by the compiler: a. char grade; b. int idnum; 3. Write the statements to accomplish the following: a. Declare variable number to hold an integer value. b. Declare variable letter to hold a character value c. Read an integer value into variable number and a character value into variable letter. d. Output the string Nice day, the value in variable letter and 5 times the value in variable number. 4. Assuming that all variables have been previously defined and that the statements are executed in the given order, show the output produced by the following statements if the input value is 9: cout << endl << Good job ; cin >> num; sum = num + 5; cout << endl << num = << num << sum= << sum; num = 7; sum = num + 5; cout << endl << num = << num << sum= << sum; 2017 Gilbert Ndjatou Page 13

14 1.5 Structure of a High-Level Language Program A high-level language program consists of one or more files called source files or source modules. the filename extension of a source file depends on the programming language. The following are filename extensions of source files in some programming languages: Programming Language Filename Extension C.c C++.cpp Java.java BASIC.bas COBOL.cob Examples of valid filenames of C++ source files are lab1.cpp, program.cpp, and payroll.cpp. C++ Program Source Module A C++ program source module consists of one or more functions. A function has a name and consists of a function header followed by a sequence of statements enclosed between the left brace and the right brace. An example of function is shown in figure 1.6. The function header of this function is: void test( ). Its name is test. Every C++ program must have a unique function named main. The execution of a program starts with the first executable statement in function main. Statements in any other function are executed only if that function is called or invoked by function main or a function that is called by function main. After the execution of the last statement in a function that is called, the next statement to be executed is the statement that follows the statement in which that function is called. In the source module of figure 1.7, the order of execution of the executable statements is: 14, 15, 16, 17, 4, 5, 6, 7, 8, 9, 10, 11, 18, 19, and 20. Statement 20 is a return statement. Its execution terminates the execution of the program Gilbert Ndjatou Page 14

15 Figure 1.6 An Example of Function Definition /* function to read a character and an integer value, to compute the double of the value, and to print it with the character read. */ void test() Char letter; int num, result; // to hold the character // to hold the integer value // to hold the double of the value /* read a character and an integer value */ cout << endl << Enter a character please: ; cin >> letter; cout << endl << Enter an integer value: ; cin >> num; /* compute the double of the value and print the results */ result = 2 * num; cout << endl << The character is: << letter; cout << endl << The double of the value is: << result; cout << endl << Bye bye ; Figure 1.7 An Example of Function Definitions and Function Call #include <iostream> using namespace std; /* function to read a character and an integer value, to compute the double of the value, and to print it with the character read. */ void test() 1 Char letter; // to hold the character 2 int num; // to hold the integer value 3 int result; // to hold the double of the value /* read a character and an integer value */ 4 cout << endl << Enter a character please: ; 5 cin >> letter; 6 cout << endl << Enter an integer value: ; 7 cin >> num; /*compute the double of the value and print the results */ 8 result = 2 * num; 9 cout << endl << The character is: << letter; 10 cout << endl << The double of the value is: << result; 11 cout << endl << Bye bye ; 2017 Gilbert Ndjatou Page 15

16 /* function main */ int main() 12 int num1; // the first number 13 int num2; // the second number /* read two integer values */ 14 cout << endl << Enter two integer values: ; 15 cin >> num1 >> num2; /*----read a character and an integer value and compute its double*/ 16 cout << endl << I am about to enter function test( ) ; 17 test(); 18 cout << endl << I am back in function main ; /* compute the sum of the two values and print it */ 19 cout << endl << The sum of the two values is: << (num1 + num2); 20 return (0); Functions That Return a Value A function returns a value by using the return statement in which the value that is returned is specified. An example of a function that returns a value is defined and called in the program in figure 1.8. A function that returns a value must be called in such a way that the value that it returns is used in function main. For example, if function tester2 defined in figure 1.8 is called as follows, the value returned will be lost: tester2( ); Figure 1.8 Calling a Function that Returns a Value Given the following definitions of functions tester2 and main: #include <iostream> using namespace std; int tester2( ) return (5); int main( ) int num; int result1; int result2; num = 10; result1 = tester2( ); result2 = num + tester2( ); cout << endl << result1 = << result1 << endl << result2 = << result2; return ( 0 ); 2017 Gilbert Ndjatou Page 16

17 The output of this program is: result1 = 5 result2 = 15 Exercise 1.5 A. List the numbers of the statements of the following program in the order in which they will be executed by the CPU. #include <iostream> using namespace std; void newtest() 1 int num1; // to hold the first integer value 2 int num2; // to hold the second integer value 3 int sum; // to hold their sum 4 cin >> num1; 5 num2 = 25; 6 sum = num1 + num2; 7 cout << endl << sum = << sum; int main() 8 int number1; // the first number 9 int number2; // the second number 10 number1 = 14; 11 number2 = number1 + 50; 12 newtest(); // call function newtest() 13 cout << endl << number1 = << number1; 14 cout << endl << number2 = << number2; 15 return (0); B. What is the output of the following program? #include <iostream> using namespace std; int newtester2( ) return (7); int main( ) int result1; int result2; result1 = newtester2( ); result2 = newtester2( ) + 9; cout << endl << result1 = << result1 << endl << result2 = << result2; return ( 0 ); 2017 Gilbert Ndjatou Page 17

18 Header Files and the Preprocessor In general, C++ program source files contain identical parts that are placed in files called header files. Instead of typing these parts in every source module, the contents of these files can be copied and pasted in each source module in which they are needed. However, instead of doing this copying and pasting yourself, you can instruct the preprocessor to do it for you by using the preprocessor directive, #include. It has the following syntax: #include <filename> // for header files that come with the compiler Example: #include file-specification // for your own header files #include <iostream> The preprocessor is a program that comes with the C++ compiler software package. It first inserts the content of header files into a program source file before that source file is translated into machine language by the compiler. An example of the processing of the #include directive is shown in figure 1.9. Figure 1.9 Processing the include Directive Suppose that the content of the file myheader.h is as follows: /* myheader.h */ int gnum = 10; int tester ( ); // a new function char letter = A ; And that the content of the file myprog.cpp is as follows: /* myprog.cpp */ #include myheader.h int main( ) int num = 15; int result; result = num + tester( ); cout << endl << The result is: << result; return ( 0 ); The contents of the file myprog.cpp after it has been processed by the preprocessor is as follows: 2017 Gilbert Ndjatou Page 18

19 /* myprog.cpp */ /* myheader.h */ int gnum = 10; int tester ( ); // a new function char letter = A ; int main( ) int num = 15; int result; result = num + tester( ); cout << endl << The result is: << result; return ( 0 ); Exercise 1.6 Suppose that the content of the header file test.h is as follows: /* my header file */ int flag = 0; void tfun( int ); // to perform some tasks int process( int ); /* That s all */ And that the content of the file myprog.cpp is as follows: /* my program file */ #include <test.h> int main() int number, sum; number = 16; sum = number - process( number ); tfun( number ); return ( 0 ); Show the contents of the file myprog.cpp after it has been processed by the preprocessor Gilbert Ndjatou Page 19

20 1.6 Library Functions A C++ compiler comes with a collection of functions that are already translated into machine language. These functions are referred to as library functions and the files in which they are located are called library files A library function may be called in any other function of a program. But it must first be declared before the statement in which it is called. You declare a function by using a declaration statement. Library functions have their declaration statements written into header files that come with the compiler software package. For example, iostream. An example of library function call is illustrated in figure Figure 1.10 Calling a Library Function Given the following program: #include <iostream> // in order to use cin and cout #include <cstdlib.h> // in order to call library function abs using namespace std; int main() int num; /* to hold an integer value */ int result; /* to hold its absolute value */ cout << endl << Enter an integer value please: ; cin >> num; result = abs( num ); cout << endl << Its absolute value is: << result; return (0); The following outputs are produced for the input values 5, and -8, respectively: A. Enter an integer value please: 5 Its absolute value is: 5 B. Enter and integer value please -8 Its absolute value is: Gilbert Ndjatou Page 20

21 Exercise Provide the output of the following program: #include <iostream> #include <cstdlib.h> using namespace std; int main() int num; /* to hold an integer value */ int result; /* to hold the result */ num = -10; result = abs( num ) + 15; cout << endl << The result is: << result; num = 7; result = abs( num ) + 9; cout << endl << The result is: << result; return (0); 2. Find all invalid statements/comments in the following C++ program and also indicate why they are invalid. Line # Statements/Comments 1 // This is a sample program 2 // It reads integer values, performs some computations 3 and prints the results. 4 #include <iostream> 5 using namespace std; 6 int main( ) 7 8 int num1; 9 int num2 = 3; 10 int result1; 11 int result2; 12 cin >> num1; 13 result1 = num1 + 5; /* compute the sum of the value read and 5 */ 14 result2 = num2 + 5; 15 cout << endl << result1 = 16 << result1; 17 num1 = num1 + 10; 18 num2 + 7 = num1; 19 cout << num1; 20 << result1; 21 cout << 15; 22 cin >> num2 + 3; 23 result3 = num1 + 25; 24 return (0); Gilbert Ndjatou Page 21

22 1.7 Processing a C/C++ Language Program The table in figure 1.11 lists the processing steps of a C++ language program. Figure 1.11 Processing Steps of a C++ Language Program Step Action System Program Used File Produced 1 type your program editor source files 2 translate source files into machine language 3 combine object files and library functions called in the program 4 load the executable file in memory and set it up for execution compiler linker loader object files executable file none Exercise Type the program in figure 1.5 into the source file figure-15.cpp and then do the following: - compile and execute your program. 2. Type the program in figure 1.7 into the source file figure-17.cpp and then do the following: - Enter the comment /* Prepared by followed by your name */ at the top of the source file. - compile and execute your program. 3. Type the program in figure 1.8 into the source file figure-18.cpp and then do the following: - Enter the comment /* Prepared by followed by your name */ at the top of the source file. - compile and execute your program. 4. Type the program in figure 1.10 into the source file figure-110.cpp and then do the following: - Enter the comment /* Prepared by followed by your name */ at the top of the source file. - compile and execute your program Gilbert Ndjatou Page 22

23 Exercise 1.9 Fill in the blanks with the most appropriate answers. 1. A is a portion of the main memory that is used to represent (hold) data to be processed in a program. 2. A is a system program that translates a high-level language program into machine language. 3. A file (or module) is created by the compiler to hold the machine language translation of a source file. 4. An receives as input the statements of a program and its input data, executes the statements of that program using its input data, and produces its output. 5. A memory location is represented by a in a high-level language program 6. The of a variable tells the compiler the type of data that will be stored in the corresponding memory location, so that it knows how many bytes to reserve for that memory location. 7. In a high-level language program, a is a note or a remark for a human being reading the program, and is ignored by the compiler. 8. A high-level language program consists of one or more files called. 9. A has a name and consists of a sequence of one or more statements used to perform a specific task. 10. A is a function that comes with the compiler, and that can be called in any program. 11. The is a program that first processes and completes a program source file before it is translated into machine language by the compiler. 12. The combines all the object modules of a program and the machine language translations of library functions called in that program into a file called executable file Gilbert Ndjatou Page 23

Chapter 1 Introduction to Computers and C++ Programming

Chapter 1 Introduction to Computers and C++ Programming Chapter 1 Introduction to Computers and C++ Programming 1 Outline 1.1 Introduction 1.2 What is a Computer? 1.3 Computer Organization 1.7 History of C and C++ 1.14 Basics of a Typical C++ Environment 1.20

More information

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

More information

Introduction. Arizona State University 1

Introduction. Arizona State University 1 Introduction CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 1 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

Chapter 1: Introduction to Computers and Programming

Chapter 1: Introduction to Computers and Programming Chapter 1: Introduction to Computers and Programming 1.1 Why Program? Why Program? Computer programmable machine designed to follow instructions Program instructions in computer memory to make it do something

More information

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program 1 By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program variables. Apply C++ syntax rules to declare variables, initialize

More information

Chapter 1: Why Program? Computers and Programming. Why Program?

Chapter 1: Why Program? Computers and Programming. Why Program? Chapter 1: Introduction to Computers and Programming 1.1 Why Program? Why Program? Computer programmable machine designed to follow instructions Program instructions in computer memory to make it do something

More information

Chapter 1 Introduction to Computers and Programming

Chapter 1 Introduction to Computers and Programming Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming Copyright 2003 Scott/Jones Publishing Contents 1.1 Why Program? 1.2 Computer Systems: Hardware

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information

Lab # 02. Basic Elements of C++ _ Part1

Lab # 02. Basic Elements of C++ _ Part1 Lab # 02 Basic Elements of C++ _ Part1 Lab Objectives: After performing this lab, the students should be able to: Become familiar with the basic components of a C++ program, including functions, special

More information

Computer Programming : C++

Computer Programming : C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program

More information

Chapter 1: Why Program? Main Hardware Component Categories 8/23/2014. Main Hardware Component Categories: Why Program?

Chapter 1: Why Program? Main Hardware Component Categories 8/23/2014. Main Hardware Component Categories: Why Program? Chapter 1: Introduction to Computers and Programming 1.1 Why Program? Why Program? Computer programmable machine designed to follow instructions Program instructions in computer memory to make it do something

More information

CSc Introduction to Computing

CSc Introduction to Computing CSc 10200 Introduction to Computing Lecture 2 Edgardo Molina Fall 2011 - City College of New York Thursday, September 1, 2011 Introduction to C++ Modular program: A program consisting of interrelated segments

More information

1a Computers, Problem Solving!

1a Computers, Problem Solving! 1a Computers, Problem Solving!! 1E3! 1a Computers and Problem Solving 1 Objectives! n To introduce the architecture of a computer.! n To introduce the notion of a programming language.! n To explore computational

More information

BITG 1113: Introduction To Computers And Programming Language LECTURE 1 LECTURE 1 1

BITG 1113: Introduction To Computers And Programming Language LECTURE 1 LECTURE 1 1 BITG 1113: Introduction To Computers And Programming Language LECTURE 1 LECTURE 1 1 Learning Outcomes At the end of this lecture, you should be able to: tell the purpose of computer programs. describe

More information

Chapter 2: Introduction to C++

Chapter 2: Introduction to C++ Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 2.1 Parts of a C++

More information

Lecture 2 Tao Wang 1

Lecture 2 Tao Wang 1 Lecture 2 Tao Wang 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common programming errors

More information

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley

More information

Objectives. In this chapter, you will:

Objectives. In this chapter, you will: Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

More information

Lecture 3 Tao Wang 1

Lecture 3 Tao Wang 1 Lecture 3 Tao Wang 1 Objectives In this chapter, you will learn about: Arithmetic operations Variables and declaration statements Program input using the cin object Common programming errors C++ for Engineers

More information

CHAPTER 3 BASIC INSTRUCTION OF C++

CHAPTER 3 BASIC INSTRUCTION OF C++ CHAPTER 3 BASIC INSTRUCTION OF C++ MOHD HATTA BIN HJ MOHAMED ALI Computer programming (BFC 20802) Subtopics 2 Parts of a C++ Program Classes and Objects The #include Directive Variables and Literals Identifiers

More information

A First Program - Greeting.cpp

A First Program - Greeting.cpp C++ Basics A First Program - Greeting.cpp Preprocessor directives Function named main() indicates start of program // Program: Display greetings #include using namespace std; int main() { cout

More information

Introduction to Programming

Introduction to Programming Introduction to Programming session 5 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2010 These slides are created using Deitel s slides Sahrif University of Technology Outlines

More information

Week 0: Intro to Computers and Programming. 1.1 Why Program? 1.2 Computer Systems: Hardware and Software. Hardware Components

Week 0: Intro to Computers and Programming. 1.1 Why Program? 1.2 Computer Systems: Hardware and Software. Hardware Components Week 0: Intro to Computers and Programming Gaddis: Sections 1.1-3 and 2.1 CS 1428 Fall 2014 Jill Seaman 1.1 Why Program? Computer programmable machine designed to follow instructions Program instructions

More information

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program

More information

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. 1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. B. Outputs to the console a floating point number f1 in scientific format

More information

C++ Support Classes (Data and Variables)

C++ Support Classes (Data and Variables) C++ Support Classes (Data and Variables) School of Mathematics 2018 Today s lecture Topics: Computers and Programs; Syntax and Structure of a Program; Data and Variables; Aims: Understand the idea of programming

More information

CS242 COMPUTER PROGRAMMING

CS242 COMPUTER PROGRAMMING CS242 COMPUTER PROGRAMMING I.Safa a Alawneh Variables Outline 2 Data Type C++ Built-in Data Types o o o o bool Data Type char Data Type int Data Type Floating-Point Data Types Variable Declaration Initializing

More information

Scientific Computing

Scientific Computing Scientific Computing Martin Lotz School of Mathematics The University of Manchester Lecture 1, September 22, 2014 Outline Course Overview Programming Basics The C++ Programming Language Outline Course

More information

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja

More information

2 nd Week Lecture Notes

2 nd Week Lecture Notes 2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++ Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++ 0.1 Introduction This is a session to familiarize working with the Visual Studio development environment. It

More information

LECTURE 02 INTRODUCTION TO C++

LECTURE 02 INTRODUCTION TO C++ PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 02 INTRODUCTION

More information

BITG 1233: Introduction to C++

BITG 1233: Introduction to C++ BITG 1233: Introduction to C++ 1 Learning Outcomes At the end of this lecture, you should be able to: Identify basic structure of C++ program (pg 3) Describe the concepts of : Character set. (pg 11) Token

More information

Understanding main() function Input/Output Streams

Understanding main() function Input/Output Streams Understanding main() function Input/Output Streams Structure of a program // my first program in C++ #include int main () { cout

More information

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program? Intro to Programming & C++ Unit 1 Sections 1.1-4 and 2.1-10, 2.12-13, 2.15-17 CS 1428 Spring 2019 Jill Seaman 1.1 Why Program? Computer programmable machine designed to follow instructions Program a set

More information

Chapter 1: An Overview of Computers and Programming Languages. Objectives. Objectives (cont d.) Introduction

Chapter 1: An Overview of Computers and Programming Languages. Objectives. Objectives (cont d.) Introduction Chapter 1: An Overview of Computers and Programming Languages Objectives Objectives (cont d.) In this chapter, you will: Learn about different types of computers Explore hardware and software Learn about

More information

CS1500 Algorithms and Data Structures for Engineering, FALL Virgil Pavlu, Jose Annunziato,

CS1500 Algorithms and Data Structures for Engineering, FALL Virgil Pavlu, Jose Annunziato, CS1500 Algorithms and Data Structures for Engineering, FALL 2012 Virgil Pavlu, vip@ccs.neu.edu Jose Annunziato, jannunzi@gmail.com Rohan Garg Morteza Dilgir Huadong Li cs1500hw@gmail.com http://www.ccs.neu.edu/home/vip/teach/cpp_eng/

More information

The C++ Language. Arizona State University 1

The C++ Language. Arizona State University 1 The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols. EEE-117 COMPUTER PROGRAMMING Basic Elements of C++ Objectives General Questions Become familiar with the basic components of a C++ program functions, special symbols, and identifiers Data types Arithmetic

More information

Fundamentals of Programming CS-110. Lecture 2

Fundamentals of Programming CS-110. Lecture 2 Fundamentals of Programming CS-110 Lecture 2 Last Lab // Example program #include using namespace std; int main() { cout

More information

CS2141 Software Development using C/C++ C++ Basics

CS2141 Software Development using C/C++ C++ Basics CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short

More information

Introduction to Programming EC-105. Lecture 2

Introduction to Programming EC-105. Lecture 2 Introduction to Programming EC-105 Lecture 2 Input and Output A data stream is a sequence of data - Typically in the form of characters or numbers An input stream is data for the program to use - Typically

More information

REVIEW. The C++ Programming Language. CS 151 Review #2

REVIEW. The C++ Programming Language. CS 151 Review #2 REVIEW The C++ Programming Language Computer programming courses generally concentrate on program design that can be applied to any number of programming languages on the market. It is imperative, however,

More information

Review for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure

Review for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure Computer Systems Computer System Computer Structure C++ Environment Imperative vs. object-oriented programming in C++ Input / Output Primitive data types Software Banking System Compiler Music Player Text

More information

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key Starting Out with C++ Early Objects 9th Edition Gaddis TEST BANK Full clear download (no formatting errors) at: https://testbankreal.com/download/starting-c-early-objects-9thedition-gaddis-test-bank/ Starting

More information

Introduction to C++ Programming. Adhi Harmoko S, M.Komp

Introduction to C++ Programming. Adhi Harmoko S, M.Komp Introduction to C++ Programming Adhi Harmoko S, M.Komp Machine Languages, Assembly Languages, and High-level Languages Three types of programming languages Machine languages Strings of numbers giving machine

More information

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance. 2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

More information

Chapter 2: Overview of C++

Chapter 2: Overview of C++ Chapter 2: Overview of C++ Problem Solving, Abstraction, and Design using C++ 6e by Frank L. Friedman and Elliot B. Koffman C++ Background Introduced by Bjarne Stroustrup of AT&T s Bell Laboratories in

More information

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming

More information

Full file at C How to Program, 6/e Multiple Choice Test Bank

Full file at   C How to Program, 6/e Multiple Choice Test Bank 2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)

More information

UEE1302 (1102) F10: Introduction to Computers and Programming

UEE1302 (1102) F10: Introduction to Computers and Programming Computational Intelligence on Automation Lab @ NCTU Learning Objectives UEE1302 (1102) F10: Introduction to Computers and Programming Programming Lecture 00 Programming by Example Introduction to C++ Origins,

More information

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable Basic C++ Overview C++ is a version of the older C programming language. This is a language that is used for a wide variety of applications and which has a mature base of compilers and libraries. C++ is

More information

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space. Chapter 2: Problem Solving Using C++ TRUE/FALSE 1. Modular programs are easier to develop, correct, and modify than programs constructed in some other manner. ANS: T PTS: 1 REF: 45 2. One important requirement

More information

Getting started with C++ (Part 2)

Getting started with C++ (Part 2) Getting started with C++ (Part 2) CS427: Elements of Software Engineering Lecture 2.2 11am, 16 Jan 2012 CS427 Getting started with C++ (Part 2) 1/22 Outline 1 Recall from last week... 2 Recall: Output

More information

Creating a C++ Program

Creating a C++ Program Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an

More information

Chapter 3 Problem Solving and the Computer

Chapter 3 Problem Solving and the Computer Chapter 3 Problem Solving and the Computer An algorithm is a step-by-step operations that the CPU must execute in order to solve a problem, or to perform that task. A program is the specification of an

More information

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.1

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.1 Superior University Department of Electrical Engineering CS-115 Computing Fundamentals Experiment No.1 Introduction of Compiler, Comments, Program Structure, Input Output, Data Types and Arithmetic Operators

More information

Introduction to Programming using C++

Introduction to Programming using C++ Introduction to Programming using C++ Lecture One: Getting Started Carl Gwilliam gwilliam@hep.ph.liv.ac.uk http://hep.ph.liv.ac.uk/~gwilliam/cppcourse Course Prerequisites What you should already know

More information

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

CSC 126 FINAL EXAMINATION FINAL Spring 2012 B. Name (last, First) Instructor. Total Possible. Received

CSC 126 FINAL EXAMINATION FINAL Spring 2012 B. Name (last, First) Instructor. Total Possible. Received CSC 126 FINAL EXAMINATION FINAL Spring 2012 B Name (last, First) Instructor Question # Total Possible Total Received 1. 8 2. 8 3. 8 4. 14 5. 18 6. 10 7. 16 8. 18 TOTAL 100 Final Exam/ Page 2 1) (8 points)

More information

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100 CSC 126 FINAL EXAMINATION Spring 2011 Version A Name (Last, First) Your Instructor Question # Total Possible 1. 10 Total Received 2. 15 3. 15 4. 10 5. 10 6. 10 7. 10 8. 20 TOTAL 100 Name: Sp 11 Page 2

More information

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm.

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm. CHAPTER 1&2 OBJECTIVES After completing this chapter, you will be able to: Understand the basics and Advantages of an algorithm. Analysis various algorithms. Understand a flowchart. Steps involved in designing

More information

EKT 120/4 Computer Programming KOLEJ UNIVERSITI KEJURUTERAAN UTARA MALAYSIA

EKT 120/4 Computer Programming KOLEJ UNIVERSITI KEJURUTERAAN UTARA MALAYSIA EKT 120/4 Computer Programming KOLEJ UNIVERSITI KEJURUTERAAN UTARA MALAYSIA AZUWIR MOHD NOR ROOM: Pusat Pengajian CABIN C PHONE: (04) 979 8249 Email: azuwir@kukum.edu.my Office hours: make appoinment or

More information

Chapter 2. Outline. Simple C++ Programs

Chapter 2. Outline. Simple C++ Programs Chapter 2 Simple C++ Programs Outline Objectives 1. Building C++ Solutions with IDEs: Dev-cpp, Xcode 2. C++ Program Structure 3. Constant and Variables 4. C++ Operators 5. Standard Input and Output 6.

More information

Topics. Hardware and Software. Introduction. Main Memory. The CPU 9/21/2014. Introduction to Computers and Programming

Topics. Hardware and Software. Introduction. Main Memory. The CPU 9/21/2014. Introduction to Computers and Programming Topics C H A P T E R 1 Introduction to Computers and Programming Introduction Hardware and Software How Computers Store Data Using Python Introduction Computers can be programmed Designed to do any job

More information

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++ DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++ Objective: To Learn Basic input, output, and procedural part of C++. C++ Object-orientated programming language

More information

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE Instructor: Final Exam Fall 2014

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE Instructor: Final Exam Fall 2014 The American University in Cairo Computer Science & Engineering Department CSCE 1001 Instructor: Final Exam Fall 2014 Last Name :... ID:... First Name:... Form I- Section No. ( ) EXAMINATION INSTRUCTIONS

More information

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004 GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004 Functions and Program Structure Today we will be learning about functions. You should already have an idea of their uses. Cout

More information

Introduction to the C++ Programming Language

Introduction to the C++ Programming Language LESSON SET 2 Introduction to the C++ Programming Language OBJECTIVES FOR STUDENT Lesson 2A: 1. To learn the basic components of a C++ program 2. To gain a basic knowledge of how memory is used in programming

More information

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq CS 241 Computer Programming Introduction Teacher Assistant Hadeel Al-Ateeq 1 2 Course URL: http://241cs.wordpress.com/ Hadeel Al-Ateeq 3 Textbook HOW TO PROGRAM BY C++ DEITEL AND DEITEL, Seventh edition.

More information

Tutorial-2a: First steps with C++ programming

Tutorial-2a: First steps with C++ programming Programming for Scientists Tutorial 2a 1 / 18 HTTP://WWW.HEP.LU.SE/COURSES/MNXB01 Introduction to Programming and Computing for Scientists Tutorial-2a: First steps with C++ programming Programming for

More information

Your First C++ Program. September 1, 2010

Your First C++ Program. September 1, 2010 Your First C++ Program September 1, 2010 Your First C++ Program //*********************************************************** // File name: hello.cpp // Author: Bob Smith // Date: 09/01/2010 // Purpose:

More information

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++ CSCE 206: Structured Programming in C++ 2017 Spring Exam 1 Monday, February 13, 2017 Total - 100 Points A Instructions: Total of 11 pages, including this cover and the last page. Before starting the exam,

More information

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++ CSCE 206: Structured Programming in C++ 2017 Spring Exam 1 Monday, February 13, 2017 Total - 100 Points B Instructions: Total of 11 pages, including this cover and the last page. Before starting the exam,

More information

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018 C++ Basics Lecture 2 COP 3014 Spring 2018 January 8, 2018 Structure of a C++ Program Sequence of statements, typically grouped into functions. function: a subprogram. a section of a program performing

More information

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program Overview - General Data Types - Categories of Words - The Three S s - Define Before Use - End of Statement - My First Program a description of data, defining a set of valid values and operations List of

More information

Programming. C++ Basics

Programming. C++ Basics Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++

More information

Chapter 4 - Notes Control Structures I (Selection)

Chapter 4 - Notes Control Structures I (Selection) Chapter 4 - Notes Control Structures I (Selection) I. Control Structures A. Three Ways to Process a Program 1. In Sequence: Starts at the beginning and follows the statements in order 2. Selectively (by

More information

Basic Computer Programming for ISNE. Santi Phithakkitnukoon ผศ.ดร.ส นต พ ท กษ ก จน ก ร

Basic Computer Programming for ISNE. Santi Phithakkitnukoon ผศ.ดร.ส นต พ ท กษ ก จน ก ร 269102 Basic Computer Programming for ISNE Santi Phithakkitnukoon ผศ.ดร.ส นต พ ท กษ ก จน ก ร Syllabus Instructor: Asst. Prof. Dr. Santi Phithakkitnukoon ผศ.ดร.ส นต พ ท กษ ก จน ก ร (อ.เอ ม) Office room:

More information

CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING. Dr. Shady Yehia Elmashad

CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING. Dr. Shady Yehia Elmashad CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING Dr. Shady Yehia Elmashad Outline 1. Introduction to C++ Programming 2. Comment 3. Variables and Constants 4. Basic C++ Data Types 5. Simple Program: Printing

More information

Chapter 1 & 2 Introduction to C Language

Chapter 1 & 2 Introduction to C Language 1 Chapter 1 & 2 Introduction to C Language Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 1 & 2 - Introduction to C Language 2 Outline 1.1 The History

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char Week 1 Operators, Data Types & I/O Gaddis: Chapters 1, 2, 3 CS 5301 Fall 2016 Jill Seaman Programming A program is a set of instructions that the computer follows to perform a task It must be translated

More information

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1 NAGERCOIL COMPUTER SCIENCE Grade: IX C++ PROGRAMMING 1 C++ 1. Object Oriented Programming OOP is Object Oriented Programming. It was developed to overcome the flaws of the procedural approach to programming.

More information

A Freshman C++ Programming Course

A Freshman C++ Programming Course A Freshman C++ Programming Course Dr. Ali H. Al-Saedi Al-Mustansiria University, Baghdad, Iraq January 2, 2018 1 Number Systems and Base Conversions Before studying any programming languages, students

More information

I/O Streams and Standard I/O Devices (cont d.)

I/O Streams and Standard I/O Devices (cont d.) Chapter 3: Input/Output Objectives In this chapter, you will: Learn what a stream is and examine input and output streams Explore how to read data from the standard input device Learn how to use predefined

More information

Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3

Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3 Programming - 1 Computer Science Department 011COMP-3 لغة البرمجة 1 011 عال- 3 لطالب كلية الحاسب اآللي ونظم المعلومات 1 1.1 Machine Language A computer programming language which has binary instructions

More information

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

Chapter 1: Introduction to Computers and Java

Chapter 1: Introduction to Computers and Java Chapter 1: Introduction to Computers and Java Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 1 discusses the following main topics:

More information

Chapter 2 Basic Elements of C++

Chapter 2 Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion

More information

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java Chapter 1: Introduction to Computers and Java Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 1 discusses the following main topics:

More information