POS/370

Programming Concepts Using C++

Week 1 Newsletter (E. Nikjeh)

 

Hello Class,

The basic concepts that we’ll be learning are applicable to any programming language. The syntax and structure may be different amongst the different languages, but the concepts are the same.

If you don’t understand a topic after we’ve covered it in the class, please ask and also feel free to call me or send me an e-mail to help clarify subjects, so use me as an additional resource.

Programmer and Analysts:

The systems analysts deliver their product (A technology-independent statement of the requirements of the system) to the system designers and they deliver their product (An architectural description of the hardware and software components that will be used to implement the system) to the programmer.

 

Program Life Cycle Development:

1-     Analyze: Define the problem and all users’ requirements (Problem specifications).

2-     Design: Plan the solution to the problem.

3-     Planning: Algorithm, Flowchart, and Pseudo-code.

4-     Implementation (Coding): Translate the algorithm into a programming language like (C++).

5-     Test and debug: Give sample input to get expected output. Locate and remove any errors in the program and run it again.

6-     Maintenance: Upgrade and modification (We need a good documentation for this phase).

 

Procedural and OOP Languages:

1-     In a procedural language such as C or Pascal, the modules are procedures. A procedure is a sequence of statements such as assignment statements, tests, loops, and sub-procedure. The design technique is top-down design e.g. Building an automobile (To decompose the problem to smaller problems).

2-     In the object oriented languages, the data and the operations that manipulate the data (Method) are both contained in the object. An O-O program is a collection of objects. The most advantage is code reusability. So we don’t have to reinvent the wheel again. All OOP languages share three common attributes: 1- Encapsulation (Data and method together) 2- Polymorphism (Means many forms, one name to be used for two or more related but technically different purposes.) 3- Inheritance (One object can acquire the properties of another. A class is a blueprint for an object. A class will be used to create an object. An object is made up of the data (attribute) and behavior (Method). For example a cookie cutter is a class of cookies and cookies are objects. So with cookie cutter we can make objects (cookies).

 

 

 

 

Interpretive and Compiled Languages:

Compiler translates entire program into machine code (0s and 1s) before running e.g. C, C++ languages are compiled languages.

Interpreter translates statements into machine code as they occur e.g. BASIC, HTML, and JAVA SCRIPT. It is real-time compiler. Interpreters are 10 to 100 times slower. JAVA is compiled and interpreted language. Compiler first translates JAVA program to JAVA Byte Code and then JAVA Virtual Machine interprets it. So it is platform independent and can be run on different hardware and operating systems.

 

History of Programming Languages:

The first programs were created by a process of toggling switches on the front panel of the computer (1800s). 1st generation is Machine Code: For example, adding two numbers

                                               1)         1010    11001

                                               2)         1011    11010

                                               3)         1100    11011

2nd generation is Assembler: Grace M. Hopper invented Assembly language in 1940, which allowed longer programs to be written:

1)                  LOAD Y

2)                  ADD    Z

3)                  STR     X

X = Y + Z

3rd generation is High-level (FORTRAN, COBOL 1950s): A programmer was able to write programs that were several thousands of lines long. This is fine for relatively short programs.

                                                            X = Y + Z

4th generation is Non-procedural and Object Oriented Languages like C++ (By Bjarne Stroustrup in the early 1980s at Bell Laboratories) good for development of application software. Visual Basic (1992)– Windows user interfaces. JAVA (1995)- Web applications.

Trends of Programming Languages:

1-     Low level to high level

2-     Machine-specific to platform independent

3-     Difficult to more easy coding

4-     High to lower error rate

5-     Text to graphical user interface (GUI)

6-     Sequential to event driven

7-     Procedural to non-procedural to object-oriented

8-     Conventional to rapid application

 

Flowchart: Graphically shows the logical steps to carry out a task and shows how the steps relate to each other. A table of flowchart symbols by ANSI (American National Standard Institute) was handed out in the class.                                                           

 

 

 

            Flowchart Good Points:

1-     See all steps of algorithm.

2-     We process one symbol at a time.

3-     Simple

Flowchart Bad Points:

1-     Rarely actually used.

2-     Horrible for redraw and to modify.

3-     Many algorithms that can be flowcharted can be visualized in your head.

 

Pseudocode: Steps, in English-like phrases needed to solve a problem. It looks like computer code and programmers use it all the time. Very sophisticated algorithms are described in pseudocode. Some pseudocode uses language keywords like print. Pseudocode can be directly translated to code.

 

Algorithm: A procedure for solving a problem in terms of

1-     The actions to be executed and

2-     The order in which these actions are to be executed is called an Algorithm.

Example: Rise and Shine algorithm for getting out of bed and going to work.

1-     Get out of bed

2-     Take off pajamas

3-     Take a shower

4-     Get dressed

5-     Eat breakfast

6-     Carpool to work ( Another example in page 39 of your text book)

Control Structures: All computer programs need to have a structure that allows for processing statements in a given order. Statements in a program are executed one after the other in order in which they are written (Sequential execution). Control Structures are:

1-  Sequential (Sequence) structures.

2-   Selection (decision) structures (To select process based on decisions).

3-      Repetition (loop) structures (To do tasks repetitively until a condition is met).          

Semantics and Syntax:

a-      Semantics: The meaning of the language elements for example:

            1-Assignment statements.          2- Data type declarations.

            3- Input and output statements  4- If statements.            5- Loop statements.

b-     Syntax: The set of rules to use the structure of statements.

 

Numeric Data in Memory:

            It is represented in internal memory using the binary (base 2) number system. e.g.

            58 = (111010) in base 2                       58 = 32 + 16 + 8 + 0 + 2 + 0

            51 = (110011) in base 2                       51 = 32 + 16 + 0 + 0 + 2 + 1

In binary number system, the value of each digit should be less than 2 (base). So we have only 0s and 1s.

To get the binary representation of a decimal number, divide that decimal number by 2 and circle the remainder again divide the quotient by 2 and circle the remainder we do this process until we get zero for the quotient then we write all the circled remainders in reverse order (backward).  

How to use the C++ software:

In order to type our program source code, we should do as follows:

1- Click on start button.           2- Select programs.    

3- Select Microsoft Visual Studio 6.0.           4- Select Microsoft Visual C++ 6.0.

5- Click on File button.            6- Click on New.        

7- Select Win32 Console Application.           8- Type the project name on the top.

9- Click OK at the bottom.       10- Click on Finish.     11- Click OK.

12- Click on File again.            13- Click on New again.          

14- Select C++ Source File.   15- Type program name in the File name space.

16- Click OK at the bottom.     17- Now we can type our program.

To get more information about error code, you can go to http://www.msdn.microsoft.com and type your error code in the area for search then click on GO.

           

As you remember we wrote and run two programs in the class as follows:

Example 1:

// This is the first example Hello, world

#include <iostream.h>

void main()

{

      cout<<”Hello, world”<<endl;

      cout<<”This is the first program in C++ “<<endl;

}

Example 2:

// This is the second example. It calculates the sale amount by reading price and tax.

#include <iostream.h>

void main()

{

            int tax = 0;

            int price = 0;

            int sale = 0;

            cout<<"Enter the Tax value"<<endl;

            cin>>tax;

            cout<<"Please enter the price"<<endl;

            cin>>price;

            sale = price + tax;

            cout<<"The sale amount is   $"<<sale<<endl;

}

Please try to run these two programs again and if you have any problems let me know. Thank you very much.

Esmaail M Nikjeh

Hosted by www.Geocities.ws

1