Example 1
Part 1: Fill in the Blanks
_____________________________________________________ machine language
_____________________________________________________ assembly language
_____________________________________________________ high-level language
line on the screen. /n
data member
newline character is encountered, then copies those characters into the
specified string. getline ().
header must include the class name and the _______________, followed by the
function name. scope resolution operator or ::
extension. .h
_______________________. number, type, and order of parameters received.
____________________________ implementation
Part 2: True – False
Indicate whether the following statements are true or false by placing a check mark (√) in the
appropriate column.
|
True |
False |
All variables must be given a type when they are declared |
ü |
|
All variables must be declared before they are used |
ü |
|
Declarations can appear almost anywhere in the body of a C++ function |
ü |
|
When applied to integers, the modulus operator will return the quotient |
|
ü |
/ instructs the compiler to ignore code to end of the line |
|
ü |
Preprocessor directives end with a semicolon |
|
ü |
White space characters in strings are ignored by the compiler |
|
ü |
C++ is case sensitive |
ü |
|
When a new value is placed in a memory location, the old value is destroyed |
ü |
|
When a value is read from memory, the value originally in the memory location is destroyed |
|
ü |
All functions must be enclosed by braces |
ü |
|
C++ evaluates equal precedence arithmetic functions right to left |
|
ü |
Parentheses can be used to force the order of evaluation |
ü |
|
cin << is used to read input from the keyboard |
|
ü |
A constructor that takes no arguments is called a default constructor |
ü |
|
A class interface describes the public member functions |
ü |
|
A class interface describes what services a user can request |
ü |
|
A class interface does not describe how requests are carried out |
ü |
|
The driver file has a .h extension |
|
ü |
The implementation file has a .h extension |
|
ü |
public is a keyword – it is an access specifier |
ü |
|
You can use the return keyword in a function declared to have return type void |
|
ü |
Part 3: Analyze Code
#include<iostream.h>
int main ()
{
cout <<"This is an";
cout <<" "<<"illustration of";
cout <<" output in C++"<<endl;
return 0;
}
This is an illustration of output in C++
#include <iostream.h>
int main ()
{
int a = 10;
int b = 20;
if (a = b)
cout <<"This prints"<<endl;
if (b > a)
cout <<"This prints also"<<endl;
return 0;
}
This prints
Part 4a: Write Code Segments
Given that you have a class named Mosquito. The class has a parameterless constructor and a constructor that accepts an integer parameter. It also has a public function named walk. The walk function takes an integer parameter.
named object of the Mosquito class that calls the parameterless constructor.
Mosquito biter ();
an appropriate parameter.
int x = 5;
biter.walk(x);
Part 4b. Write a Complete Class
Write a class named Banking (interface separate from implementation) that has
Place the interface here.
class Banking //Assume this file named banking.h
{
public: //Constructors and member functions declared public
Banking ();
Banking (int member, double amountIn);
double Status (double amount);
private: //Data members declared private
int customerID;
double deposit;
};
Place the definition here
#include <iostream.h> < > indicate a standard C++ header file
#include “banking.h” //Quotations indicate a user written header file
Banking::Banking() //Note the scope resolution operator (:: and why it is used)
{
customerID = 0;
deposit = 0.0;
}
Banking::Banking(int custNumber, double custDeposit)
{
customerID = custNumber;
deposit = custDeposit;
}
Banking::Status ()
{
return deposit;
}
NOTE: A DRIVER WAS NOT REQUIRED - ONE IS PROVIDED BELOW
#include <iostream.h>
#include "banking.h"
int main ()
{
int memberNumber = 0;
double deposit = 0;
cout <<"What is your member number?"<<endl;
cin >> memberNumber;
cout << "How much do you wish to deposit?<<endl;
cin >> deposit
Banking myBank (memberNumber, deposit) //Creating an object and calling constructor
cout <<"Your deposit was: "<<myBank.status<<endl; //Printing amount of deposit
return 0;
}
Part 5: Extra credit
Identify the following contributors to the field of Computer Science or computers.
First and last names must be given to receive credit.
Father of computer science: ________________ Alan Turing
Wrote the first program: ________________ Agusta Byron
Wrote the first compiler: ________________ Grace Murray Hopper
Designed the ENIAC: ________________ John Mauchley
Developed the stored-program concept: ________________ John von Neumann
Developed the first computer: ________________ Charles Babbage
The Boolean data type is named after him: ________________ George Boole
Developed the transistor: __________________ William Shockley