TEST 1 CS 1410 Intro. To Computer Science Name KEY. October 13, 2010 Fall 2010

Similar documents
Formatting outputs String data type Interactive inputs File manipulators. Access to a library that defines 3. instead, a library provides input

I/O Streams and Standard I/O Devices (cont d.)

The cin Object. cout << "Enter the length and the width of the rectangle? "; cin >> length >> width;

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.

Week 3: File I/O and Formatting 3.7 Formatting Output

C++ Input/Output: Streams

BITG 1233: Introduction to C++

Definition Matching (10 Points)

Chapter 3 - Notes Input/Output

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

Fundamentals of Programming CS-110. Lecture 2

Department of Computer and Mathematical Sciences. Lab 10: Functions. CS 1410 Intro to Computer Science with C++

The C++ Language. Output. Input and Output. Another type supplied by C++ Very complex, made up of several simple types.

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

Input and Output File (Files and Stream )

Getting started with C++ (Part 2)

1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A.

Software Design & Programming I

Sample Code: OUTPUT Daily Highs & Lows

Introduction to Programming EC-105. Lecture 2

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

Program Organization and Comments

THE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.7. User Defined Functions II

Ch 6. Functions. Example: function calls function

CPE Summer 2015 Exam I (150 pts) June 18, 2015

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

CSC 138 Structured Programming CHAPTER 4: TEXT FILE [PART 1]

VARIABLES & ASSIGNMENTS

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

BITG 1113: Files and Stream LECTURE 10

File I/O. File Names and Types. I/O Streams. Stream Extraction and Insertion. A file name should reflect its contents

We will exclusively use streams for input and output of data. Intro Programming in C++

Introduction to C++ (Extensions to C)

Review for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure

Chapter 2: Basic Elements of C++

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

Strings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts

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

Chapter 1 INTRODUCTION

3.1. Chapter 3: The cin Object in Program 3-1. Displaying a Prompt 8/23/2014. The cin Object

Chapter 3: Expressions and Interactivity

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces

3.1. Chapter 3: Displaying a Prompt. Expressions and Interactivity

PROGRAMMING EXAMPLE: Checking Account Balance

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

Starting Out With C++: Early Objects, Seventh Edition Solutions to End-of-Chapter Review Questions

Chapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

CMPS 221 Sample Final

C++ Input/Output Chapter 4 Topics

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

Expressions, Input, Output and Data Type Conversions

Problem Solving: Storyboards for User Interaction

Chapter 3: Input/Output

Input and Output. Data Processing Course, I. Hrivnacova, IPN Orsay

Chapter 3: Expressions and Interactivity. Copyright 2012 Pearson Education, Inc. Thursday, October 9, 14

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

Lecture 4 Tao Wang 1

Chapter Overview. I/O Streams as an Introduction to Objects and Classes. I/O Streams. Streams and Basic File I/O. Objects

CS242 COMPUTER PROGRAMMING

Chapter 3 Problem Solving and the Computer

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

2.1-First.cpp #include <iostream> // contains information to support input / output using namespace std;

BEng (Hons) Electronic Engineering. Resit Examinations for / Semester 1

READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties. Do not start the test until instructed to do so!

CS150 Intro to CS I. Fall Fall 2017 CS150 - Intro to CS I 1

Objectives. In this chapter, you will:

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science. Instructor: Final Exam Fall 2011

3.1. Chapter 3: The cin Object. Expressions and Interactivity

CS2141 Software Development using C/C++ Stream I/O

The C++ Language. Arizona State University 1

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

CS 007A Midterm 1 Practice Chapters 1 5

Chapter 1 Introduction to Computers and C++ Programming

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

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

The following is a typical execution run of this program:

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

Objects and streams and files CS427: Elements of Software Engineering

Chapter 15 - C++ As A "Better C"

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Dr. Khalil Exam II Fall 2011

Engineering Problem Solving with C++, Etter/Ingber

Reading from and Writing to Files. Files (3.12) Steps to Using Files. Section 3.12 & 13.1 & Data stored in variables is temporary

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No.

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

Text File I/O. #include <iostream> #include <fstream> using namespace std; int main() {

Computer Programming : C++

WARM UP LESSONS BARE BASICS

Chapter 1: An Overview of Computers and Programming Languages. Objectives. Objectives (cont d.) Introduction

C++ As A "Better C" Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan.

The American University in Cairo Department of Computer Science & Engineeringt CSCI &09 Dr. KHALIL Exam-I Fall 2009

