Tutorial 1 Chapter 1 and 2 Exercises1. 2 Exercise 1 Which of the following identifiers are: main 1.invalid identifiers 2.valid identifiers and why? double.

Slides:



Advertisements
Similar presentations
Computer Science 1620 Loops.
Advertisements

What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 Objectives You should be able to describe: Relational Expressions The if-else Statement Nested if Statements The switch Statement Common Programming.
CS150 Introduction to Computer Science 1
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
© 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5/e Starting Out with C++: Early Objects 5 th Edition Chapter 2 Introduction.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
1 9/25/06CS150 Introduction to Computer Science 1 Nested Ifs, Logical Operators, exit() Page 194.
The If/Else Statement, Boolean Flags, and Menus Page 180
Exercise 5.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
For Loops Programming. COMP102 Prog Fundamentals I: for Loops/Slide 2 The for Statement condition action true false initialization update.
Basic Elements of C++ Chapter 2.
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
Presented by Joaquin Vila Prepared by Sally Scott ACS 168 Problem Solving Using the Computer Week 12 Boolean Expressions, Switches, For-Loops Chapter 7.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
Variables, Data Types and Constants Yared Semu Addis Ababa Institute of Technology Mar 31, 2012.
For Repetition Structures (L13) * General Form of the for Statement * Components of a Typical for Header * Pre/Postincrement of the Counter * Stream Manipulator.
2 Objectives You should be able to describe: Relational Expressions Relational Expressions The if-else Statement The if-else Statement Nested if Statements.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
CS31: Introduction to Computer Science I Discussion 1A 4/9/2010 Sungwon Yang
Completing the Basic (L06)
Value and Reference Parameters. CSCE 1062 Outline  Summary of value parameters  Summary of reference parameters  Argument/Parameter list correspondence.
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
Chapter 3. Outline Relational Operators Loops Decisions Logical Operators Precedence Summary.
CHAPTER#3 PART1 STRUCTURED PROGRAM DEVELOPMENT IN C++ 2 nd semester King Saud University College of Applied studies and Community Service Csc.
Lecture #6 OPERATORS AND ITS TYPES By Shahid Naseem (Lecturer)
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects Sixth.
Array & Matrix Selected topics. 1. It will compare two adjacent elements, if second element is smaller than the first then it will swap them, if we wanted.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Input a number #include using namespace std; int main() { int num; cout num; return 0; }
Overview Go over parts of quiz? Another iteration structure for loop.
Chapter#3 Part1 Structured Program Development in C++
GE 211 Dr. Ahmed Telba. // compound assignment operators #include using namespace std; int main () { a =5 int a, b=3; a = b; a+=2; // equivalent to a=a+2.
Before we get started…. First, a few things… Weighted Grading System Programming Style Submitting your assignments… The char and string variable types.
Today in CS161 Lecture #5 Learn about… Data types (char, int, float) Input and Output (cin, cout) Writing our First Program Write the Inches to MM Program.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
Lecture 5 Computer programming -1-. Input \ Output statement 1- Input (cin) : Use to input data from keyboard. Example : cin >> age; 2- Output (cout):
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Computer Programming Arrays 1. Question #1 2 Question Choose the correct answer..
Program Flow Control Addis Ababa Institute of Technology Yared Semu April 2012.
A Sample Program #include using namespace std; int main(void) { cout
Program Development and Design Using C++, Third Edition
Chapter five exercises. a. false; b. true; c. false; d. true; e. true; f. true; g. true; h. false.
arithmetic operator & cin I.Mona Alshehri The output formatting functions setw(width) setw(n) - output the value of the next expression in n columns.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Chapter Topics The Basics of a C++ Program Data Types
Chapter 3 Control Statements
REPETITION CONTROL STRUCTURE
Computing Fundamentals
Basic Elements of C++.
Chapter 2 Assignment and Interactive Input
Programming Fundamentals
CS149D Elements of Computer Science
Bools & Ifs.
Chapter 2 part #3 C++ Input / Output
Basic Elements of C++ Chapter 2.
Counting Loops.
If Statements.
CS150 Introduction to Computer Science 1
Chapter 2 part #3 C++ Input / Output
Programming Fundamental-1
Presentation transcript:

Tutorial 1 Chapter 1 and 2 Exercises1

2 Exercise 1 Which of the following identifiers are: main 1.invalid identifiers 2.valid identifiers and why? double 2time G sue’s return cout xzy123 part#2 #insert this_is_along_one

3 Show the output displayed by the following program lines when the data entered are 5 and 7 respectively. Cout<<“Enter two integers“; Cin>>m>>n; m = m + 5; n = 3 * n; Cout<<“m =“<<m<<endl; Cout <<“n=“<<n; Exercise 2

4 Show the output displayed by the following lines if the value of exp=11. Cout<<“My name is “; Cout<<“Hoda Ahmed.”; Cout<<endl; Cout<<“I live in “; Cout<<“Riyadh, Olaya Street “<<endl; Cout<<“and I have “ << exp << “ years “; Cout<<“of programming experience.”; Cout<<“ *****\n****\n***\n**\n*\n“ ; Exercise 3

5 Write a program that draws a simple triangle of stars on screen. Exercise 4 Exercise 5 Write 2 separate programs that show the following: 1.)Hello, World! 2.)Hello, World! * ** *** **** *****

******************** Salary 2500 Overtime 1250 Total-Sal= 3750 ******************** Exercise 6: Draw a flowchart then write a program that calculates the total salary, Given that a user will enter the salary and overtime. Note: Total-Sal = Salary +Overtime

Please enter first number: 5.5 Please enter second number: 2.5 The Product is Draw a flowchart and write a program to calculate the product of two numbers. Your output must be: Exercise 7:

Exercise 8: Where possible, write equivalents for the following statements using compound assignment operators: a)r = r / 10; b)z = z * x + 1; c)q = q + r * m; Exercises8

Exercise 9: Find the value of x, when j = 5 and k = 2: a)x = j +1*k-3; b)x = k-j*2(j+1); c)x = j k; d)x = j++; e)X=++k; Exercises9

Exercise 10: State the order of evaluation of the operators in each of the following C statements and show the value of x after each statement is performed x = ( 3 * 9 * ( 3 + ( 9 * 3 / ( 1+2 ) ) ) ); Exercises10

Exercises11 Exercise 11: Assume the following: int j = 6; int k = 10; int n; bool b = false; Give the value that is assigned, or illegal. 1.__________ n = k++; 2.__________ n = (k++); 3.__________ n = ++k; 4.__________ n = 7++; 5.__________ n = k j; 6.__________ n = k+++++j; 7.__________ n = k = j = 5; 8.__________ n = k = (j = 5); 9.__________ n = (k = j) = 5; 10.__________ 3 = 4; 11.__________ n = k; n += 1; 12.__________ n = k; n *= 2; 13.__________ n = k; n /= 2;

Exercise 12: Assume that: double y = ; Do the following : Print the integer part of y Print y on 10 places Print y on 7 places and fill the blank places with ‘#’ Print 1 number after the decimal point Print 2 numbers after the decimal point Store the integer part of y in x Add 30.9 to y and store the integer part of the result in z Exercises12