C++ Quiz 1
Determine the output of the following C++ program (without running the program) # include <iostream> # include <string> using namespace std; void main () { const string STAR35 = "***********************************"; const char STAR = '*'; const string BLANK33 = " "; const string MSG = "Welcome to C++ Programming!"; const string BLANK3 = " "; cout << STAR35 << endl << STAR << BLANK33 << STAR << endl; cout << STAR << BLANK3 << MSG << BLANK3 << STAR << endl; cout << STAR << BLANK33 << STAR << endl << STAR35 << endl; }
*********************************** * * * Welcome to C++ Programming! * * * ***********************************
What is the 8 bits binary (base 2) representation of the integer 119?
01110111 base 2
There are 5 units in a typical computer hardware architecture, list them.
1) Input unit 2) Output unit 3) Memory Unit 4) Central Processing Unit 5) Secondary Storage Unit
Two Areas are typically associated with computers, Computer Hardware and Computer Software; define what does each area refers to?
1) memory: memory is a circuit that can store 0s and 1s in each of a series of thousands of addressed locations. 2) processor: circuits that support different calculations. They are used to process (execute) a list of desired calculations (each calculation = instruction)
What is the output of the following C++ code fragment? int i = 5, j = 6, k = 7, n = 3; cout << i + j * k - k % n << endl; cout << i / n << endl;
46 1
What is the integer decimal (base 10) number being represented by the following 8 bits binary number: 00101110?
46 base 10
How many "bits" there are in 1 Byte?
8 bits = 1 byte
A CPU consists of two main areas: ALU and CU, state what each stands for and its function within the CPU.
ALU: (Arithmetic and logic unit) performs arithmetic calculations (addition, subtraction, etc.) and logic units (>,<,=, etc.). CU: (control unit) supervises and coordinates the other sections of the computer by decoding each machine instruction and sends signals to other components for carrying out the instruction.
What unit do we use to measure the capacity of a computer memory?
Bytes
What does CPU stands for?
Central Processing Unit
What is a computer?
Device capable of performing computations and making logical decisions. It can also process data.
Give an example for each of the following: Input Unit, Output Unit, and a Secondary Storage Unit.
Input Unit: Keyboard Output Unit: Printer Secondary Storage Unit: USB Hard Drive
In the Problem Solving Methodology, it asks to describe Input(s) and Output(s), Define what is considered Input(s) and What is considered output(s)
Input: input is described as as information used to collect information from the user. Devices that are used to collect information from the user (input) are mouses, keyboards, etc. Output: output is described as information that is being given to the user. Devices used to give information to the user (output) are screens, speakers, printers, etc.
Give a name of a well-known microprocessor manufacturer.
Intel
Give 6 Examples of High Level Programming Languages other than C++.
Java, Swift, Javascript, Ruby, Python, Pascal
Computer Programming Languages went through 3 development stages: Machine Language, Assembly Language, and High Level Languages; briefly describe each, highlighting the differences between them.
Machine Language: Programs that are instructions written in binary code. Assembly Language: Programs that are instructions made up of mnemonics. High-Level Languages: Use statements that resemble English phrases combined with mathematical terms needed to express the problem or task being programmed. (ex. Java, Python, etc) Compiler Process: High-Level Languages --> Assembly Languages --> Machine Languages
Computer Software is divided into two main areas of Software: Operating Systems (OS) and Application Software, Define each area giving examples of each.
Operating System (OS): the software that supports that supports a computer's basic functions (ex. macOS Mojave). Application Software: Software designed to perform a group of coordinated functions, tasks, or activities for the benefit of the user.
What is the difference between RAM (Random Access Memory) and ROM (Read Only Memory)?
RAM: memory that is for the operating system. Programs and processes use RAM when the computer is running. (volatile ---> temporary) ROM: memory that comes with your computer that is prewritten to hold the instructions for booting-up the computer. (non-volatile ---> permanent)
What is an Op-Code (operation code)?
The command part of a computer instruction.
Given that variables dollars, quarters, dimes, nickels, pennies and TotalPennies are properly declared as integers and assigned proper values, write a C++ statement that computes the total amount of the money in pennies represented in the variables and store it into variable TotalPennies.
TotalPennies = pennies + (nickels * 5) + (dimes * 10) + (25 * quarters) + (100 * dollars);
Write a C++ expression to convert a time stored in the integer variables hours, minutes, and seconds, into the number of seconds represented by the time and assign its result to the variable TotalTimeInSeconds. (this should be a single valid C++ statement)
TotalTimeInSeconds = seconds + (60 * minutes) + (3600 * hours);
What is an Assembler?
Used to convert assembly language (mnemonic codes) to machine language
Convert the following numbers into standard decimal form: a) 1.26e3 b) 6.5623e3 c) 3.42695e4 d) 4.8932e4 e) 3.21e-1 f) 1.23e-2 g) 6.789e-3
a) 1260 b) 6562.3 c) 34269.5 d) 48932 e) 0.321 f) 0.0123 g) 0.006789
Write C++ expressions that implement each of the following formulas (you must use the math library function where appropriate) Note: Assume all variables have been properly declared and assigned. a - f refer to: https://s3.us-east-1.amazonaws.com/blackboard.learn.xythos.prod/5a33ed4744755/4762541?response-content-disposition=inline%3B%20filename%2A%3DUTF-8%27%27Lecture%25203%2520Review%2520Questions.pdf&response-content-type=application%2Fpdf&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20191012T175206Z&X-Amz-SignedHeaders=host&X-Amz-Expires=21600&X-Amz-Credential=AKIAIL7WQYDOOHAZJGWQ%2F20191012%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=25de6011eef3a26e5b6506b38891d2915d395543143f05085db14aceaadf9e35
a) 3 * x + y b) pow(A,2) + 2 * B + C c) ((A + B) / (C-D)) * (x / y) d) ((pow(A,2) + 2 * B + C) / D) / (x * y) e) sqrt(abs(A - B)) f) pow(x, -cos(y))
Write the following decimal numbers using scientific (exponent) notation: a) 63400 b) 19.5162 c) 839.5 d) 0.000295 e) 0.0004623
a) 6.34e4 b) 1.95162e1 c) 8.395e2 d) 2.95e-4 e) 4.623e-4
Evaluate each of the following C++ expressions into its equivalent value; if an expression produces a floating point value, then you must indicate that by using a decimal point. If an expression produces an error, then you must state so, indicating the reason for the error: a) 3 + 6 b) 3.4 - 6.1 c) 2 * 3 d) 8 / 2 e) 8.0 / 2.0 f) 8 / 8 g) 8 / 9 h) 8 / 7 i) 8 % 8 j) 8 % 9 k) 8 % 7 l) 0 % 7 m) 5 % 2.3 n) 10 / 2 * 3 o) 10 % 3 - 4 / 2 p) 5.0 * 2.0 / 4.0 * 2.0 q) 5.0 * 2.0 / (4.0 * 2.0) r) 5.0 + 2.0 / (4.0 * 2.0) s) 27 + 8 * 6 - 44 % 5 t) 27 + 8 / 5 - 7 u) 27.0 + 8 / 5.0 - 7.0 v) 25 % 7 + 9.0 w) 17++ x) int (15.0 + 12.0 * 2.2 - 3 * 7) y) --23 z) 18 / 1.0
a) 9 b) -2.7 c) 6 d) 4 e) 4.0 f) 1 g) 0 h) 1 i) 0 j) 8 k) 1 l) 0 m) error: cannot mod a float n) 24 o) -1 p) 4 q) 1 r) 0 s) 71 t) 21 u) 23.0 v) 13.0 w) error: only works on variables x) 18 y) error: only works on variables z) 18.0
a) Write a valid C++ statement to declare two double precision floating-type variables, name them UserInput, and Result. b) Write a valid C++ statement to prompt the user of the program to Enter a Positive Value. c) Write a valid C++ statement to read the user entered value and store it into the variable UserInput. d) Write a valid C++ statement to utilize a math library function that calculates the square root of the user entered value (which is stored into variable UserInput) and assign the result to variable Result. e) Write a valid C++ statement (single statement) that will display the square root of the user entered value (which is stored into variable Result). The value displayed must be preceded by an appropriate message and it must be shown with exactly two digits after the decimal point whether the digits are significant or not significant.
a) double UserInput, Result; b) cout << "Enter a positive value" << endl; cin >> PositiveValue; c) cout << "you said, " << UserInput << "." << endl; d) Result = sqrt(UserInput); cout << Result << endl; e) Result = sqrt(UserInput); cout << "The square root of " << UserInput << " is" << fixed << setPrecision(2) << Result << endl;
. Fill in the blanks in each of the following sentences: The first 4 sentences are about the C++ environment (Cycle) a) C++ programs are normally typed into a computer using an _______ program. b) In a C++ system, a _______________ program executes before the compiler's translation phase begins. c) The ____________ program combines the output of the compiler with various library functions (or files) to produce an executable image. d) The ____________ program transfers the executable image of a C++ program from disk to memory. e) Every C++ program begins execution at the function _________. f) The ____________________ begins the body of every function and the _____________________ ends the body of every function. g) Every C++ statement ends with a ___________.
a) editor b) preprocessor c) linker d) loader e) main() f) {} curly brackets g) ; semicolon
State if each of the following is a Valid or Invalid C++ identifier, make sure you give the reason for the Invalid ones: a) theDog b) all-In-One c) const d) recycling e) DVD_ROM f) elizabeth_the_2nd g) 2morrow h) page#
a) valid b) Invalid: cannot have dashes c) Invalid: cannot be a reserved word d) valid e) valid f) valid g) Invalid: cannot start with a number h) Invalid: cannot have a pound sign
Given integer variable days that contains a number of days, a) Write a C++ expression that gives the number of whole weeks corresponding to days. For example, if days contains 23, then the number of whole weeks is 3. (Assume all variables are properly declared and assigned values) b) Write a C++ expression that gives the number of days remaining after taking the whole weeks out of the value in days. For example, if days contains 23, then the number of days remaining after 3 whole weeks is 2. (Assume all variables are properly declared and assigned values)
a) weeks = days / 7; b) weeks = days / 7; days = days % 7;
What do we call the smallest piece of information that we can store in computers?
bits
What is a computer program? What is computer programming?
computer program: commands that are written as a set of instructions computer programming: computer programming is communicating with a computer to complete a task.
What is a Compiler?
converts the whole high level language to machine language.
Write a single valid C++ output statement that outputs the following three lines: He said, "How is that possible?" She replied, "Using manipulators." "Of course!" he exclaimed.
cout << "He said, \"How is that possible?\"" << endl << "she replied, \"Using manipulators.\""<< endl << "\"Of course!\" he exclaimed." << endl;
Given the same variables in problem 10, compute the total but store it in a floatingpoint variable that you should declare and name money so that the integral part of money is dollars and the fractional part is cents.
double money = double(TotalPennies) / 100;
Write a valid C++ statement to declare variable count as an integer and initialize it to 25. Then write a valid C++ abbreviated assignment statement that increments the value of variable count by 32.
int count = 25; count += 32;
Write a set of valid C++ statements to give the values 2, 20, and 12 to the variables hours, minutes, and seconds respectively.
int hours = 2, minutes = 20, seconds = 12;
Write a valid C++ statement (single statement) to declare the variables hours, minutes, seconds and TotalTimeInSeconds to hold integer values.
int hours, minutes, seconds, TotalTimeInSeconds;
What is an Algorithm? Give a real life example of an algorithm you follow in your life
set of chronological directions used to solve a problem. example from everyday life: following a recipe
What is a Source Code (Source Program)? What is an Object Code (Object Program)?
source code: a text listing of commands to be compiled or assembled into an executable computer program. object code: code produced by a compiler or an assembler.
What is a Syntax Error? What is a Logical Error? Of course we all love to have our programs to be free of all types of errors, but If your program is to have one of these two types of errors which one you rather have in your program, and why?
syntax error: a syntax error is an error that has to do with a mistake in the "grammar" of the program. ex. forgetting a semicolon logical error: a mistake in the code that causes the program to not operate correctly. ex. getting the wrong output If I were to chose which error I'd prefer to have I would prefer to have a syntax error because its easier to find the "grammar" mistake than to find where I went wrong in my logical approach to my program.
What does the term "debugging" means?
the process of determining and fixing the cause of a problem in a computer program.