CS 240 Computer Programming 1

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick Strings #include using namespace std; int main () { string word; cout
Advertisements

© 2007 Lawrenceville Press Slide 1 Assignment Statement An assignment statement gives a value to a variable. Assignment can take several forms: x = 5;
Copyright © 2002 Pearson Education, Inc. Slide 1.
Copyright © 2003 Pearson Education, Inc. Slide 1.
Chapter 1 C++ Basics. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 1-2 Learning Objectives Introduction to C++ Origins, Object-Oriented.
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
ALGEBRAIC EXPRESSIONS
Introduction to C Systems Programming Concepts. Introduction to C A simple C Program A simple C Program –Variable Declarations –printf ( ) Compiling and.
Limits (Algebraic) Calculus Fall, What can we do with limits?
CS 141 Computer Programming 1 1 Arrays. Outline  Introduction  Arrays  Declaring Arrays  Examples Using Arrays  Sorting Arrays  Multiple-Subscripted.
EC-111 Algorithms & Computing Lecture #11 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
C++ Statements represent the lowest-level building blocks of a program and it may be like:. A simple statement is a computation terminated by a semicolon.
1 Chapter 3:Operators and Expressions| SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2006 | Last Updated: July 2006 Slide 1 Operators and Expressions.
Chapter 16 Exception Handling. What is Exception Handling? A method of handling errors that informs the user of the problem and prevents the program from.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 12P. 1Winter Quarter User-Written Functions.
1 Lecture 16:User-Definded function I Introduction to Computer Science Spring 2006.
Chapter 6 Advanced Function Features Pass by Value Pass by Reference Const parameters Overloaded functions.
CSE202: Lecture 3The Ohio State University1 Assignment.
Introduction to Programming Lecture 15. In Today’s Lecture Pointers and Arrays Manipulations Pointers and Arrays Manipulations Pointers Expression Pointers.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
C++ Data Type String A string is a sequence of characters enclosed in double quotes. Examples of strings: “Hello” “CIS 260” “Students” The empty string.
CS Sept Your first C++ program… Boilerplate // Cannon, demo program #include using namespace std; int main() {// program goes here… return.
EXERCISE IN CLASS CHAPTER 3. PART 1 IDENTIFIER SCENARIO 1 o record1 o 1record o file_3 o return o $tax o Name o name and address o name-and-address o.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
CS150 Introduction to Computer Science 1
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
1 9/08/06CS150 Introduction to Computer Science 1 Arithmetic Operators.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
CS150 Introduction to Computer Science 1
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Pointer Data Type and Pointer Variables. Objectives: Pointer Data Type and Pointer Variables Pointer Declaration Pointer Operators Initializing Pointer.
1 CS 1430: Programming in C++. 2 Literal Values Literal values of int Literal values of float
CS31: Introduction to Computer Science I Discussion 1A 4/9/2010 Sungwon Yang
COMPUTER PROGRAMMING. Functions What is a function? A function is a group of statements that is executed when it is called from some point of the program.
CSE1222: Lecture 3The Ohio State University1. Assignment Operations  The C++ assignment operator is: =  Examples: x = 3 * 5; y = x – 7; y = y + 4; Do.
First steps Jordi Cortadella Department of Computer Science.
CS Class 03 Topics  Sequence statements Input Output Assignment  Expressions Read pages Read pages 40 – 49 for next time.
Objective: Students will be able to: Declare and use variables Input integers.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
8.4 Use Scientific Notation Algebra. Scientific Notation Numbers such as 1,000,000, 153,000 and are written in standard form. Another way to write.
Exceptions in C++. Exceptions  Exceptions provide a way to handle the errors generated by our programs by transferring control to functions called handlers.
Variables and Constants Objectives F To understand Identifiers, Variables, and Constants.
1 What is a Named Constant? A named constant is a location in memory that we can refer to by an identifier, and in which a data value that cannot be changed.
COMPUTER PROGRAMMING. Array C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
 constant represented by a name, just like a variable, but whose value cannot be changed  The const keyword precedes the type, name, and initialization.
