## PIC10A Lecture 1

Section 1.1

### Computer and Computer programs

• OR "Hardware of Software
• Hardware consists of the physical components of the system.
• Software consists of programs that control the hardware to solve a problem,

### Elements of Hardware

• Central Processing Unit(CPU)
• Memory (including RAM)
• Input/Output Device(keyboard, mouse, monitor, printer, etc etc)

### Software

• Programs are written using an unambigous computer langauge
• Low level: assembly language, machine
• High level: C++, java
• PIC10A will mainly deal with software written in C++

### Software Development

• Problem specification(information and goals)
• Design(data structure, algorithms)
• Implementation(coding)
• Testing/debugging
• Maintenance

### Example:

Question: Calculate the increase percentage of the tuition fee.

### Problem specification

• What do you know? (this year's tuition fee, last year's tuition fee)
• What do you want? (the increase percentage)

### Design and Implementation

• Data Structures
• Algorithms(unambiguous directions that use the data structure to solve the problem)
• Consists of translating pseudocode into a computer language

### Pseudocode for the example

1. Input this year's tuition fee
2. Input last year's tuition fee
3. calculate the increase precentage by the formula
4.   increasePercentage = (last year's tuition fee - this year's tuition fee)/(last year's tuition fee)  times 100%
5. output the result
Here is the code

 ```#include using namespace std; int main() {     double thisYearFee, lastYearFee, percentage;         cout << "Please enter last year's tuition fee: ";     cin >> lastYearFee;     cout << "Please enter this year's tuition fee: ";     cin >> thisYearFee;     percentage = (thisYearFee - lastYearFee)/lastYearFee;     cout << "The tuition increases " << percentage*100 << "%.\n";     return 0; }```

Here is the output of the program
 Please enter last year's tuition fee: 1233       Please enter this year's tuition fee: 1459 The tuition increases 18.3293%.

• Compiling translate high-level code to a langauge the computer understands
• Likings adds in the tools used, but didn't define(e.g. cout)

### Testing/Debugging, Maintenance, and Documentation

• On first attemps roughly 99.9999999% of all codes have mistakes
• Can be syntax and logical
• Maintenance keeps things up-to-date
• Documentation ensures others can use your program

### Compiler and Syntax Error

• You can think of the compiler as a very strict English teacher. If you make any typographical errors or use any errant punctuation, you will be told about this in no uncertain terms.
• Syntax errors: these are where the compiler expects a particular set of symbols and you provide something that is not expected.
• For example, in the above program,  instead of
``double thisYearFee, lastYearFee, percentage;``
You type
``doule thisYearFee, lastYearFee, percentage; ``
``(The image is for Visual C++)``

## Explanation of the program

```#include<iostream>     /_____________ these two lines are included using namespace std;   \               so that the libaries about input/output                                        are available to the program int main() {                    <----------------- fill your codes here     return 0; } ```
Code
Explanation
```double thisYearFee, lastYearFee, percentage;``` declare 3 decimal numbers
```cout << "Please enter last year's tuition fee: ";``` cout <<"blah blah blah";
outputs blah blah blah on the screen
`cin >> lastYearFee;` cin >> x;  asks the user to input a value.
The value will be stored in a variable named x.
``` ```