Programming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1

COMP322 - Introduction to C++

System Design and Programming II

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

causing a set of statements (the body) to be executed repeatedly. C++ provides three control structures to support iteration (or looping).

Sequential Program Execution

CMSC 202 Midterm Exam 1 Fall 2015

Transcription:

TEST 1 CS 1410 Intro. To Computer Science Name KEY October 13, 2010 Fall 2010 Part I: Circle one answer only. (2 points each) 1. The decimal representation of binary number 11011 2 is a) 19 10 b) 29 10 c) 27 10 d) 37 10 e) 47 10 2. The binary representation of decimal number 41 10 is a) 41 10 b) 110011 2 c) 101001 2 d) 100101 2 f) 101011 2 3. The binary number 1010111110 2 can be represented in Hex (base 16) as a) 2AE 16 b) 2BE 16 c) AF2 16 d) AF4 16 e) AF8 16 4. To store a character in C++, it requires a memory space of a) 4 bits b) 8 bits c) 16 bits d) 32 bits 5. In UNICODE, it requires 2 bytes or 16 bits to represent a character in different languages including English language. Which of the following code represents English character? a) 00000001 00000111 b) 00000010 01110101 c) 00000100 01011111 d) 00000011 01110111 e) 00000000 01010111 6. If each pixel of a picture can have one of the 32 colors,, how many bits it requires to store color information? a) 2 bits b) 3 bits c) 4 bits d) 5 bits e) 6 bits 7. One pixel of a picture requires 8 bits to store color information. At least, how many bytes necessary to store picture with 80,000 pixels? a) 300,000 b) 240,000 c) 100,000 d) 80,000 8. How many bits does it requires to store an RGB-color picture? a) 8 b) 16 c) 24 d) 32 9. Which of the following is a high-level language? a) Machine code b) Java language c) Assembly language d) Mnemonic code 10. Which header file is needed if your program uses setprecision? a) iostream b) iomanip c) fstream d) cmath 11. Which of the following is a valid identifier in C++? a) LastFirstMiddle b) Last.First.Middle c) Last-First-Middle d) Last&First&Middle 12. In C++, cin refers to: a) a CD-ROM drive b) a floppy disk drive c) the display screen d) the keyboard

Test 1: page 2 of 6 13. In C++, if we want a variable to hold or store a decimal value, an appropriate type for declaring the variable is a) string b) double c) char d) int 14. After the following statement is executed, what does the computer do? int interestrate; a) Declare interestrate to be variable b) Set interestrate to be int type c) Allocate a memory space to interestrate d) Declare interestrate to be int type 15. What is the output of the following code? int Integer1 = 57; cout<<"integer1"; a) 57 b) "Integer1" c) Integer1 d) syntax error 16. Which of the following is a valid constant declaration? a) const int LastYear = 2001; b) const int = 2001; c) const 2001; d) const int 2001 = Lastyear; 17. What is the value of the following C++ expression: 20/3? a) 6.67 b) 6 c) 2 d) 0 18. What is the value of the following C++ expression: 20/3.0? a) 6.67 b) 6 c) 2 d) 0 19. What is the value of the following C++ expression: 20.0/3? a) 6.67 b) 6 c) 2 d) 0 20. In C++, the value of the expression 27%4 is a) 1 b) 2 c) 3 d) 4 21. In C++, the value of the expression 13/3%2 is a) 1 b) 2 c) 3 d) 4 22. What is the value of the expression: 2 + 3 * 4-5 a) -5 b) 20 c) -1 d) 9 23. Which of the following statements prints Have A Nice Day! on one output line? a) cout<<"have A "<<endl; cout<<"nice Day!"<<endl; b) cout<<"have A "; cout<<"\nnice Day!"<<endl; c) cout<<"have A " <<"Nice Day!"<<endl; d) cout<<"have A " <<"\nnice Day!"<<endl; 24. What manipulator(s) will set the floatingpoint values to decimal number? a) fixed b) setw c) left d) right

