Question: Assume there is a stock class which has symbol (string), cost (int) and shares (int) as public members. 1.Write the minimum declaration that supports both

Assume there is a stock class which has symbol (string), cost (int) and shares (int) as public members.

1.Write the minimum declaration that supports both statements

stock s2(APPL, 209, 77), s3(FB, 100, 1); // 77 shares of APPL at $209, 1 share of FB at $100

stock s4(s3);

Write member operator overload function declaration that supports int value=s2+s3; // value is the sum of (cost*shares)

2.Given the stock class has the following declaration:

friend ostream& operator>> (istream&, stock&);

Answer each of the following questions in less than 10 words.

A.Can this function be implemented as a member function? If yes, how? If no, why?

B.Can this function be implemented without the friend declaration? If yes, how? If no, why?

4.If we create a stockDB class which stores variable number of stocks in a dynamic stock array. Complete the minimum stockDB.h class definition such that

stockDB frank(5), obama(700); // frank can have at most 5 stocks, obama 700 max

class stockDB {

5 Write the implementation code (cpp) that supports frank = obama;

6.Further assume that stock has operator< overloaded and there is a global swap(stock&, stock&) function. Complete the following implementation code for stockDB selection sort.

void stockDB::selectionSort() {

7.Add additional code below to cause a dangling pointer issue.

int * a = new int(5);

int * b = a;

8.Given the declaration int * d = new int[5]; Check ALL statements that prints out the address of the 2nd elements in d array

cout << d + 1;

cout << d + 4;

cout << &d[1];

cout << &d+4;

cout << d++; // this is a bit tricky

9.Is the following code correct? If yes, whats the output? If no, whats wrong?

int *p; //Line 1

int *q; //Line 2

p = new int; //Line 3

*p = 43; //Line 4

q = p; //Line 5

*q = 52; //Line 6

delete q; //Line 7

cout << *p << " " << *q << endl; //Line 8

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!