You are on page 1of 3

Lecture1

1 of 3

http://www.charlesli.org/pic10a/lectures/lecture1/index.html

PIC10A Lecture 1

Reading

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)
Building(compiling and linking)
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)
10/12/2015 3:56 PM

Lecture1

2 of 3

http://www.charlesli.org/pic10a/lectures/lecture1/index.html

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
increasePercentage = (last year's tuition fee - this year's tuition fee)/(last year's tuition fee) times 100%
4. output the result

Here is the code

#include<iostream>
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%.

Building(Compiling and linking)


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
10/12/2015 3:56 PM

Lecture1

3 of 3

http://www.charlesli.org/pic10a/lectures/lecture1/index.html

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>
using namespace std;
int main() {

/_____________ these two lines are included


\
so that the libaries about input/output
are available to the program

<----------------- fill your codes here


}

return 0;

Code

Explanation

cout << "Please enter last year's tuition fee: ";

cout <<"blah blah blah";


outputs blah blah blah on the screen

double thisYearFee, lastYearFee, percentage;

cin >> lastYearFee;

declare 3 decimal numbers

cin >> x; asks the user to input a value.


The value will be stored in a variable named x.

10/12/2015 3:56 PM

You might also like