Test 1: page 3 of 6 25. If we want a program to use file for input or output, we have to include header file a) iostream b) iomanip c) cmath d) fstream 26. Assume that the declaration of logical file variable is fstream InFile; Which of the following code is used to open the file to read? a) InFile.open("Test.txt",ios::out); b) InFile.open("Test.txt",ios::in); c) InFile.open("Test.txt"); d) All of the above 27. If Age is an int variable containing the value 45, which output statement will produce the following output: 1234567890 Age: 45 a) cout<<"1234567890"<<endl <<"Age:"<<setw(2)<<Age; b) cout<<"1234567890"<<endl <<"Age:"<<setw(3)<<Age; c) cout<<"1234567890"<<endl <<"Age:"<<setw(4)<<Age; d) cout<<"1234567890"<<endl <<"Age:"<<setw(5)<<Age; 28. What is the output of the following program fragment? int INumber1 = 3214, INumber2 = 83; cout<<setw(5)<<inumber1<<endl <<setw(5)<<inumber2<<endl; a) 3214 83 b) 3214 83 c) 32140 83000 d) 3214 83 29. What is the output of the following program fragment? double DNumber1 = 32.145; double DNumber2 = 283.75; cout<<fixed<<setw(2)<<dnumber1<<endl <<DNumber2<<endl; a) 32.145 283.75 b) 32.145000 283.750000 c) 32.145 283.75 d) 32.1450 283.750 30. Given the following code: char Letter1,Letter2,Letter3; cin>>letter1>>letter2>>letter3; cout<<letter1<<letter2<<letter3; and the input as follows 12 34 What is the output? a) 123 b) 12 c) 12 3 d) 12 34 31. Given the following code: char Letter1,Letter2; int Num; cin>>letter1>>letter2>>num; cout<<letter1<<letter2<<num; and the input as follows 123456 What is the output? a) 123 b) 1234 c) 12345 d) 123456

Test 1: page 4 of 6 32. Given the input stream as 123 4567 89ABCDEF GH\n 987 65\n What is the output of the following code? cin>>inum1>>inum2; cin.ignore(50,'d'); cin>>inum3; cout<<inum1<<' '<<INum2<<' ' <<INum3; a) 123 4567 89 b) 123 4567 987 c) 123 4567 EF d) 123 4567 65 33. Given the input stream as 1234567890 ABCDEF \n GH 987 65\n What is the output of the following code? cin.ignore(10,\n); cin>>letter1>>letter2; cin.ignore(100,'d'); cin>>letter3, cout<<letter1<<' '<<Letter2 <<' '<<Letter3; a) A B b) A B C c) A EF d) A E 35. The following is a formula to compute the final price after 25% discount: price = price (1- discount) Assume the following declaration: const double Rate = 0.25; double Purchase; Which of the following assignment statement that computes the final price? a) Price = Price*(1-Discount); b) Purchase = Purchase*(1-Rate); c) Purchase = Purchase(1-Rate); d) Price = Price(1-Discount); 34. Which assignment statement could be used to store the letter A into the char variable somechar? a) somechar = "A"; b) somechar = A; c) somechar = 'A'; d) somechar == "A"

Test 1: page 5 of 6 Part II (30 Points) An online retail company will charge 8.25% sales tax if an order will be delivered anywhere in Texas. A standard of $5.95 shipping will be added to all order. Write a C++ program to determine the total sales amount of an order that the company receives. The total sales amount is the sum of the amount of the order, sales tax if applicable, and the shipping cost. The program will ask for the amount of the order and the state for delivery. Then output the amount of the order, sales tax, the shipping cost and the total sales amount. All numbers should be displayed in with 2 decimal places. Use setw() to format the output. The following are samples of input and output. Email project folder to ongards4@yahoo.com Input/output samples:

Test 1: page 6 of 6 #include <iostream> #include <iomanip> #include <string> using namespace std; int main() { const double Shipping = 5.95; const double taxrate =.0825; double Sales, TotalAmount, Tax; string State; cout<<"enter the amount of the order -->"; cin>>sales; cout<<"enter the state where the order will be delivered. TX for Texas, AZ for Arizona -->"; cin>>state; if (State == "TX") Tax = Sales*taxRate; else Tax = 0; TotalAmount = Sales + Shipping + Tax; cout<<fixed<<setprecision(2); cout<<endl; cout<<"**************************************************"<<endl; cout<<"** Online Retail Company **"<<endl; cout<<"**************************************************"<<endl; cout<<"\nthe order amount is "<<setw(15)<<"$"<<setw(9)<<sales; cout<<"\nthe sales tax is "<<setw(18)<<"$"<<setw(9)<<tax; cout<<"\nthe shipping is "<<setw(19)<<"$"<<setw(9)<<shipping; cout<<"\nthe total amount of the order is "<<setw(2)<<"$"<<setw(9)<<totalamount; cout<<"\n\nthank you for shopping with us!!!"; cin.get(); cin.get(); } return 0;