Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PC Magazine Guide To Client Server Databases

Authors: Joe Salemi

1st Edition

156276070X, 978-1562760700

More Books

Students also viewed these Databases questions

Question

Are the rules readily available?

Answered: 1 week ago

Question

Are these written ground rules?

Answered: 1 week ago