• When a program is not running, it is stored
  • RAM, random-access memory, is called that because
  • The code that a programmer writes is called _____ code.
  • Compilers translate the instructions written by the programmer into _____ code.
  • Words that have a special meaning in a programming language are called _____.
  • Suppose your name was Alan Turing. Write a statement that would print your last name , followed by a comma, followed by your first name . Do not print anything else (that includes blanks).
  • Suppose your name was George Gershwin. Write a complete program that would print your last name , followed by a comma, followed by your first name . Do not print anything else (that includes blanks).
  • Given an integer variable count, write a statement that writes the value of count to standard output .
  • Write the include directive needed to allow use of the various I/O operators such as cout and cin .
  • Write a complete program that declares an integer variable , reads a value from the keyboard into that variable , and writes to standard output the square of the variable 's value . Besides the number, nothing else should be written to standard output.
  • Every C++ program must contain a ____ function.
  • Which of the following is not a statement?
  • Which of the following IS a statement?
  • The rules that govern the correct order and usage of the elements of a language are called the ____ of the language.
  • An error in a program that involves a violation of language rules will be detected at ____ time.
  • Division by zero when the program is executing is an example of a ____ error.
  • The purpose of testing a program with different combinations of data is to expose run-time and ____ errors.
  • Which string does NOT match the regular expression: "v.x.*"?
  • Write the necessary preprocessor directive to enable the use of file streams.
  • Define an object named outfile that can be used to write data from program variables to a file.
  • Define two objects named outfile1 and outfile2 that can be used to write data from program variables to two different files.
  • Define an object named infile that can be used to read data into program variables from a file.
  • Define two objects named infile1 and infile2 that can be used to read data into program variables from two different files.
  • Given an ofstream object named output , associate it with a file named yearsummary.txt by opening the file for writing.
  • Given that corpdata is an ifstream object that has been used for reading data and that there is no more data to be read, write the necessary code to complete your use of this object .
  • Given the availability of an ofstream object named output , write the other statements necessary to write the string "3.14159" into a file called pi . (Do not define a main function.)
  • Given an ifstream object named input , associate it with a file named hostdata by opening the file for input.
  • Given the availability of an ifstream object named input , write the other statements necessary to read an integer into a variable datum that has already been declared from a file called rawdata . Assume that reading that one integer is the only operation you will carry out with this file. (Note: write just the statements , do not define a main function.)
  • Read first a user's given name followed by the user's age from standard input. Then use an ofstream object named outdata to write this information separated by a space into a file called outdata . Assume that this is the extent of the output that this program will do.
  • Given an int variable x write some statements that attempt to open a file named "table20" and read a value into x ; if that turns out not to be possible your code should then read avalue from standard input into x .
  • Given a bool variable fileExists write the necessary code to set this variable to true if the file "crucial_data" exists and sets it to false otherwise.
  • Write the necessary preprocessor directive to enable the use of the exit function.
  • Write the definition of a function named panic . The function prints the message "unrecoverable error" and then terminates execution of the program , indicating failure..
  • Given an ofstream object named output , associate it with a file named yearsummary.txt by opening the file for appending.
  • Given an fstream object named todo , associate it with a file named todolist by opening the file for appending.
  • Given an fstream object named menu , associate it with a file named todaysmenu.txt for output in a way that truncates (erases) any existing data in the file.
  • Given a file named execution.log write the necessary code to add the line "Program Execution Successful" to the end of the file.
  • Given an initialized variable fileName, write a sequence of statements that create a file whose name is given by the variable and whose content is a single line consisting of "This Is File: " followed by the name of the file. Make sure that the data written to the file has been flushed from its buffer and that any system resources used during the course of running these statements have been released. (Do not concern yourself with any possible exceptions here-- assume they are handled elsewhere.)
  • Write the necessary preprocessor directive to enable the use of the stream manipulators like setw and setprecision.
  • Assume that m is an int variable that has been given a value . Write a statement that prints it out in a print field of 10 positions.

Given three variables , a, b, c, of type double that have already been declared and initialized , write some code that prints each of them in a 15 position field on the same line, in such away that scientific (or e-notation or exponential notation) is avoided. Each number should be printed with 5 digits to the right of the decimal point. For example, if their values were 24.014268319, 14309, 0.00937608, the output would be:

|xxxxxxx24.01427xxxx14309.00000xxxxxxxx0.00938

NOTE: The vertical bar, | , on the left above represents the left edge of the print area; it is not to be printed out. Also, we show x in the output above to represent spaces-- your output should not actually have x's!

