Upload
april
View
32
Download
0
Embed Size (px)
DESCRIPTION
In the Name of Allah The Most Merciful The Most Compassionate Programming In C++ http://vustudents.ning.com/. COURSE CONTENTS. Week 1: Basics Week 2: Loops and Decisions Week 3: Arrays and Strings Week 4: Functions Week 5: Structures and Intro to Classes - PowerPoint PPT Presentation
Citation preview
In the Name of Allah The Most Merciful The Most Compassionate Programming In Programming In
C++C++http://vustudents.ning.com/http://vustudents.ning.com/
COURSE CONTENTSCOURSE CONTENTS Week 1: Basics Week 2: Loops and Decisions Week 3: Arrays and Strings Week 4: Functions Week 5: Structures and Intro to Classes Week 6: Intro to Pointers and Final Test» Students passing the final test will only be awarded
certificates
Recommended BooksRecommended Books
Object Oriented Programming in C++ by Robert Lafore
C++ How to Programby Deital & Deital
Other ResourcesOther Resources
All displayed slides will be available in academics folder
Net Tutorials http://www.tutorialbox.com/tutors/c++/C++tutor.htm http://www.intap.net/~drw/cpp/ http://www.olagam.com/tech1/c-tutorial.htm www.freeprogrammingresources.com/cpptutor.html
History of ProgrammingHistory of Programming 1st Generation Languages
Machine Language 2nd Generation Languages
Assembly Language 3rd Generation Languages
Procedural Programming Languages like Basic, Pascal, Fortran, C etc.
4th Generation Languages OOP e.g. Java ,C++, VB.
C++ HistoryC++ History
C was developed at AT & T’s Bell Laboratories of USA in 1972 by Dennis Ritchie
C++ an extension of C was developed by Bjarne Stroustrup in early 1980s at Bell Laboratories. C++ provides capabilities for object-oriented programming.
Getting StartedGetting Started
Alphabets Words Sentences Paragraph
Program/ Code
InstructionsConstants,Variables,Keywords
Alphabets,Digits, Special- Symbols
English LanguageEnglish Language
C++ LanguageC++ Language
Structure of C ProgramStructure of C Program
# include < iostream.h >
int main ( )
{ cout << “Welcome to C++” ; return 0;}
Preprocessor Directives
Function Body
Main Functionvoid
Preprocessor DirectivesPreprocessor Directives
The first line of the program# include < iostream.h >is called a Preprocessor Directive,The instruction that are given to the compiler before beginning of the actual program.
It begins with the # sign and a keyword (reserve word) “include” followed by < name of header file>.
Header FilesHeader Files Header files are a part of the C++ Compiler and contain definitions of
standard library functions. Each header file has an extension “.h”. The preprocessor “include”
is used to add a header file into the source code. The name of the file is written in angle brackets ”< >”. Syntax is
# include < name of header file># include “ name of header file”
For example; iostream.h :The source file that contains declarations needed for
input and output statements like cout/cin. math.h : This header file contains definitions for mathematical
functions
FunctionsFunctions Functions are the fundamental building
blocks of C++. The first program consists of a single function called main ( ) .
The Main() FunctionThe Main() Function The main function indicates the beginning of a
C++ program. It must be included in every program.When a C++ program is executed, the control goes directly to main () function.The statements within this function are the main body of a program.If the main function is not included, the program is not compiled and an error is generated.
Syntax of the main() function is:int / void main ()
{
body of main function(program statements) ;
}Terminated by a semi colon “;”
The Function BodyThe Function BodyBraces: The braces ( Curly brackets “{ }“ ) indicate Begin and
End of a function. Every function must use this pair of braces. Program Statements: The basic unit of a C++ program. In our
program we’ve only one program statement i.e. cout << “Welcome to C++” ;
This statement tells the compiler to display thequoted phrase. A semicolon (;) indicates theend of the statement. Each statement hasto be followed by a semicolon otherwise, acompilation error will occur.
OUTPUT USING OUTPUT USING coutcout The identifier cout ( pronounced as “ C out” ) is
a predefined object in C++, called as Standard Output Stream. It follows data to be displayed.
The operator << is called the Insertion or Put to operator.
In our example, the phrase “Welcome to C++” is an example of a String Constant or String Literal, is directed to cout by the insertion operator << and is to be displayed on the output.
Escape Sequence or Escape Sequence or Backslash Character ConstantBackslash Character Constant In C++, backslash (\) causes an “escape” from the
normal way of output. An escape sequence is combination of a backslash ‘\’ i.e; control character and a code character.
Symbol Meaning Symbol Meaning\abeep \” Double / alarm quotes \r return \’ Single quote\nnew line \? ?\t tab \\ \\bbackspace \xdd Hexadecimal
The endl ManipulatorThe endl Manipulator Manipulators are instructions to the output
stream that modify the output in various ways. This causes a linefeed to be inserted into the
stream, so that the subsequent text is displayed on the next line. It has the same effect as the ‘\n’ character.cout<<"PAKISTAN”<<endl;cout<<“OUR HOMELAND"<<endl;cout<<“PAKISTAN\nOUR HOMELAND\n”;
The setw ManipulatorThe setw Manipulator It modifies or manipulates the way in which
data is displayed setw(n) : causes the string or no. that follows
it in the stream to be printed within a field n characters wide.The value is right justified within the field.cout<<"PAKISTAN\tIS\tTHE BEST"<<endl;
cout<<"PAKISTAN" <<setw(10)<<"IS"<<setw(14) <<"THE BEST";
Both have the same output
CommentsComments A comment statement is a non-executable
statement. It is used to add remarks in a program.The compiler ignores the comments given in the program.Comments are used to explain, what a program is doing. Comments can be written anywhere in a program. Syntax:
// comments for single-line comments /* comments…… for multi-line comments
……..*/
# include<iostream.h>int main() //beginning of main function{cout<<“\n \”NU \t ST\” ”; //printing outputscout<<“\n \’MCS\’ ”;return 0;}
Output ??? “NU ST” ‘MCS’
# include<iostream.h>void main(){/*This is a program to find errorscout<<“\n NUST ; cout<<“\n PAKISTAN”return 0;}//end of program
Errors ???
Steps of Programming in C++ Steps of Programming in C++ Editing
– Editing is done in an editor like BORLAND C / TURBO C / TC BIN
To write and save the code -filename.cpp Preprocessing
– To include required library files (headers etc) e.g # include
Compiling and Linking– To create Object file -filename.obj– Lib is linked to make an exe file -filename.exe
Execution– To view the output
Any Questions???http://vustudents.ning.com