DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

Similar documents
Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Computer Programming : C++

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Scientific Computing

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

UNIT- 3 Introduction to C++

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

VARIABLES & ASSIGNMENTS

CS2141 Software Development using C/C++ C++ Basics

A First Program - Greeting.cpp

Understanding main() function Input/Output Streams

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

Chapter 1 INTRODUCTION

CSc Introduction to Computing

REPETITION CONTROL STRUCTURE LOGO

CS242 COMPUTER PROGRAMMING

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

WARM UP LESSONS BARE BASICS

Chapter 2: Basic Elements of C++

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Lecture 3 Tao Wang 1

CSCE 110 PROGRAMMING FUNDAMENTALS

BITG 1233: Introduction to C++

Chapter 4 - Notes Control Structures I (Selection)

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

3 The L oop Control Structure

The C++ Language. Arizona State University 1

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

Chapter 2. Outline. Simple C++ Programs

Functions. CS111 Lab Queens College, CUNY Instructor: Kent Chin

Introduction to Computer Science Midterm 3 Fall, Points

Your first C++ program

1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl?

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

Chapter 2: Introduction to C++

Chapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Chapter 3 Problem Solving and the Computer

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

Objectives. In this chapter, you will:

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

Object Oriented Pragramming (22316)

CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING. Dr. Shady Yehia Elmashad

Study Guide for Test 2

Lab # 02. Basic Elements of C++ _ Part1

Name Section: M/W or T/TH. True or False (14 Points)

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.1

Name SECTION: 12:45 2:20. True or False (12 Points)

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key

Chapter 2 Basic Elements of C++

Fundamentals of Programming CS-110. Lecture 2

2 nd Week Lecture Notes

LECTURE 02 INTRODUCTION TO C++

Maciej Sobieraj. Lecture 1

C++ Programming: From Problem Analysis to Program Design, Third Edition

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Lab Instructor : Jean Lai

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Computer Programming. Decision Making (2) Loops

Concepts Review. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++.

A SHORT COURSE ON C++

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

C++ Support Classes (Data and Variables)

6.096 Introduction to C++ January (IAP) 2009

Increment and the While. Class 15

Integer Data Types. Data Type. Data Types. int, short int, long int

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

CHAPTER 4 FUNCTIONS. 4.1 Introduction

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

5. Selection: If and Switch Controls

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

Week 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

C++ basics Getting started with, and Data Types.

Introduction to C++ General Rules, Conventions and Styles CS 16: Solving Problems with Computers I Lecture #2

Engineering Problem Solving with C++, Etter/Ingber

CHAPTER 3 BASIC INSTRUCTION OF C++

3. Functions. Modular programming is the dividing of the entire problem into small sub problems that can be solved by writing separate programs.

Introduction. C provides two styles of flow control:

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

CS 101 Computer Programming and utilization. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics

True or False (12 Points)

Chapter 1 Introduction to Computers and C++ Programming

CSCI 111 First Midterm Exam Fall Solutions 09.00am 09.50am, Wednesday, October 18, 2017

CS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM

C++ Programming: From Problem Analysis to Program Design, Third Edition

CSC 309/404 Section 901/910 Spring 2017 Midterm Exam Due: May 7 (Sun) 2015, 11:59 pm

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING

Transcription:

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++ Objective: To Learn Basic input, output, and procedural part of C++. C++ Object-orientated programming language compiled programming language case-sensitive Integrated Development Environment An IDE (Integrated Development Environment) will be used to write programs. IDE is basically a programmer-orientated text editor, which has syntax highlighting and normally compiler integration. Most commonly used IDE for C++ are: Eclipse Dev-C++ Code::Blocks NetBeans IDE Microsoft Visual Studio Express CodeLite Borland C++ Turbo C Data Types C++ Type int Stores Whole numbers (integers) bool True of False (0 or 1) float double char Fractional number (real number) float with twice the precision A single ASCII character Variables: Variables are used to store values. int a; a = 10; int a = 10; declaring variable assigning value to a variable. initialization [assignment with the declaration] Page 1 of 7