Given three variables , a, b, c, of type double that have already been declared and initialized , write some code that prints each of them in scientific (also known as e-notation or exponential notation) in a 10 position field on the same line. Each number should be printed with 3 digits to the right of the decimal point. For example, if their values were 987654321, 1234, 0.00987654321, the output would be:

|x9.877e+08x1.234e+03x9.877e-03

NOTE: The vertical bar, | , on the left above represents the left edge of the print area; it is not to be printed out. Also, we show x in the output above to represent spaces-- your output should not actually have x's!

Write a statement that reads 5 successive integers into these variables that have already been declared : x1 x2 x3 x4 x5 . Then write a statement that prints each out on its own line so that they form a right-justified column with a 5-digit width. If any of the integers are 5-digits in size, then they will start at the very beginning of their lines. For example:

|54213
| 8713
| 23
| 147
| 15

NOTE: The vertical bar, | , on the left above represents the left edge of the print area; it is not to be printed out. Also, we show x in the output above to represent spaces-- your output should not actually have x's!

  • A variable c of type char has been declared . Write the necessary code to read in the next character from standard input and store it in c , regardless of whether is a whitespace character .
  • Assume that c is a char variable has been declared . Write some code that reads in the first character of the next line into c . Assume that the lines of input are under 100 characters long.
  • An array of 1000 integers is declared. What is the largest integer that can be used as an index to the array?
  • Consider the declaration: int v[1]; What is the index of the last element of this array?
  • Write a statement that declares an array of char named streetAddress that contains exactly eighty elements .
  • Suppose v is an array with 100 int elements. If 100 is assigned to v[100], what happens?
  • Declare an array named scores of twenty-five elements of type int
  • Given an array a , declared to contain 34 elements , write an expression that refers to the last element of the array .
  • Assume that the array monthSales of integers has already been declared and that its elements contain sales data for the 12 months of the year in order (i.e., January, February, etc.). Write a statement that writes to standard output the element corresponding to October. Do not write anything else out to standard output .
  • Assume that an array of integers named salarySteps that contains exactly five elements has been declared . Write a statement that assigns the value 160000 to the last element of the array salarySteps .
  • Assume that an array named a , containing exactly five integers has been declared and initialized . Write a single statement that adds ten to the value stored in the first element of the array .
  • Given that an array of int named a with 30 elements has been declared , assign 5 to its last element .
  • Assume that an array of int named a has been declared with 12 elements and that the integer variable k holds a value between 0 and 6. Assign 15 to the array element whose index is k .
  • Given that an array of int named a has been declared , and that the integer variable n contains the number of elements of the array a, assign -1 (minus one) to the last element in a.
  • Given an array arr of type int , along with two int variables i and j , write some code that swaps the values of arr[i] and arr[j] . Declare any additional variables as necessary.
  • Given an array temps of double , containing temperature data, and an int variable n that contains the number of elements in temps : Compute the average temperature and store it in a variable called avgTemp . Besides temps , n , and avgTemp , you may use only two other variables -- an int variable k and a double variable total , which have been declared .
  • Declare an array named taxRates of 5 elements of type double and initialize the elements (starting with the first) to the values 0.10, 0.15, 0.21, 0.28, 0.31, respectively.
  • Write a statement to declare and initialize an array of int named denominations that contains exactly six elements . Your declaration statement should initialize the elements of the array to the following values : 1, 5, 10, 25, 50, 100. (The value 1 goes into the first element ; the value 100 to the last.)
  • printArray is a function that has two parameters . The first parameter is an array of element type int and the second is an int , the number of elements in the array . The function prints the contents of the array parameter ; it does not return a value . inventory is an array of int s that has been already declared and filled with values . n is an int variable that holds the number of elements in the array . Write a statement that prints the contents of the array inventory by calling the function printArray .
  • Write a statement that declares a prototype for a function printArray , which has two parameters . The first parameter is an array of element type int and the second is an int , the number of elements in the array . The function does not return a value .
  • Write the definition of a function printArray , which has two parameters . The first parameter is an array of int s and the second is an int , the number of elements in the array . The function does not return a value . The function prints out each element of the array , on a line by itself, in the order the elements appear in the array , and does not print anything else.
  • Given an int variable k , an int array incompletes that has been declared and initialized , an int variable nIncompletes that contains the number of elements in the array , an int variable studentID that has been initialized , and an int variable numberOfIncompletes , Write code that counts the number of times the value of studentID appears in incompletes and assigns this value to numberOfIncompletes . You may use only k , incompletes , nIncompletes , studentID , and numberOfIncompletes .
  • You are given an int variable k , an int array zipcodeList that has been declared and initialized , an int variable nZips that contains the number of elements in zipcodeList , and a bool variable duplicates . Write some code that assigns true to duplicates if there are two adjacent elements in the array that have the same value , and that assigns false to duplicates otherwise. Use only k , zipcodeList , nZips , and duplicates .
  • Declare a 3x3 two-dimensional array of integers named tictactoe .
  • Declare a two-dimensional character array named "gasgiants" that is capable of storing the names of the gas giant planets of our solar system: jupiter, saturn, uranus, and neptune. Do not make the array any larger than it needs to be.
  • Given a two-dimensional array x of doubles , write an expression whose value is twice the value of the element in the 3rd row and the 2nd column.
  • Given a two-dimensional array x of element type int , write an expression whose value is the sum of the element in the 3rd row/4th column and the element in the 5th row/1st column.
  • Given a two-dimensional array x of element type double , and two integer variables i and j , write an expression whose value is the i-th element in the j-th row.
  • Given a two-dimensional array of integers named q , with 2 rows and 4 columns, write some code that puts a zero in every element of q . Declare any variables needed to help you.
  • Declare an array of integers , westboundHollandTunnelTraffic that can store the number of vehicles going westbound through the Holland Tunnel on a particular hour (numbered 0 through 23) on a particular day (numbered 0 through 6) on a particular week numbered (0 through 51) over the last ten years (numbered 0 through 9). The innermost dimension should be years, with the next being weeks, and so on.
  • Declare and initialize a two-dimensional character array named "stooges" to store the names "moe", "larry" and "curly" (in that order). Do not make the array any larger than it needs to be.
  • Write an expression that evaluates to true if and only if the C-string s equals the C-string "end".
  • Write an expression that evaluates to true if the value of C-string lastName is greater than the C-string "Dexter" .
  • Write an expression that evaluates to true if and only if the C-string s does not equal "end" .
  • Declare a char array named line suitable for storing C-strings as large as 50 characters , and write a statement that reads in the next line of standard input into this array . (Assume no line of input is 50 or more characters .)
  • Given the availability of an ofstream object named output , and a string variable name tweet , write the other statements necessary to open a file named mytweet" , display the prompt tweet: and then read an entire line into tweet and then write it out to the file mytweet. (Do not define a main function.)
  • Declare a string named line and write a statement that reads in the next line of standard input into this variable .
  • Assume that word is a variable of type string that has been assigned a value . Assume furthermore that this value always contains the letters "dr" followed by at least two other letters. For example: "undramatic", "dreck", "android", "no-drip". Assume that there is another variable declared , drWord , also of type string . Write the statements needed so that the 4-character substring word of the value of word starting with "dr" is assigned to drWord . So, if the value of word were "George slew the dragon" your code would assign the value "drag" to drWord .
  • Given a string variable address , write a string expression consisting of the string "http://" concatenated with the variable 's string value . So, if the value of the variable were "www.turingscraft.com", the value of the expression would be "http://www.turingscraft.com".
  • Assume that name is a variable of type string that has been assigned a value . Write an expression whose value is the last character of the value of name . So if the value of name were "Blair" the expression 's value would be 'r'.
  • Assume that name is a variable of type string that has been assigned a value . Write an expression whose value is a string containing the first character of the value of name . So if the value of name were "Smith" the expression 's value would be "S".
  • Assume that name is a variable of type string that has been assigned a value . Write an expression whose value is a string containing the last character of the value of name . So if the value of name were "Smith" the expression 's value would be "h".
  • Assume that name is a variable of type string that has been assigned a value . Write an expression whose value is a string containing the second character of the value of name . So if the value of name were "Smith" the expression 's value would be "m".
  • Assume that word is a variable of type string that has been assigned a value . Write an expression whose value is a string consisting of the first three characters of the value of word . So if the value of word were "dystopia" the expression 's value would be "dys".
  • Assume that word is a variable of type string that has been assigned a value . Write an expression whose value is a string consisting of the last three characters of the value of word . So if the value of word were "biggest" the expression 's value would be "est".
  • Given the string variable address , write an expression that returns the position of the first occurrence of the string "Avenue" in address .
  • Write an expression that whose value is the fifth character of the string name .
  • Write a sequence of statements that finds the first comma in the string line , and assigns to the variable clause the portion of line up to, but not including the comma. You may assume that an int variable pos , as well as the variables line and clause , have already been declared .
  • Declare a vector named scores of twenty-five elements of type int .
  • Given the vector a , write an expression that refers to the first element of the vector.
  • Assume that the vector arr has been declared . In addition, assume that VECTOR_SIZE has been defined to be an integer that equals the number of elements in arr . Write a statement that assigns the next to last element of the vector to the variable x ( x has already been declared ).
  • Assume that the vector monthSales of integers has already been declared and that its elements contain sales data for the 12 months of the year in order (i.e., January, February, etc.). Write a statement that writes to standard output the element corresponding to October. Do not write anything else out to standard output .
  • Assume that an vector named a , containing exactly five integers has been declared and initialized . Write a single statement that adds ten to the value stored in the first element of the vector.
  • Given that an vector of int named a has been declared , and that the integer variable n contains the number of elements of the vector a , assign -1 to the last element in a .
  • Assume v is a vector that has been declared and initialized . Write an expression whose value is the number of values that have been stored in v.
  • Assume v is a vector that has been declared and initialized . Write an expression whose value is the maximum number of values could be stored in v.
  • Assume v is a vector that has been declared and initialized . Write an expression whose value is the number of values that could be additionally stored in v.
  • Assume v is a vector that has been declared and initialized . Write an expression whose true if there are any values stored in v.
  • Assume v is a vector that has been declared and initialized . Write a statement that removes ALL the values stored in v.
  • Assume v is a vector of integers that has been declared and initialized . Write a statement that adds the value 42 to the vector.
  • Define a new type called POINT that is a structure consisting of two fields, x and y , both of type double
  • Define a new type called POINT3D that is a structure consisting of three fields, x , y and z , each of type double .
  • Declare a structure whose tag name is Book and that contains exactly three fields (or members), each of type int . The first field is nCopies, the second field is nPages and the third field is nAuthors.
  • Declare a structure whose tag name is Money and that contains exactly two int fields, dollars and cents.
  • Define a new type called DATE that is a structure consisting of three int fields, dayOfMonth , month and year .
  • Given the declaration of a structure whose tag is DATE write the declaration of the following variables enrolled_on, paid_on, and completed_on, each of which is of type DATE..
  • Assume a structured type , PrecinctReport, with these fields, address (a string ), felonies, murders, and robberies. Declare an array named allPrecincts with NPRECINCTS elements , each of type PrecinctReport. (NPRECINCTS is a pre-declared constant .)
  • Assume that a new type called POINT has been defined-- it is a structure consisting of two fields, x and y , both of type double . Assume two variables p1 and p2 of type POINT have been declared . Assume that p1 has already been initialized . Write a statement that gives p2 the same value that p1 has.
  • Given a variable , mets, of type Team-- a structured type with a field named pitcher (a string ), write a statement that assigns "Acosta" to that field (pitcher) of that variable (mets).
  • Assume you have a variable price1 of type Money where the latter is a structured type with two int fields, dollars and cents. Assign values to the fields of price1 so that it represents $29.95.
  • The "origin" of the cartesian plane in math is the point where x and y are both zero. Given a variable , origin of type Point-- a structured type with two fields, x and y, both of type double , write one or two statements that make this variable 's field's values consistent with the mathematical notion of "origin".
  • Assume you have a variable sales of type Money where the latter is a structured type with two int fields, dollars and cents. Write a statement that reads two integers from standard input, a dollar amount followed by a cents amount, and store these values in the appropriate fields in sales.
  • In mathematics, "quadrant I" of the cartesian plane is the part of the plane where x and y are both positive. Given a variable , p that is of type POINT-- a structured type with two fields, x and y, both of type double -- write an expression that is true if and only if the point represented by p is in "quadrant I".
  • Assume you are given a variable , payRate of type Money (a structured type with two int fields, dollars and cents). Write the necessary code to increase the effective value of payRate by $1.50. To do this you need to add 50 to cents and 1 to dollars but you ALSO must make sure that cents does not end up over 99: if it does, you need to "carry a one" to dollars. For example, if payRate were $12.80 then a naive addition of $1.50 yields 13 (dollars) and 130 (cents). This would have to be changed to 14 (dollars) and 30 (cents).
  • In mathematics, the distance of a point with coordinates (x,y) from the origin is the square root of the sum of x-squared and y-squared. Given a variable , p that is of type POINT-- a structured type with two fields, x and y, both of type double , write an expression whose value is the distance of the point represented by p from the origin.
  • Assume that PrecinctReport is a structured type with these fields, address (a string ), and three int fields which are counts of crimes in the given precinct: felonies, murders, and robberies. Assume that NPRECINCTS is a pre-declared int constant and that an array named allPrecincts with NPRECINCTS elements , each of type PrecinctReport has been declared and initialized Assume that an int variable murderCount has been declared . Write the necessary code that traverses the allPrecincts array and adds up all the murder counts storing the resulting total in murderCount.
  • Assume that type Money, a structured type with two int fields, dollars and cents, has been declared . Also assume the availability of a function named normalize that receives a Money argument and returns a "normalized" Money value (i.e. one that is equivalent to the argument but where the cents values is between 0 and 99). Now write the definition of a function named addMoney that receives two Money arguments and returns their sum , in normalized form. So if the equivalent of $1.85 and $2.19 is passed the function would return the equivalent of $4.04.
  • Write a declaration for a variable salesAnnualof type Money (a structured type with two int fields, dollars and cents) and initialize it to represent $1,325,023.47.
  • Write a full class definition for a class named Acc2 , and containing the following members: A data member named sum of type integer . A constructor that accepts no parameters . THe constructor initializes the data member sum to 0. A member function named getSum that accepts no parameters and returns an integer . getSum returns the value of sum.
  • Write a full class definition for a class named Accumulator , and containing the following members: A data member named sum of type integer . A constructor that accepts no parameters . The constructor initializes the data member sum to 0. A member function named getSum that accepts no parameters and returns an integer . getSum returns the value of sum . A member function named add that accepts an integer parameter and returns no value . add increases the value of sum by the value of the parameter .
  • Write a full class definition for a class named Counter , and containing the following members: A data member counter of type int . A constructor that accepts no arguments and initializes the counter data member to 0. A function called increment that accepts no parameters and returns no value . increment adds one to the counter data member. A function called getValue that accepts no parameters . It returns the value of the instance variable counter.
  • Write a full class definition for a class named GasTank , and containing the following members: A data member named amount of type double . A constructor that no parameters . The constructor initializes the data member amount to 0. A function named addGas that accepts a parameter of type double . The value of the amount instance variable is increased by the value of the parameter . A function named useGas that accepts a parameter of type double . The value of the amount data member is decreased by the value of the parameter . A function named getGasLevel that accepts no parameters . getGasLevel returns the value of the amount data member.
  • Write a full class definition for a class named Counter , and containing the following members: A data member counter of type int . A constructor that takes one int argument and assigns its value to counter A function called increment that accepts no parameters and returns no value . increment adds one to the counter data member. A function called decrement that accepts no parameters and returns no value . decrement subtracts one to the counter data member. A function called getValue that accepts no parameters . It returns the value of the instance variable counter .
  • Write a full class definition for a class named Player , and containing the following members: A data member name of type string . A data member score of type int . A member function called setName that accepts a parameter and assigns it to name . The function returns no value . A member function called setScore that accepts a parameter and assigns it to score . The function returns no value . A member function called getName that accepts no parameters and returns the value of name . A member function called getScore that accepts no parameters and returns the value of score .
  • Write a full class definition for a class named Acc1 , containing containing no constructors , functions, or data members (i.e., a totally empty class ). (Note, the last character of the classname is "one" not "ell".)
  • Objects of the Calculator class require no additional information when created. Define an object named calc, of type Calculator.
  • Objects of the BankAccount class require a name (string ) and a social security number (string ) be specified (in that order)upon creation. Define an object named account , of type BankAccount , using the values "John Smith" and "123-45-6789" as the name and social security number respectively.
  • Objects of the Window class require a width (integer ) and a height (integer ) be specified (in that order) upon definition. Define an object named window, of type Window, corresponding to a 80 x 20 window.
  • Objects of the Window class require a width (integer ) and a height (integer ) be specified (in that order) upon definition. Define an object named window, of type Window, whose width and length are obtained from the (already declared and initialized ) variables , w and l.
  • Objects of the Window class require a width (integer ) and a height (integer ) be specified (in that order) upon definition. Declare two integers corresponding to a width and a length and read values into them from standard input (in that order). Use these value to define an object of type Window named newWindow.
  • Creating objects of the Currency class require a name (string ), a currency symbol (string ) and the number of decimal places (integer ) usually associated with the currency (in that order). Define an object named curr, of type Currency corresponding to "US Dollar" with the symbol "$" and 2 decimal places.
  • Objects of class Name are defined by supplying last name (string ) and a first name (string )-- in that order. Define an object of type Name named name and corresponding to a last name of "Black" and a first name of "Susan".
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.