Multiple Choice
Multiple Choice Section 2.1 - 2.2 Introduction to Classes |
class foo { public: void x(foo f); void y(const foo f); void z(foo f) const; ...Which of the three member functions can alter the PRIVATE member variables of the foo object that activates the function?
class quiz { public: quiz( ); int f( ); int g( ) const; private: double score; };Which functions can carry out an assignment score=1.0; to the private member variable score?
Multiple Choice Section 2.4 Classes and Parameters |
void f(int i, int &k) { i = 1; k = 2; }Suppose that a main program has two integer variables x and y, which are given the value 0. Then the main program calls f(x,y); What are the values of x and y after the function f finishes?
int day_of_week(int year, int month = 1, int day = 1); // Possible function calls: cout << day_of_week( ); cout << day_of_week(1995); cout << day_of_week(1995, 10); cout << day_of_week(1995, 10, 4);How many of the function calls are legal?
Multiple Choice Section 2.5 Operator Overloading and Friends |
Multiple Choice Multiple Choice Section 2.1 - 2.2 Introduction to Classes Here is the start of...
1. Write TWO different but equivalent statements to do the same thing: use a for statement to print the elements of array numbers by using pointer ptr. 2. Write an expression that uses ptr to copy element 1 (zero-based) of the array to element 3. Do not use numbers in the array in Here is the start of a class declaration: class foo { public: void x(foo f); void y(const foo f); void z(foo f) const; ... 3. Which of...
Data Structures using C++ Here is the start of a class declaration: class ClassA { public: void func1(const ClassA& a); void func2(const ClassA& a) const; void func3(ClassA a) const; ... Which of the three member functions can alter the private member variables of the ClassA object that activates the function? A. None of the three functions. B. Only func1. C. Only func2. D. Only func3. E. Only two of the three functions.
Multiple Choice Multiple Choice Section 4.1 Pointers and Dynamic Memory Consider the following statements: int *p; int i; int k; i = 42; k = i; p = &i; After these statements, which of the following statements will change the value of i to 75? A. k = 75; B. *k = 75; C. p = 75; D. *p = 75; E. Two or more of the answers will change i to 75. Consider the following statements: int i =...
1.Suppose that the goop function from the previous question changes the value of z[1]. Does this change effect the value of the actual argument? A. Yes B. No 2.Here is a function declaration: void goo(int* x) { *x = 1; } Suppose that a is an int* variable pointing to some integer, and *a is equal to zero. What is printed if you print *a after the function call goo(a)? A. 0 B. 1 C. address of a D. address...
2 Class Vec Message1 2.1 Introduction • Write a class Vec Message1 with the following declaration. class Vec_Message1 { public: Vec_Message1(); Vec_Message1(int n); Vec_Message1(int n, const Message1 &a); Vec_Message1(const Vec_Message1 &orig); Vec_Message1& operator= (const Vec_Message1 &rhs); ~Vec_Message1(); int capacity() const; int size() const; Message1 front() const; Message1 back() const; void clear(); void pop_back(); void push_back(const Message1 &a); Message1& at(int n); private: void allocate(); void release(); int _capacity; int _size; Message1 * _vec; }; 2.2 allocate() and release() • Examine the...
I need help implementing class string functions, any help would be appreciated, also any comments throughout would also be extremely helpful. Time.cpp file - #include "Time.h" #include <new> #include <string> #include <iostream> // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for the hours, // an integer variable for the minutes, and a char variable for...
c++ Error after oveloading, please help? LAB #8- CLASSES REVISITED && Lab #8.5 … Jayasinghe De Silva Design and Implement a Program that will allow all aspects of the Class BookType to work properly as defined below: class bookType { public: void setBookTitle(string s); //sets the bookTitle to s void setBookISBN(string ISBN); //sets the private member bookISBN to the parameter void setBookPrice(double cost); //sets the private member bookPrice to cost void setCopiesInStock(int noOfCopies); //sets the private member copiesInStock to...
Please answer all the questions thank you 1) (Classes – 20 Points) Consider the following class declaration for Time to complete the questions below: DO NOT WRITE MORE THAN ASKED FOR. class Time private: int hours; int minutes; public: Time(); Time (int , int m = 0); void addMin(int m); void addHr(int h); void reset(int h = 0, int m = 0); Time operator+(const Time & t) const; Time operator-(const Time & t) const; Time operator*(double n) const; friend Time...
Redefining Base Functions (C++) Create two simple C++ classes (Use separate files please and include appropriate headers) Define a base class named "Venue" that holds the following member variables and functions: Type of venue (string), e.g. public venue, private venue, community venue Year opened (int) Capacity (int) Base price (float), holds the average ticket price for the venue Potential revenue (float), a function returning capacity * base price Next, define a class named "Theater" that is derived from the "Venue"...
Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part 1: In this assignment, you are asked: Stage1:?Design and implement a class named memberType with the following requirements: An object of memberType holds the following information: • Person’s first name (string)?• Person’s last name (string)?• Member identification number (int) • Number of books purchased (int)?• Amount of money spent (double)?The class memberType has member functions that perform operations on objects of memberType. For the...