Basic concepts of C++ Presented by Prof. Satyajit De

Slides:



Advertisements
Similar presentations
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Advertisements

True or false A variable of type char can hold the value 301. ( F )
Lecture 1 The Basics (Review of Familiar Topics).
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
The If/Else Statement, Boolean Flags, and Menus Page 180
Libraries Programs that other people write that help you. #include // enables C++ #include // enables human-readable text #include // enables math functions.
CS107 Introduction to Computer Science Java Basics.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
High-Level Programming Languages: C++
CS107 Introduction to Computer Science Java Basics.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Chapter 2 Overview of C++. A Sample Program // This is my first program. It calculates and outputs // how many fingers I have. #include using namespace.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
3. The Nuts and Bolts of C++ Computer Programming 3. The Nuts and Bolts of C++ 1 Learning the C++ language 3. The Nuts and Bolts of C++
C++ Programming: Basic Elements of C++.
Fundamental Programming: Fundamental Programming Introduction to C++
6/3/2016 CSI Chapter 02 1 Introduction of Flow of Control There are times when you need to vary the way your program executes based on given input.
Making Decisions (True or False) Relational Operators >greater than =greater than or equal to
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
Lecture #6 OPERATORS AND ITS TYPES By Shahid Naseem (Lecturer)
Syntax and Semantics, and the Program Development Process ROBERT REAVES.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 2.
C++ Lecture 1 Friday, 4 July History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Structured Programming (4 Credits) HNDIT Week 2 – Learning Outcomes Design an algorithmic solution for simple problem such as computation of a factorial,
CSC 143A 1 CSC 143 Introduction to C++ [Appendix A]
Introduction to C++.  Computers: CPU, Memory & Input / Output (IO)  Program: Sequence of instructions for the computer.  Operating system: Program.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
Fundamental Programming Fundamental Programming Introduction to Functions.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Chapter 1.2 Introduction to C++ Programming
Programming what is C++
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
CMPT 201.
Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
CS161 Introduction to Computer Science
Introduction to C++.
Introduction to C++ October 2, 2017.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Chapter 2 – Getting Started
Compound Assignment Operators in C++
Introduction to C++ Programming
Programming Funamental slides
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Selection Control Structure
Introduction to C++ Programming
C++ Programming Lecture 3 C++ Basics – Part I
Programs written in C and C++ can run on many different computers
Fundamental Programming
Repetition Statements (Loops) - 2
CS 101 First Exam Review.
CSC 1051 – Data Structures and Algorithms I
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Chapter 1 c++ structure C++ Input / Output
Programming Fundamental
Presentation transcript:

Basic concepts of C++ Presented by Prof. Satyajit De Dept. of Computer Sc. Maheshtala College

A C++ program /* include headers; these are modules that include functions that you may use in your program; we will almost always need to include the header that defines cin and cout; the header is called iostream.h */ #include <iostream.h> int main() { // header file //variable declaration //read values input from user //computation and print output to user return 0; } After you write a C++ program you save as “filename.cpp” and then compile it; that is, you run a program called compiler that checks whether the program follows the C++ syntax if it finds errors, it lists them If there are no errors, it translates the C++ program into a program in machine language which you can execute

Notes what follows after // on the same line is considered comment indentation is for the convenience of the reader; compiler ignores all spaces and new line ; the delimiter for the compiler is the semicolon all statements ended by semicolon Lower vs. upper case matters!! Void is different than void Main is different that main

Simple c++ program Here is the Hello world program in C++. #include <iostream.h> int main() { cout << “Hello world!”; return 0; }

Variable declaration type variable-name; Meaning: variable <variable-name> will be a variable of type <type> Where type can be: int //integer float / double / long double //real number char //character Example: int a, b, c; double x; int sum; char my-character;

Input statements cin >> variable-name; Meaning: read the value of the variable called <variable-name> from the user Example: cin >> a; cin >> b >> c; cin >> x; cin >> my-character; Extraction operator

Output statements Insertion operator cout << variable-name; Meaning: print the value of variable <variable-name> to the user cout << “any message “; Meaning: print the message within quotes to the user cout << endl; Meaning: print a new line Example: cout << a; cout << b << c; cout << “This is my character: “ << my-character << “ he he he” << endl; Insertion operator

If statements True False S2 S1 S3 if (condition) { S1; } else { S2; S3; True False condition S2 S1 S3

Boolean conditions ..are built using Comparison operators (Relational Operators) == equal != not equal < less than > greater than <= less than or equal >= greater than or equal Boolean operators (Logical Operators) && and || or ! not

Examples Assume we declared the following variables: int a = 2, b=5, c=10; Here are some examples of boolean conditions we can use: if (a == b) … if (a != b) … if (a <= b+c) … if(a <= b) && (b <= c) … if !((a < b) && (b<c)) …

If example #include <iostream.h> void main() { int a,b,c; cin >> a >> b >> c; if (a <=b) { cout << “min is “ << a << endl; } else { cout << “ min is “ << b << endl; cout << “happy now?” << endl;

While statements while (condition) { S1; } S2; True False S1 S2

While example //read 100 numbers from the user and output their sum #include <iostream.h> void main() { int i, sum, x; sum=0; i=1; while (i <= 100) { cin >> x; sum = sum + x; i = i+1; } cout << “sum is “ << sum << endl;

Exercise Write a program that asks the user Do you want to use this program? (y/n) If the user says ‘y’ then the program terminates If the user says ‘n’ then the program asks Are you really sure you do not want to use this program? (y/n) If the user says ‘n’ it terminates, otherwise it prints again the message Are you really really sure you do not want to use this program? (y/n) And so on, every time adding one more “really”.