Chapter 2 Creating a C++ Program. Elements of a C++ Program Four basic ways of structuring a program Four basic ways of structuring a program 1.Sequencing.
Array. Array is a group of data of the same type. Array elements have a common name –The array as a whole is referenced through the common name Individual.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Current Assignments Project 3 has been posted, due next Tuesday. Write a contact manager. Homework 6 will be posted this afternoon and will be due Friday.
CS 240 Computer Programming 1
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
Chapter 2 Introduction to C++ Programming
Variables Mr. Crone.
Computing Fundamentals
Variables A variable is a placeholder for a value. It is a named memory location where that value is stored. Use the name of a variable to access or update.
Pointer Data Type and Pointer Variables
Chapter 2 Elementary Programming
C Stuff CS 2308.
Screen output // Definition and use of variables
CS150 Introduction to Computer Science 1
Arithmetic Operations
CS150 Introduction to Computer Science 1
Pointer Data Type and Pointer Variables
Pointer Data Type and Pointer Variables
Reading from and Writing to Files Part 2
Algebraic Expressions & Solving Equations
Presentation transcript:

CS 240 Computer Programming 1 Variables

Which of the following is a correct C++ identifier: Question 1 : Which of the following is a correct C++ identifier: SS N1 a$total2 D_D s-3 _ds

Which of the following is correctly formed constant of type integer? Question 2 : Which of the following is correctly formed constant of type integer? 145 4.0 12.3 34 ‘8’ “9” 12,5

Declare the following using one statement: Question 3 : Declare the following using one statement: int x; int y; int z;   char a = ‘i’; char b; char c = ‘E’; int x , y , z ; char a = ‘i’ , b , c = ‘E’ ;

Write a C++ statement to do the following: Question 4 : Write a C++ statement to do the following: a) Declare two variables of type character, each one is in a separate declaration statement. char a ; char b ;

Write a C++ statement to do the following: Question 4 : Write a C++ statement to do the following: b) Declare two variables of type character and initialize them with the values $and ? respectively in the declaration. NOTE: use one declaration statement. char c = ‘$’ , d = ‘?’ ;

Write the following algebraic expressions as C++ expressions: Question 5: Write the following algebraic expressions as C++ expressions: 𝑏2−4𝑎𝑐 b * 2 – 4 * a * c

Write the following algebraic expressions as C++ expressions: Question 5: Write the following algebraic expressions as C++ expressions: 𝑤𝑙𝑥2−𝑤𝑥22 w * l * x * 2 – w * x * 22

Question 6: Each of the following assignment statement contains at least one error. Identify them: Delta=x(y+(3x+(z+15))) X=5=y+4

Question 7: Given the algebraic equation y=a 𝑥 3 +7 , which of the following, if andy are correct C++ statements for this equation? a. Y= a*x*x*x+7; b. Y=a*x*x*(x+7); c. Y=(a*x) * x*(x+7); d. Y=(a*x)*x*x+7;

Correct the errors in the following programs: Question 8: Correct the errors in the following programs: #include<iostream>; using namespace std; int main(); { int x; y=2; z= 4; x=y+z; cout<<”x”; //print the integer x } #include<iostream> using namespace std; int main() { int x, y=2 , z=4; x=y+z; cout<<x; //print the integer x }

Correct the errors in the following programs: Question 8: Correct the errors in the following programs: #include<iostream> using name space std; int main { char a=”$”; cout<<a; cin>>b; cout<<b, return o; #include<iostream> using name space std; int main ( ) { char a=‘$’ , b; cout<<a; cin>>b; cout<<b; return 0; }

What is the output by each of the following code fragment? Question 9: What is the output by each of the following code fragment? int x=1; int main() { int x=3; cout<<x<<endl; cout<<::x<<endl; return 0; } The output : 3 1

What is the output by each of the following code fragment? Question 9: What is the output by each of the following code fragment? int a=1; int b=-3; int c=2; b=a++; c+=--a+b++; cout<<a<<" "<<b<<" " <<c; The output : 1 2 4

Problem 1 Question Write a program that asks the user to input 2 numbers A and B, then exchange the values of A and B.

Problem 1 Answer

Problem 1 Answer

Problem 2 Question Write a program that reads in the length and the width of a rectangular yard. Your program should compute the time required (in minutes) to cut the grass at the rate of 2.3 square meters per a second.

Problem 2 Answer

Problem 2 Answer

Problem 3 Question Write a program that asks the user to type the price without tax of one kilogram of tomatoes, the number of kilograms you want to buy and the tax in percent units. The program must calculate the total price including taxes.

Problem 3 Answer

Problem 3 Answer