Download presentation
Presentation is loading. Please wait.
1
Reminders Please turn off cell phones.
No food or soft drinks in the classroom. Stow water bottles at floor level.
2
Introduction Without software, the computer is useless.
Software is developed with programming languages. C++ is one of the most popular programming languages. TIOBE Index IEEE Top 10 Programming Languages for 20176 PYPL Index C++ is suited for a wide variety of programming tasks. C++ Programming: From Problem Analysis to Program Design, Seventh Edition
3
C++ Versus C C++ evolved from C, and you can think of C as being a subset of C++. Most of this course will focus on material that is common to C++ and C. Other popular languages that evolved from C include Java, C#, Objective-C. C++ C
4
Elements of a Computer System
Hardware CPU Main memory Secondary storage Input/Output devices Software C++ Programming: From Problem Analysis to Program Design, Seventh Edition
5
Central Processing Unit and Main Memory
Brain of the computer Most expensive piece of hardware Carries out arithmetic and logical operations C++ Programming: From Problem Analysis to Program Design, Seventh Edition
6
Central Processing Unit and Main Memory (cont’d.)
Directly connected to the CPU All programs must be loaded into main memory before they can be executed. All data must be brought into main memory before it can be manipulated. When computer power is turned off, everything in main memory is lost. C++ Programming: From Problem Analysis to Program Design, Seventh Edition
7
Central Processing Unit and Main Memory (cont’d.)
Main memory is an ordered sequence of memory cells. Each cell has a unique location in main memory, called the address of the cell. Each cell can contain either a programming instruction or data. C++ Programming: From Problem Analysis to Program Design, Seventh Edition
8
Secondary Storage Secondary storage: device that stores information permanently. Examples of secondary storage: Hard disks Flash drives CDs & DVDs Tapes C++ Programming: From Problem Analysis to Program Design, Seventh Edition
9
Input/Output Devices Input devices feed data and programs into computers. Keyboard Mouse Output devices display results. Monitor Printer C++ Programming: From Problem Analysis to Program Design, Seventh Edition
10
Software Software: programs that do specific tasks.
System programs control the computer. Operating system (such as Windows or macOS) monitors the overall activity of the computer and provides services such as: Memory management Input/output activities Storage management Application programs perform a specific task for the user. Word processors Spreadsheets Games C and C++ are well-suited for both kinds of programs. C++ Programming: From Problem Analysis to Program Design, Seventh Edition
11
The Language of a Computer
Digital devices (computers, iPods, cell phones, …) use binary code to represent information. This means they store all information (numbers, text, images, music, …) as sequences of 0s and 1s. Each 0 or 1 in such a sequence is called a bit (short for binary digit). Example of an 8-bit sequence: A typical song in an MP3 file might contain 40 million bits.
12
The Language of a Computer (cont’d.)
Byte: A sequence of eight bits Kilobyte (KB): 210 bytes = 1024 bytes Table 1-1 on page 6 (next slide) shows some other related terms. This is useful general information, but not critical to what we’ll do in this course. C++ Programming: From Problem Analysis to Program Design, Seventh Edition
13
The Language of a Computer (cont’d.)
C++ Programming: From Problem Analysis to Program Design, Seventh Edition
14
The Evolution of Programming Languages
Early computers were programmed in machine language, which required the programmer to type sequences of 0s and 1s. Example: to calculate wages = rate * hours in machine language, you might type: //Load //Multiply //Store C++ Programming: From Problem Analysis to Program Design, Seventh Edition
15
The Evolution of Programming Languages (cont’d.)
Assembly language replaces sequences of 0s and 1s with mnemonics (abbreviations such as LOAD or MULT). Example: Using assembly language instructions, wages = rate * hours might be typed as: LOAD rate MULT hour STOR wages C++ Programming: From Problem Analysis to Program Design, Seventh Edition
16
The Evolution of Programming Languages (cont’d.)
High-level languages include Basic, FORTRAN, COBOL, Pascal, C, C++, Java, C#, and Python. Programs written in these language look much more like English. The equation wages = rate * hours can be written in C++ as: wages = rate * hours; Compiler: translates a program written in a high-level language into machine language. C++ Programming: From Problem Analysis to Program Design, Seventh Edition
17
Microsoft Visual Studio
In this course you’ll use Microsoft Visual Studio Community 2015 to enter, run, and test your programs. This is a free version of Visual Studio that you can install at home. Instructions on course website. It’s powerful, complex software used by professional programmers. On campus, it’s on the computers in the EET Resource Center (room 1-242H) and on some computers in the library.
18
Signing in to Microsoft Visual Studio
Visual Studio is free, but to use it you must have a Microsoft account. If you don’t already have one, go to
19
Development Settings and Color Theme
The first time you use Visual Studio, you’ll see the following dialog box. Change the Development Settings from General to Visual C++. To change development settings later, Tools > Import and Export Settings… > Reset all settings > No> Visual C++. To change color them later, Tools > Options > Environment > General > Color theme.
20
A Simple C++ Program //******************************************************** // Name: Week1FirstProgram // Author: Nick Reeder // Date: 07/13/2015 // This program computes and displays wages, based on // hard-coded values for hourly rate and number of hours. #include <iostream> using namespace std; int main() { int rate = 15; int hours = 40; int wages = rate * hours; cout << wages << "\n"; return 0; } Have them create new project named Week1FirstProgram (console app, empty project), then enter and run it, starting with couting 15*40, then adding variable names, then adding program title block. Also show some of the many errors that can occur (misspelled variable name, missing semicolon, no 0 after return…). C++ Programming: From Problem Analysis to Program Design, Seventh Edition
21
Title Block //******************************************************** // Name: Week1FirstProgram // Author: Nick Reeder // Date: 07/13/2015 // This program computes and displays wages, based on // hard-coded values for hourly rate and number of hours. Each program should contain a title block listing the program’s name, your name, the date, and a description that uses proper spelling and grammar. At a minimum, the description should say what input values the user is expected to provide, and what output values the program will produce. Use as many lines as needed for the description so that you can read it without scrolling to the right.
22
Finding Your Files in Windows
Here is the file that contains the source code that you typed. Have them close Visual Studio to find these files.
23
Displaying the File Extensions in Windows
To make Windows 7 display file extensions, select Tools > Folder Options… > View, then remove the check mark next to Hide extensions for known file types.
24
Caution: Be Sure to Open the Right File
To resume work on an existing program, one way is by double-clicking a file in Windows, without first opening Visual Studio. But you must double-click either the solution file (Week1FirstProgram.sln) or the project file (Week1FirstProgram.vcxproj), not the source-code file (Week1FirstProgram.cpp). Show them different ways to re-open the project in Visual Studio.
25
Parentheses, Braces, and Brackets
C++ uses the following symbols to enclose code: Parentheses ( ) Braces { } Square brackets [ ] Angle brackets < > Each pair of symbols has a specific use. They are not interchangeable. For example, you can’t use parentheses where you’re supposed to use braces.
26
Processing a C++ Program
C++ Programming: From Problem Analysis to Program Design, Seventh Edition
27
Processing a C++ Program (cont’d.)
Steps in processing a C++ program: Use an editor to create source code in C++. Preprocessor directives begin with # and are processed by the preprocessor. Compiler: Checks that the program obeys the language rules. Translates into machine language (object program). C++ Programming: From Problem Analysis to Program Design, Seventh Edition
28
Processing a C++ Program (cont’d.)
Steps in processing a C++ program (cont’d.): Linker: Combines object program with other files to create executable code. Library: contains prewritten code you can use. Loader: Loads executable program into main memory. The last step is to execute the program. C++ Programming: From Problem Analysis to Program Design, Seventh Edition
29
Integrated Development Environement
In the old days you might need several computer programs to perform all of the steps listed above. But Visual Studio combines all of these into a single program. It’s an example of an Integrated Development Environment (IDE). Steps 2 through 6 on the previous slides take place when you press Ctrl+F5. Another popular free C++ IDE is Bloodshed’s Dev-C++ at
30
Programming with the Analysis–Coding–Execution Cycle
An algorithm is a step-by-step process for solving a specific type of problem. Programming is a process of problem solving. C++ Programming: From Problem Analysis to Program Design, Seventh Edition
31
The Problem Analysis–Coding–Execution Cycle (cont’d.)
Step 1: Analyze the problem. Outline the problem and its requirements. Design steps (algorithm) to solve the problem. Step 2: Implement the algorithm. Implement the algorithm in code. Verify that the algorithm works. Step 3: Maintain. Use and modify the program if the problem domain changes. C++ Programming: From Problem Analysis to Program Design, Seventh Edition
32
Example 1-1 Design an algorithm to find the perimeter and area of a rectangle. The perimeter and area of the rectangle are given by the following formulas: perimeter = 2 * (length + width) area = length * width C++ Programming: From Problem Analysis to Program Design, Seventh Edition
33
Example 1-1 (cont’d.) Algorithm: Get length of the rectangle.
Get width of the rectangle. Find the perimeter using the following equation: perimeter = 2 * (length + width) Find the area using the following equation: area = length * width C++ Programming: From Problem Analysis to Program Design, Seventh Edition
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.