Presentation is loading. Please wait.

Presentation is loading. Please wait.

C++ Introduction. Why Learn C++? Very powerful and respected prog. Lang. Very powerful and respected prog. Lang. Highly respected in Academics Highly.

Similar presentations


Presentation on theme: "C++ Introduction. Why Learn C++? Very powerful and respected prog. Lang. Very powerful and respected prog. Lang. Highly respected in Academics Highly."— Presentation transcript:

1 C++ Introduction

2 Why Learn C++? Very powerful and respected prog. Lang. Very powerful and respected prog. Lang. Highly respected in Academics Highly respected in Academics B. Tech./M.Tech. Project work B. Tech./M.Tech. Project work Job Written Test + Interview Job Written Test + Interview Research: Programming work can be done in C++ Research: Programming work can be done in C++

3 Only course in C++ This may be the only course in C++ done by you. This may be the only course in C++ done by you. So learn it well So learn it well Benefits, later on in life, can be enormous Benefits, later on in life, can be enormous Excellent Lab facilities Excellent Lab facilities Use extra Lab time whenever possible Use extra Lab time whenever possible But do not neglect other courses But do not neglect other courses

4 Course Book C++ Primer, Fourth Edition C++ Primer, Fourth Edition Authors: Authors: Stanley B. Lippman Stanley B. Lippman Josee Lajoie Josee Lajoie Barbara E. Moo Barbara E. Moo Publisher: Pearson Education Publisher: Pearson Education ISBN: 81-317-1077-7 ISBN: 81-317-1077-7 Price Price List Price: Rs. 475 List Price: Rs. 475 Discount: Usually 10 to 20% Discount: Usually 10 to 20%

5 Course Book - 2 Availability of hard copy enables: Availability of hard copy enables: Easy lookup and study Easy lookup and study Faster and better learning Faster and better learning At least one copy for two students is essential At least one copy for two students is essential Will be useful after course too Will be useful after course too Procure book quickly Procure book quickly Book covers both C and C++ Book covers both C and C++ Reading chapters of book will be very useful Reading chapters of book will be very useful

6 First C++ Program #include //Not iostream.h #include //Not iostream.h int main() int main() { std::cout << “Hello world\n”; std::cout << “Hello world\n”; }

7 First C++ Program – 2 C++ is a superset of C C++ is a superset of C Standard header files do not have.h typically Standard header files do not have.h typically The iostream header includes information about stream objects used for input and output. The iostream header includes information about stream objects used for input and output. All such stream objects are said to be part of the iostream library All such stream objects are said to be part of the iostream library Instead of printf we use std::cout Instead of printf we use std::cout

8 First C++ Program - 3 std is a namespace std is a namespace cout is an object which writes (outputs) to a stream (the terminal usually) cout is an object which writes (outputs) to a stream (the terminal usually) :: is required between namespace and object :: is required between namespace and object << is the way to direct data into cout object << is the way to direct data into cout object << is also called output operator << is also called output operator

9 First C++ Program - 4 Source code file extension should be.cpp Source code file extension should be.cpp Save file as firstpgm.cpp Save file as firstpgm.cpp Compile using c++ or g++ Compile using c++ or g++ Executable file is named as a.out Executable file is named as a.out

10 Second C++ Program Book code is available as a zip file Book code is available as a zip file Windows: http://www.informit.com/content/images/0201721481/sourcecode/MS_ files.zip Windows: http://www.informit.com/content/images/0201721481/sourcecode/MS_ files.zip Linux: http://www.informit.com/content/images/0201721481/sourcecode/gnu_ files.tar.gz Linux: http://www.informit.com/content/images/0201721481/sourcecode/gnu_ files.tar.gz Copy it to your system (on Linux) and unzip it Copy it to your system (on Linux) and unzip it Chapter 1, add.cc Chapter 1, add.cc.cc is also used as extension for C++ source files but you should only use.cpp while you are doing this course..cc is also used as extension for C++ source files but you should only use.cpp while you are doing this course.

11 Second C++ Program - 2 << output operator can be used multiple times in one statement << output operator can be used multiple times in one statement std::endl is another way of inserting a newline (\n) std::endl is another way of inserting a newline (\n) Defining int variables is same as C Defining int variables is same as C

12 Second C++ Program - 3 std::cin is an input stream object which usually reads from keyboard std::cin is an input stream object which usually reads from keyboard >> is the input operator which reads input and puts the input into variables on right hand side of operator >> is the input operator which reads input and puts the input into variables on right hand side of operator

13 Read Course Book Course book (C++ Primer 4/e) : Course book (C++ Primer 4/e) : Gives a lot of additional information far beyond what we have time to cover in class Gives a lot of additional information far beyond what we have time to cover in class Is somewhat precise and so may take getting used to Is somewhat precise and so may take getting used to

14 Read Course Book - 2 But it is very good and very accurate But it is very good and very accurate Has simple exercises Has simple exercises Has nice layout with certain paragraphs marked specially as Notes or Beware (warnings) Has nice layout with certain paragraphs marked specially as Notes or Beware (warnings) Reading and understanding it thoroughly will make you a thorough C++ Guru Reading and understanding it thoroughly will make you a thorough C++ Guru

15 Hands On (Finally ) Start your system Start your system Choose Red Hat Linux as OS (instead of default Windows) Choose Red Hat Linux as OS (instead of default Windows) Log on with userid: - and password: - Log on with userid: - and password: - Wait for the GUI (Graphical User Interface) to come up properly Wait for the GUI (Graphical User Interface) to come up properly Open a terminal window Open a terminal window

16 First Assignment Write the Hello World program using vi Write the Hello World program using vi Source file name must end in.cpp Source file name must end in.cpp Compile it using c++ or g++ Compile it using c++ or g++ Executable file will be a.out (like what cc does) Executable file will be a.out (like what cc does) Run./a.out Run./a.out

17 Second Assignment First copy the book code zip file onto your system First copy the book code zip file onto your system Unzip the file Unzip the file Now read 1/add.cc Now read 1/add.cc Then write a program which takes in four integral numbers and gives the average of them as output. Then write a program which takes in four integral numbers and gives the average of them as output.

18 Book Source Code Copyright Note The course book is C++ Primer, 4th Edition by Lippman, Lajoie and Moo. Any references in earlier files to source files, and use of code within those files, are of example code given in and/or along with the book. As these slides are freely accessible on the Internet, not-for-profit, and for educational purposes, based on the permission related statements in the source code, I have considered that permission has been granted to use them in these slides. The course book is C++ Primer, 4th Edition by Lippman, Lajoie and Moo. Any references in earlier files to source files, and use of code within those files, are of example code given in and/or along with the book. As these slides are freely accessible on the Internet, not-for-profit, and for educational purposes, based on the permission related statements in the source code, I have considered that permission has been granted to use them in these slides.


Download ppt "C++ Introduction. Why Learn C++? Very powerful and respected prog. Lang. Very powerful and respected prog. Lang. Highly respected in Academics Highly."

Similar presentations


Ads by Google