Exam 1 Review: Chapters 1-6 & 10 Concepts
15 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

When one control statement is located within another, it is said to be ________.

nested

What is the significance of \n and \t in C++?

  • They are arithmetic operators.
  • They are examples of escape sequences. (correct)
  • They are loop control statements.
  • They are used for variable declarations.

Given the array declaration int myArray[12] = {1,2,3,6,5,4,7,1,2};, how many indexed variables does the array have?

12

In the statement cout << *p1;, what does the * symbol signify?

<p>Dereference operator (D)</p> Signup and view all the answers

If a while loop's condition never becomes false, a deadlock will occur.

<p>False (B)</p> Signup and view all the answers

In a switch statement, if the value of the expression does not match any of the case values, the statements following the ________ label execute.

<p>default</p> Signup and view all the answers

To use functions for manipulating C-style strings, what library must be included in C++?

<p>cstring</p> Signup and view all the answers

In C++, what is :: called?

<p>Scope Resolution Operator (D)</p> Signup and view all the answers

A ________ is a way of changing a value of one type to a value of another type.

<p>type cast</p> Signup and view all the answers

The << operator always follows the cin object, and the >> operator follows the cout object.

<p>False (B)</p> Signup and view all the answers

By default, what is the access level for all members of a class?

<p>private</p> Signup and view all the answers

When is a variable passed by reference?

<p>When changes to the formal parameter also affect the actual parameter (A)</p> Signup and view all the answers

To use setw, you need to #include the ________ library.

<p>iomanip</p> Signup and view all the answers

When more than one function has the same name, they are called ________ functions.

<p>overloaded</p> Signup and view all the answers

The ________ of a variable is where that variable can be used.

<p>scope</p> Signup and view all the answers

Flashcards

Nested control statement

When a control statement is located inside another.

Escape sequences

Newline and tab

Array size

The number of elements the array can hold, specified during declaration.

  • operator (in cout << *p1;)

Dereference operator

Signup and view all the flashcards

Infinite loop

A loop that continues indefinitely because its terminating condition is never met.

Signup and view all the flashcards

switch Statement's Default

default

Signup and view all the flashcards

Include for C-strings

#include

Signup and view all the flashcards

:: in C++

Scope resolution operator

Signup and view all the flashcards

Changing a variable's data type

Type casting

Signup and view all the flashcards

<< operator

Insertion operator

Signup and view all the flashcards

Default class member access

private

Signup and view all the flashcards

Passing a variable

by reference

Signup and view all the flashcards

Library for setw

#include

Signup and view all the flashcards

Functions with the same name

Overloaded

Signup and view all the flashcards

Variable's Visibility

scope

Signup and view all the flashcards

Study Notes

Exam 1 Review General Concepts

  • Exam 1 covers chapters 1, 2, 3, 4, 5, the structures and classes section of chapter 6, and the pointers part of chapter 10.
  • Material from the book, labs, and slides is relevant

Fill-in-the-Blanks

  • When a control statement is inside another, it is nested.
  • \n (newline) and \t (tab) are examples of escape sequences.
  • The array int myArray[12]={1,2,3,6,5,4,7,1,2} has 12 indexed variables.
  • In cout << *p1;, the * is the dereference operator.
  • A(n) infinite loop may occur if nothing within a while loop causes the condition to become false.
  • In a switch statement, statements after the default label execute if no case values match.
  • To use functions for manipulating c-strings, the <cstring> library must be included.
  • In C++, :: is the scope resolution operator.
  • Casting is changing a value's type to another type.
  • The extraction operator >> follows cin, and the insertion operator << follows cout.
  • Class members are private by default.
  • If a variable is passed by reference, changes to the formal parameter affect the actual parameter.
  • To use setw, the <iomanip> library must be included.
  • Functions with the same name are overloaded functions
  • The scope of a variable determines where it can be used.
  • The six comparison operators in C++ are:
    • == (equal to)
    • != (not equal to)
    • < (less than)
    • > (greater than)
    • <= (less than or equal to)
    • >= (greater than or equal to)

True or False

  • False, the amount of memory depends on both the number of elements and the size of each element.
  • True
  • False, C-strings are character arrays, while string objects are instances of the string class, offering more functionality.
  • True
  • False, p2 is an integer.
  • False, the order of arguments must match the order of parameters.
  • True
  • True
  • True
  • False, it will output just 5.
  • True

Code Problems

  • Write a function named divide that takes two integers and returns the first divided by the second.
  • Add code to the divide function so the second integer has a default value of 5.
  • Write C++ code that reads an integer from the user, passes it as a pointer to a function named absoluteValue, and updates the original integer with its absolute value.
  • Write a void function with two integer call-by-reference parameters that output the sequence 6, 12, 18, 24.
  • Write a class definition for a Table with members for name, material, length, and width, including mutator and accessor functions.
  • Write a program that defines a function to populate an array with a series of positive and negative integers, then another function to separate these into two arrays (positive and negative) and print their contents.

Debugging

  • Find and correct all five errors in a given C++ program designed to print a reversed c-string.

Fill-In-The-Blanks (Code Completion)

  • Complete a function call to myFunction(int i, char j, string k) with valid arguments.
  • Complete code to output "beep" using a loop that iterates through a string.
  • Complete code that sets a pointer and outputs the value 12 after some pointer manipulation:
    • int *ptr2 = &y;
    • *ptr1 = ptr2;
    • *ptr2 = 12;
    • cout << *ptr1 << endl;
  • Complete the program to input and output name and student ID:
    • getline(cin, myClass[i].name);

Code Evaluation

  • Determine the exact output of various small C++ programs, considering data types and order of operations.
  • Pay close attention to whether the output is an integer or a decimal-based number.
  • Consider operator precedence and data type conversions which determine the final output.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

Description

Review key concepts for Exam 1, covering chapters 1 through 6 (structures and classes) and chapter 10 (pointers). Focus on materials from the textbook, lab exercises, and lecture slides. Key topics include nested control statements, escape sequences, arrays, and operators.

More Like This

C++ Random Exam Generator
4 questions

C++ Random Exam Generator

EnchantingSunflower avatar
EnchantingSunflower
C++ Object Oriented Programming Exam
10 questions
C++ Programming Exam
8 questions

C++ Programming Exam

BrightBlueTourmaline4442 avatar
BrightBlueTourmaline4442
Object Oriented Programming in C++ Exam - MCADD-501
16 questions
Use Quizgecko on...
Browser
Browser