Math2220 Lecture 1

Computer and Computer programs

Elements of Hardware

Software

Software Development

Example:

Question: Calculate the increase percentage of the tuition fee.

Problem specification

Design and Implementation

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<iostream>
using namespace std;

void 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";
    
    char line[100];
    cin.getline(line,100);
    cin.getline(line,100);

} 

Here is the output of the program
Please enter last year's tuition fee: 42310
Please enter this year's tuition fee: 45678
The tuition increases 7.96029%.

Building(Compiling and linking)

Testing/Debugging, Maintenance, and Documentation

Compiler and Syntax Error

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
void main() {
   
               <----------------- fill your codes here

}

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.