True or false A variable of type char can hold the value 301. ( F )

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Computer Science 1620 Loops.
1 Engineering Problem Solving With C++ An Object Based Approach Chapter 3 Control Structures.
Logical Operators Java provides two binary logical operators (&& and ||) that are used to combine boolean expressions. Java also provides one unary (!)
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Correction of the Handout #include //Preprocessor using namespace std; int main (){ ………….. return 0; } A namespace is a named group of definitions. When.
Control Structures Control structures control the flow of program execution. 3 types of control structures: sequence, selection.
Introduction to C Programming
CONTROL STATEMENTS Lakhbir Singh(Lect.IT) S.R.S.G.P.C.G. Ludhiana.
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
Basic Elements of C++ Chapter 2.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Data representation and Data Types Variables.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Chapter 4 Program Control Statements
Lecture 4 C Program Control Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT3: Conditional Statements CS2311 Computer Programming.
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.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Week 1 Algorithmization and Programming Languages.
C++ Programming: Basic Elements of C++.
CPS120: Introduction to Computer Science Decision Making in Programs.
CSE 332: C++ execution control statements Overview of C++ Execution Control Expressions vs. statements Arithmetic operators and expressions * / % + - Relational.
Chapter 7 Additional Control Structures. Chapter 7 Topics l Switch Statement for Multi-Way Branching l Do-While Statement for Looping l For Statement.
Chapter 05 (Part III) Control Statements: Part II.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 3 Selections.
Control Structures Repetition or Iteration or Looping Part II.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X1 Chapter 3 Control Statements.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
Programming Fundamentals. Today’s Lecture The Conditional Operator Logical Operators Structures Enumerations.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Loops cause a section of a program to be repeated a certain number of times. The repetition continues while a condition remains true. When a condition.
Recap……Last Time [Variables, Data Types and Constants]
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Programming Fundamentals. The setw Manipulator setw changes the field width of output. The setw manipulator causes the number (or string) that follows.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Chapter 05 (Part II) Control Statements: Part II.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
CPS120 Introduction to Computer Science Exam Review Lecture 18.
 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.
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
LECTURE # 7 : STRUCTURED PROGRAMMING Selection Statements Tr.Hadeel.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
C++ LANGUAGE MULTIPLE CHOICE QUESTION
Introduction to Computer Programming
Chapter 1.2 Introduction to C++ Programming
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 3 Control Statements
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
The setw Manipulator The setw manipulator causes the number (or string) that follows it in the stream to be printed within a field n characters wide, where.
Chapter 4 C Program Control Part I
Basic Elements of C++.
Chapter 3 Control Statements Lecturer: Mrs Rohani Hassan
Intro to Programming Week # 5 Repetition Structure Lecture # 9
Basic Elements of C++ Chapter 2.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Introduction to C++ Programming
Chapter 7 Additional Control Structures
Chapter 2 Programming Basics.
C++ Programming Basics
Presentation transcript:

True or false A variable of type char can hold the value 301. ( F ) In an assignment statement, the value on the left of the equal sign is always equal to the value on the right. It’s perfectly all right to use variables of different data types in the same arithmetic expression. The increment expression in a for loop can decrement the loop variable - Relational operators have a higher precedence than arithmetic operators. ( F ) ( F ) ( T ) ( T ) ( F )

True or false A structure and enumerator use similar syntax. A structure definition creates space in memory for a variable. You can assign one structure variable to another, provided they are of the same type. In C++ count and COUNT are two different identifiers. In C++ each statement must end with semicolon ( F ) ( F ) ( T ) ( T ) ( T )

Complete A function name must be followed by ________. ( ) A function body is delimited by ________ A C++ instruction that tells the computer to do something is called a ________. The header file that must be included with your program when using setw is ________ The expression 11%3 evaluates to ________. ( ) { } statement iomanip 2

Complete The increment operator increases the value of a variable by ________. Let var1=20 the output of the statement “cout << var1--;” will be ________ and the output of the statement “cout << ++var1;” will be ________. An else always matches the _________ “ if ”, unless the “ if ” is _________. Executing the continue operator from within a loop causes control to go to ________. 1 20 20 last Connected with its else The tope of the loop

Complete The closing brace of a structure is followed by a __________. The first three enumerators of an enum type are normally represented by the values _________, _________, and _________. ;

Choose the correct answer 1. Dividing a program into functions a. is the key to object-oriented programming. b. may reduce the size of the program. c. makes the program run faster. d. all of the above 2- An expression a. usually evaluates to a numerical value. b. indicates the emotional state of the program. c. always occurs outside a function. d. cannot be part of a statement.

Choose the correct answer 3- The statements that display on the screen the character ‘x’ is a. cout<<x; b. cout<<’x’; c. cout>>”x”; d. cout<<’x’ 4- A relational operator a. assigns one operand to another. b. yields a Boolean result. c. logically combines two operands. d. none of the above.

Choose the correct answer 5- A variable defined within a block is visible a. from the point of definition onward in the program. b. from the point of definition onward in the function. c. from the point of definition onward in the block. d. throughout the function. 6- The library function exit() causes an exit from a. the loop in which it occurs. b. the block in which it occurs. c. the function in which it occurs. d. the program in which it occurs.

Choose the correct answer 7- The && and || operators a. compare two numeric values. b. combine two numeric values. c. compare two Boolean values. d. combine two Boolean values. 8- The break statement causes an exit a. only from the innermost loop. b. only from the innermost switch. c. from all loops and switches. d. from the innermost loop or switch.

Choose the correct answer 9- A structure brings together a group of a. items of the same data type and variables. b. related data items. c. integers with user-defined names. d. all of the above. 10- When accessing a structure member, the identifier to the left of the dot operator is the name of a. a structure member. b. a structure tag. c. a structure variable. d. the keyword struct.

Write a program 1- Write a program that generates the following output: 10 20 19 Use an integer constant for the 10, an arithmetic assignment operator to generate the 20, and a decrement operator to generate the 19.

#include <iostream> using namespace std; int main() { int var = 10; cout << var << endl; // var is 10 var *= 2; // var becomes 20 cout << var- - << endl; // displays var, then decrements it cout << var << endl; // var is 19 return 0; }

2- Write a for loop that displays the numbers from 100 to 110.

3 -Create a calculator program that contains four-function 3 -Create a calculator program that contains four-function. The program should ask the user to enter a number, an operator, and another number. (Use floating point.) It should then carry out the specified arithmetical operation: adding, subtracting, multiplying, or dividing the two entered numbers. Use a switch statement to select the operation. Finally, display the result. When it finishes the calculation, the program should ask whether the user wants to do another calculation. The response can be ‘y’ or ‘n’. If the response ‘n’ the program will terminate otherwise the program will repeat itself.

#include <iostream> using namespace std; int main() { double n1, n2, ans; char oper, ch; do { cout << “\nEnter first number, operator, second number: “; cin >> n1 >> oper >> n2; switch(oper) case ‘+’: ans = n1 + n2; break; case ‘-’: ans = n1 - n2; break; case ‘*’: ans = n1 * n2; break; case ‘/’: ans = n1 / n2; break; default: ans = 0; } cout << “Answer = “ << ans; cout << “\nDo another (Enter ‘y’ or ‘n’)? “; cin >> ch; } while( ch != ‘n’ ); return 0;

mins, and secs. Call this structure time. 4- Write a structure specification that includes three variables—all of type int—called hrs, mins, and secs. Call this structure time.