Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce.

Similar presentations


Presentation on theme: "Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce."— Presentation transcript:

1

2 Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce the fundamental hardware and software components of a computer system To describe the role of compilers in high-level programming To describe the role of compilers in high-level programming To examine the use of algorithms in program design To examine the use of algorithms in program design To define the software life cycle To define the software life cycle To introduce the C++ programming language To introduce the C++ programming language

3 Chapter 1CS 140Page 2 Computer Hardware

4 Chapter 1CS 140Page 3 Key ‘P’ struck Computer Software Hardware Direct access to circuitry, disks, mouse, keyboard, monitor, etc. Operating System Software that relays messages between application and hardware Application Software that performs high level operations (computation, graphics, etc.) “Hey, OS! key ‘P’!” “Hey, App! key ‘P’!” Send explosion sound to speaker and new pixel values to monitor Contact sound & graphics cards Specify resulting audio & video

5 Chapter 1CS 140Page 4 Low-Level Programming Languages A computer processor is not smart! Its vocabulary is limited to a simple “machine language” consisting of a small number of simple commands. Move this number over there! Move that number over here! Add this number to that number! Check to see if this number is zero!

6 Chapter 1CS 140Page 5 Programming To get the computer to perform sophisticated operations, the programmer writes programs that tell the processor the sequence of primitive steps to take to get a result. 0010010101101010 1010101010101010 0001111110011100 1011110000011010 1001001011101010 0010100100001101 0110010101001101 0110010101001010 1001010010101011 0100101010001001 0101010101010101 0101001010101001 Programming in machine language is a binary pain, so higher level languages have been developed to make the job of the programmer more efficient and more effective!

7 Chapter 1CS 140Page 6 Compiling a High-Level Program A program caller a “compiler” is used to translate your “source program” (in a language like C++) into an “object program” (in your system’s machine language). #include using namespace std; void main() { int x, y; cout << “Enter two integers: ”; cin >> x >> y; if (x > y) cout << x << “ is the largest!”; else cout << y << “ is the largest!”; } LEXICAL ANALYSIS Split the source program into words like “void”, “x”, “>”, and “;”. PARSING Analyze the grammatical syntax of the source program (e.g., “if (x > y)” makes sense, but “if (x > ) y” doesn’t).CODEGENERATION Generate an equivalent program in machine language. 110101000101100011000 010010110110100010101 011110010101011100000 010011100101011001110 101010111001010100101 010101000000110110111 011101010100111110101 010101001001001010000 010101010101000000101 111100101100001011101 010101010100010101111 110010100100100101000 Source Program Object Program

8 Chapter 1CS 140Page 7 Linking and Loading After being compiled, the object program must be “linked” (i.e., connected to other compiled code from libraries, like math functions or input/output operators) and then “loaded” into main memory for execution. SourceProgramObjectProgram LinkedProgram CompiledLibraryPrograms COMPILE LINK LOAD

9 Chapter 1CS 140Page 8 Algorithms After defining a problem that the programmer wants the computer to solve, the programmer must first design an algorithm, a sequence of precise instructions that lead to a solution. Problem: Find the largest value in a list of numbers. Algorithm: 1) Retrieve the list of numbers. 2) Consider the first number the largest value so far. 3) Starting at the second number in the list, compare the number in the list to the largest value so far; if it’s larger, then make it the largest value so far. 4) After examining all of the numbers, announce the largest value so far - it’s the largest in the list!. 47 28 56 61 30 19 47 56 61 47 56 ? ? ? ? ? 61 LARGEST!

10 Chapter 1CS 140Page 9 Another Algorithm Problem: Find the phone number of a specific person in an alphabetized phonebook. Algorithm: 1) Get the phonebook. 2) Crack what’s left of the phonebook open to the middle page. 3) Check to see if the name you’re seeking is on that page. If so, announce the phone number and you’re done!. Otherwise, throw away the “impossible” half of the phonebook, and repeat the process, starting at step #2. 4) If the entire phonebook is ever thrown out, then the person is unlisted!

11 Chapter 1CS 140Page 10 The Software Life Cycle Specification Clearly state the purpose of the software, including full details of the problem being solved. Design Develop a solution to the problem, modularizing it and determining specific pre- and post-conditions. Coding Program the modules using a bottom- up approach (with dummy drivers) or a top-down approach (with stubs). Testing Design test scenarios for individual modules, interaction between modules, and the entire program. Maintenance Respond to “bugs” and “sugs”, and determine when the software has become obsolete. DOCUMENTATION!!!

12 Chapter 1CS 140Page 11 Introduction to C++ Ancient Languages Fortran - Great for scientific computations COBOL - Great for business file processing Very special purpose, not good in general Old Languages C - General purpose language for UNIX systems Pascal - General purpose language for PCs Emphasis upon procedures instead of data Modern Languages C++ - Object-oriented version of C Java - Object-orientation with networking emphasis Emphasis upon the objects being manipulated

13 Chapter 1CS 140Page 12 A Sample C++ Program #include // This library facilitates input & output. #include // This library enables math functions, like sqrt. using namespace std;// Assigns the program to a specific namespace. void main()// Every C++ program must have a "main" function. {// Opening brace to contain main's statements. int nbr;// Declare variable "nbr" to be an integer. double root;// Declare variable "root" to be a long real number. nbr = 2;// Set value of nbr to be 2. root = sqrt(nbr);// Calculate square root of nbr. cout << "The square root of "// Output a message to the memory file << nbr << " is " << root// associated with the monitor (i.e., cout), << endl << endl;// including nbr, root, and a skipped line. cout << "Enter a number: ";// Ask the user for a value for nbr. cin >> nbr;// Input from the file associated with the keyboard (cin). root = sqrt(nbr);// Calculate the square root of nbr's new value. cout << "The square root of "// Output a message to the cout file << nbr << " is " << root// concerning the values of nbr and root, << endl << endl << endl;// followed bt two skipped lines. return;// Terminate the program's execution. }// Closing brace to indicate end of main function.


Download ppt "Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce."

Similar presentations


Ads by Google