Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5 MCD McDonald\'s Corporation# 35 99.25 HD The Home Depot, Inc.# 31 115.54 F For

ID: 642940 • Letter: 5

Question

5
MCD McDonald's Corporation# 35 99.25
HD The Home Depot, Inc.# 31 115.54
F Ford Motor Co.# 288 16.49
WMT Wal-Mart Stores Inc.# 10 83.33
BA The Boeing Company# 24 151.46

On your own, create a modular C++ program to lookup the trading symbol in a given stock portfolio. The program will use dynamic parallel arrays to hold the stock information: trading symbol, company name, number of shares and current price. Do not use global variables or constants in your solution. Stock portfolio information will be read from file and can contain any number of stocks. The first line of the file contains an integer identifying the remaining number of stocks to read from the file. Each remaining line in the file contains data for a single stock (data types in parentheses): trading symbol (multiple characters), company name (multiple characters with embedded spaces and end delineated by #), number of shares (integer), and current price (real). A sample stock file is given below: 5 MCD McDonald's Corporation# 35 99.25 HD The Home Depot, Inc.# 31 115.54 F Ford Motor Co.# 288 16.49 WMT Wal-Mart Stores Inc.# 10 83.33 BA The Boeing Company# 24 151.46 a) Create the source code file StockLookUp.cpp. Add a block comment at the top of the file to identify your name, file, date, class, assignment, and short description of the program. b) Include the following design requirements in your code:

Explanation / Answer

// search and that end points just past the last item.
int* search(int *begin,int *end,String x) {
int* ptr = begin;
while(ptr != end) {
if(*ptr == x)
return ptr;
else
ptr++;
}
return end;
}
---------------------------------------------------------------------------------------------------------
// Sort the items between begin and end.
// end should point just past the end of the
// range of values being sorted.
template <typename T>
void sort(T *begin,T *end)
{
// Sort the array using insertion sort
T *mover = begin; // mover points to the element being inserted.
mover++;
while(mover != end) {
T value = *mover; // The value of the item being inserted
// The current pointer will scan through the part of the array
// that appears before the mover location.
T *current = mover;
while(current != begin) {
// previous points to the location before current
T *previous = current;
previous--;
// As long as we keep seeing numbers that are greater than
// the value we are inserting, we will keep moving things
// aside to make room for the value we want to insert.
if(*previous > value) {
*current = *previous;
current--;
} else
break;
}
// Drop the value into place and move on to the next
// item to insert.
*current = value;
mover++;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote