Object Oriented Programming Using C++ Mathematics & Computing IET, Katunayake

Similar documents
I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK a) What is the difference between Hardware and Software? Give one example for each.

Lectures 4 and 5 (Julian) Computer Programming: Skills & Concepts (INF-1-CP1) double; float; quadratic equations. Practical 1.

Engineering 12 - Spring, 1999

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

sends the formatted data to the standard output stream (stdout) int printf ( format_string, argument_1, argument_2,... ) ;

On a 64-bit CPU. Size/Range vary by CPU model and Word size.

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

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

ALGORITHMS AND FLOWCHARTS

CS111: PROGRAMMING LANGUAGE1. Lecture 2: Algorithmic Problem Solving

Computer Engineering 1 (1E3)

Pointers and scanf() Steven R. Bagley

Companion C++ Examples

Chapter 3. Computer Science & Engineering 155E Computer Science I: Systems Engineering Focus. Existing Information.

PROBLEM 1 : (Vocabulary: 12 points) For each of the words/phrases below, circle the denition that is the best description as it pertains in the contex

CSCI 111 Midterm 1 Exam Spring Solutions 09.00am 09.50am, Monday, March 21, 2016

CMPE Experiment 3 Selective Structures

b. Suppose you enter input from the console, when you run the program. What is the output?

Week4. Huayi Li

1st Midterm Exam: Solution COEN 243: Programming Methodology I

Computer Science & Engineering 150A Problem Solving Using Computers

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 3. Existing Information. Notes. Notes. Notes. Lecture 03 - Functions

Warm Up. Factor the following numbers and expressions. Multiply the following factors using either FOIL or Box Method

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Algebra II Chapter 5

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.

Add Subtract Multiply Divide

AP Computer Science Java Mr. Clausen Program 6A, 6B

Programming and Data Structure

Working with Algebraic Expressions

Homework #3 CS2255 Fall 2012

Learning to Program with Haiku

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma.

Computer Programming: Skills & Concepts (CP) arithmetic, if and booleans (cont)

Outline. First Quiz Results. Exercise Five Goals. Question Three. Questions One and Two. Exercise five if statements February 28, 2006

Introduction To Computer Programming C++ Mr. Clausen Program C11A, C11B

PSEUDOCODE AND FLOWCHARTS. Introduction to Programming

Class 2: Variables and Memory. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

Control Statements. If Statement if statement tests a particular condition

ASSIGNMENT CLASS-11 COMPUTER SCIENCE [C++]

P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS DEPARTMENT OF SCIENCE AND HUMANITIES EVEN SEMESTER FEB 2017

Finite Math - J-term Homework. Section Inverse of a Square Matrix

Functions and Recursion

Chapter 1 An Introduction to Computer Science. INVITATION TO Computer Science 1

Operators and Expressions:

Today is the last day to register for CU Succeed account AND claim your account. Tuesday is the last day to register for my class

University of Dublin

Outline. Functions. Functions. Predefined Functions. Example. Example. Predefined functions User-defined functions Actual parameters Formal parameters

Algorithms and Programming I. Lecture#12 Spring 2015

Computers in Engineering. Moving From Fortran to C Michael A. Hawker

Object-Oriented Programming. Chapter 4

From Pseudcode Algorithms directly to C++ programs

LAB 4.1 Relational Operators and the if Statement

Chapter 1 Section 1 Solving Linear Equations in One Variable

Introduction to Functions in C. Dr. Ahmed Telba King Saud University College of Engineering Electrical Engineering Department

EP578 Computing for Physicists

CS 199 Computer Programming. Spring 2018 Lecture 2 Problem Solving

02157 Functional Programming Lecture 2: Functions, Basic Types and Tuples

Lecture 3 Tao Wang 1

3.1 INTRODUCTION TO THE FAMILY OF QUADRATIC FUNCTIONS

1. Answer: x or x. Explanation Set up the two equations, then solve each equation. x. Check

CHAPTER 4 FUNCTIONS. Dr. Shady Yehia Elmashad

C++ Programming Lecture 11 Functions Part I

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

Quadratic Equations. Learning Objectives. Quadratic Function 2. where a, b, and c are real numbers and a 0

Expressions & interactions Conditionals Solving a problem. binary representation (8 bits)

Question 1. [5 points] Circle and briefly explain the error(s) in the following code:

Computers in Engineering. Moving From Fortran to C Part 2 Michael A. Hawker

