Preston University, Islamabad Campus

Preview:

DESCRIPTION

Lecturer’s Introduction Senior Executive IT (Middleware and Provisioning) in Ufone Working in IT Industry (Software Development) since 2007 MS in Software Engineering from NUST in 2012 BS in Computer and Information Sciences from PIEAS in 2007 Designed / Developed Multiple Systems / Optimized Business Flows for Internal IT Customers and External Business Customers including Complete In House built CRM Enhancements, Provisioning System, Reporting Modules.

Citation preview

Programming in C++Preston University, Islamabad

Campus

Lecturer’s Introduction

• Senior Executive IT (Middleware and Provisioning) in Ufone• Working in IT Industry (Software Development) since 2007

• MS in Software Engineering from NUST in 2012• BS in Computer and Information Sciences from PIEAS in 2007

• Designed / Developed Multiple Systems / Optimized Business Flows for Internal IT Customers and External Business Customers including Complete In House built CRM Enhancements, Provisioning System, Reporting Modules.

Class Introduction

• Name• Why did you chose the Current Field?

Book

• Turbo C Programming for the PC and Turbo C++: Revised Edition by Robert Lafore: SAMS Publishing

Grading Mechanism

• Assignments / Projects: 10 Marks• Quizzes: 10 Marks• Class Participation / Attendance: 5 marks• Mid Term: 25 Marks• Final: 50 Marks

The Turbo C Programming Environment

Chapter 1

• Computer science deals with the theoretical foundations of information and computation, together with practical techniques for the implementation and application of these foundations

• Computer programming is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs

• Technology is changing everyday in this field– Necessary to get up to date on the regular bases– Big competition factor present in the field of Software

development

Computer Language• A computer language is a set of rules and conversions used to convey the

information to a computer.• There are three types of computer language:

– Machine Language: The native tongue of a computer is the machine language. Each Machine Language instruction is a binary string of 0’s and 1’s that specifies an operation and identifies the memory cells involved in that operation.

– Low Level Language: In the low level language, Machine Language is still used by the computer as it processes data, but Low level Language software first translate the specific operation symbol onto machine language equivalent. e.g. Assembly Language

– High Level Language: High Level Language is a programming Language where an instruction resembles everyday language. Instructions are given to computer by using conventional letters, symbols or English text rather than by using 1’s and 0’s code that the computer understand.e.g. Basic and Pascal etc

Introduction to C LanguageC, a high-level language programming language was developed in early 1970s by Dennis Ritchie at Bell Laboratories. Over the years, the power and flexibility of C, together with the availability of high quality C compilers for computers of all sizes, have made it a popular language in industry for a wide variety of applications.

• Why use C Language?– C is the most popular PC programming language.– C is unique in programming language in that it provides the convenience of a high

level language such as Basic or Pascal, but at the same time allows much closer control of a computer's hardware and peripherals, as the assembly language does.

– C compilers can generates amazingly fast code.– C Language is a well-structured and modular language. Its syntax makes it easy to

write programs that are modular and therefore they are easy to understand and maintain.

– C Language is portable: i.e it is easier to convert a C program to run on a different machine than it is to convert programs written in most other languages.

– C Language IDE is more user-friendly then most other languages.

Turbo C++ Environment

• Turbo C++ Development Systems– The Integrated Development Environment(IDE)

• Screen Display with windows • Pull-down Menus

– Command Line• Dos

Installation Program• Extract Turbo C++ files• Install the software DOSBox ver 0.74 (TC Installer)• 6MB HD Space Required

• Sub Directories– BIN– INCLUDE– LIB– So on

BIN

• Executable File • TC.exe (Place IDE on Screen)

• TCC – Command – line compiler• TLINK – Command-line Linker• MAKE – File-management Program• CPP – Preprocessor Utility• TZIP – Library File Manager• etc

LIB

• Library Files• Precompiled routines for performing specific Tasks• E.g. Math Libraries, Run Time Object Files

INCLUDE

• Header Files• Contains definition of Library Files• .h extension• Added in to Program before compilation

Program Execution Life Cycle

Compiler\Interpreter

• Compiler– Spends some time evaluating the entire program and

then translates all the programming statements of a program into a machine language program, which is then executed at once.

• Interpreter – Translates interactively each programming statement

into an immediately usable machine language instruction. Although an interpreter slows down the execution speed of a program somewhat, it does not require extra steps to compile and link like a compiler.

C\C++

• C++ is the Advance version of C• C is the Procedural Language• C++ is the Object Orient Programming Language

Structure of C++ Program

• Three Main Parts– Preprocessor Directories– The main() Function– C++ Statements

#include<stdio.h>void main(){printf(“Hello World”);}

Preprocessor Directories

• The instruction that are given to the compiler before the beginning of the actual program

• Also know as Compiler Directories• Consist Instructions for the compiler• Start with Number Sign #• Keywords “include” or “define”• E.g. Used to include Header files

The main() Function

• Contain Main body of C++ Program• void before main() specifies that function will not return

a value• main(void) specifies that function takes no arguments

void main(void){ program statements…}

C++ Statements

• Written under the main() function between the curly braces{} (Delimiters)

• Each statement end with semicolon(;) in C++• Case Sensitive Language• Contain Keyword/Reserved Words

– E.g. include, int , main etc.• Tokens

– Consists of variable names, keywords, constants, punctuation marks, operators etc.

IDE Environment

New File

Save File

• .cpp for C++ Program• .c For C Program

C++ Program

Compile (Alt+F9)

Make\Link (F9)

Run (Ctrl+F9)

User Window

Program Error

Debugging

Exit IDE

Escape Sequence

• Special non-printing characters to control printing on output device

• Combination of backslash ‘\’ and a code

Escape Sequence Explanation\n New line

printf(“I \n Love \n Pakistan”);ILovePakistan

\t Tab printf(“A \t B”);A B

\\ Print backslashprintf(“C:\\TC”);C:\TC

Print Message

• printf in C– printf(“This is number two: 2”);– printf(“This is number two : %d”,2);

%d – decimal%c – character%s – String

Activity

• After the source file C \ C++ program has been written, it must be– C_______– L_______– And E_______

• Output?– printf(“%s is %d million \n from the sun.”, “venus”,67);– printf(“ Path of Turbo C++ is: \n %s”,“C:\\TC”);– void main(void){printf(“%s\n%s\n%s”, “one”, “two”, “three”);}

LAB Work

• Write a program that generate following outputMr. Green is 42,Mr. Brown is 48.

• Write a program that print the phrasea, b and c are all letters.Use character constants to represent the letter.

Recommended