Variable name: It cannot be a reserved keyword It doesn t start with a number or a special characer (*; etc) General convention is to start it with a lower case letter C++ Library File <iostream> Standard Input / Output Streams Library Standard input/output stream objects: Objects Operators cin Standard input stream (object) >> extraction operator cout Standard output stream (object) << insertion operator Namespace: A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries. std: The std namespace (where features of the C++ Standard Library, such as string or vector, are declared). Note: you can combine multiple statements into one cout << "Hello, " << "World!"; You can also combine cin statements together in the same way to receive several pieces of input in a row. Enter still needs to be pressed after each one, Lab0101.cpp: // Hello World Program cout << "Hello World"; Page 2 of 7

Lab0102.cpp: // Add two numbers int num1, num2; int sum = 0; cout << "Enter first number : "; cin >> num1; cout << "\n Enter second number : "; cin >> num2; sum = num1 + num2; cout << "\n Sum of two numbers is : " << sum << "\n" ; Operators: Arithmetic operators: Comparison operators: Logical operators: Compound operator: +, -, *, /, %, == equal && AND a+=1 a=a+1 ++, - - (unary operators for increment and decrement)!= not equal < less than OR! NOT a*=b a=a*b > greater than etc. Page 3 of 7

Conditionals: if Statement Syntax: if ( TRUE ) Execute all statements inside the braces If-else Statement Syntax: if ( TRUE ) // Execute these statements if TRUE else // Execute these statements if FALSE If-else if-else Statement Syntax: if ( <condition> ) statement(s) if <condition> is TRUE else if ( <another condition> ) statement(s) if <another condition> is TRUE else Execute when none of the above conditions is TRUE Lab0103.cpp: // Is number positive or negative? int number = 0; cout << "Enter number : "; cin >> number; if (number > 0) cout << "Number is Positive!\n"; else cout << "Number is Negative!\n"; Page 4 of 7

SWITCH CASE Syntax: switch(expression) case value1 : case value2 : case value3 : default : Lab0104.cpp: // C++ program to build simple calculator using switch Statement char op; float num1,num2; cout<<"select an operator either + or - or * or / \n"; cin>>op; cout<<"enter two operands: "; cin>>num1>>num2; switch(op) case '+': cout<<num1<<" + "<<num2<<" = "<<num1+num2; case '-': cout<<num1<<" - "<<num2<<" = "<<num1-num2; case '*': cout<<num1<<" * "<<num2<<" = "<<num1*num2; case '/': cout<<num1<<" / "<<num2<<" = "<<num1/num2; default: cout<<"error! Operator is not correct"; Page 5 of 7

Loop: A loop is a piece of code that is repeated several times, one after another until a certain condition is met. C++ has three types of loop; for loop, while loop and do while loop. for loop Syntax: for ( init; condition; increment ) statement(s); while loop Syntax: while(condition) statement(s); do-while loop Syntax: do statement(s); while( condition ); Lab0105.cpp: // Do-while loop char ch; do cout << "Do you want to play again? (Y/N) " ; cin>>ch; while (ch == 'Y' ch == 'y'); Page 6 of 7

Task#1(lab01T01.cpp) Write a program to accept an integer n from the user and find the sum and average of first n natural numbers. Make sure that user enters positive integer between 1 and 20. Submission Deadline: Sec A : 2nd Sep, 15 Wednesday 11:55 pm Sec B : 4th Sep, 15 Friday 11:55 pm Problem lab01p01.cpp Write a program to print reverse of a number. [If input is 12345, the output will be 54321] Part B Problem lab01p02.cpp Write a program to design a menu with the following options to calculate: 1. Factorial of a number 2. Prime or not 3. Odd or Even 4. Exit [Hint: Use switch statement to select the menu option and perform desired task] Output screen would like this: Page 7 of 7 Copy protected with Online-PDF-NoCopy.com