You should be able to plot points on the coordinate axis. You should know that the the midpoint of the line segment joining (x, y 1 1

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

Computers in Engineering COMP 208. Roots of a Quadratic in C 10/25/2007. Moving From Fortran to C Part 2 Michael A. Hawker

CSI33 Data Structures

1/16/12. CS 112 Introduction to Programming. A Foundation for Programming. (Spring 2012) Lecture #4: Built-in Types of Data. The Computer s View

Fundamentals of Programming CS-110. Lecture 2

UNIT 5 QUADRATIC FUNCTIONS Lesson 1: Interpreting Structure in Expressions Instruction

UNIT 3 EXPRESSIONS AND EQUATIONS Lesson 3: Creating Quadratic Equations in Two or More Variables

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

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

School Year:

2.2 Transformers: More Than Meets the y s

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

CGF Lecture 2 Numbers

Unit 2: Accentuate the Negative Name:

2. From General Form: y = ax 2 + bx + c # of x-intercepts determined by the, D =

A SHORT COURSE ON C++

Outline. Why do we write functions? Introduction to Functions. How do we write functions? Using Functions. Introduction to Functions March 21, 2006

Transformations with Quadratic Functions KEY

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

) 2 + (y 2. x 1. y c x2 = y

Lab Instructor : Jean Lai

Lecture 3. Review. CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions. Conditions: Loops: if( ) / else switch

LOGO BASIC ELEMENTS OF A COMPUTER PROGRAM

Session 3. Basic Java Data Types, Control Structures. 8 primitive or built-in data types

COMP 208 Computers in Engineering

Data Structures and Algorithms

ECOR Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

Floating-point numbers. Phys 420/580 Lecture 6

1.1 Introduction. 1.2 Model

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh

Transcription:

Assigning Values // Example 2.3(Mathematical operations in C++) float a; cout << "Enter any value for a: "; cin >> a; cout << "First value of a: " << a << "\n"; a = a + 2; // add two for first value cout << "Second value of a: " << a << "\n"; a = 2*a; // multiply second value by 2 cout << "Third value of a: " << a << "\n"; // Example 2.3(Mathematical operations in C++) #include <math.h> float a, b; cout << "Enter any value for a: "; cin >> a; b = pow (a,7); // sevent power of a cout << "seventh power of a: " << b << "\n"; b = sqrt (a); // getting square root cout << "Square root of a: b = log (a); // getting ln value cout << "ln of a: " << b << "\n"; " << b << "\n"; b = log10 (a); // getting log value cout << "log of a: " << b << "\n"; 5

Decisions and Loops // Example 3.1 (if loop) int a; // declaring integer float b, c, d; // declaring values cout << "Enter 1 for addition or enter 2 for multiplication "; cin >> a; cout << "enter two integer values: ";// output the requirement cin >> b >> c; // asign the values if (a == 1) d = b + c; if (a == 2) d = b*c; cout << d << "\n"; // output the result 6

// Example 3.2 (if loop) char r; // declaring character float b, c, d; // declaring values cout << "Enter a for addition or enter m for multiplication "; cin >> r; cout << "enter two integer values: "; // output the requirement cin >> b >> c; // asign the values if (r == 'a') d = b + c; if (r == 'm') d = b*c; cout << d << "\n"; // output the result 7

// Example 3.3 (if loop & string) #include <string> using std::string; string r; // declaring string float b, c, d; // declaring values cout << "Enter addition or multiplication: "; cin >> r; cout << "enter two values: "; // output the requirement cin >> b >> c; // asign the values if (r == "addition") d = b + c; if (r == "multiplication") d = b*c; cout <<" " << d << "\n"; // output the result 8

// Example 3.4 (if, else if and else) char c; // declaring character cout << "Enter mathematical operation: "; cin >> c; // asign the character if (c == '+') cout << "Symbol of addition"; else if (c == '-') cout << "Symbol of subtract"; else if (c == '*') cout << "Symbol of multiplication"; else if (c == '/') cout << "Symbol of division"; else cout << "Not a mathematical symbol"; cout << "\n"; // starting new line 9

// Example 3.5(solution for equation) #include <math.h> #include <string> using std::string; float a, b, c, d, x; string r; cout << "Enter type of equation (simple or quadratic): "; cin >> r; if (r == "simple") cout << "ax + b = 0\n"; cout << "Enter a and b: "; cin >> a >> b; x = -b/a; cout << "x = " << x << "\n"; else if (r == "quadratic") cout << "ax2 + bx + c = 0\n"; cout << "Enter a, b and c: "; cin >> a >> b >> c; d = b*b - 4*a*c; if (d >= 0) d = sqrt (d); x = (-b + d)/(2*a); cout << "x = " << x << "\n"; x = (-b - d)/(2*a); cout << "x = " << x << "\n"; if (d < 0) d = sqrt (-d); cout << "x = " << -b/(2*a) << " + i" << d/(2*a) << "\n"; cout << "x = " << -b/(2*a) << " - i" << d/(2*a) << "\n"; else cout << "error input\n"; 10

11