1. Engineering
  2. Computer Science
  3. c programming write a program which expects the name of...

Question: c programming write a program which expects the name of...

Question details

C Programming:

Write a program which expects the name of an input file and an output file to be given by the user. If the user does not input any names, default file names should be used, such asin.txt, and out.txt. The input files have lines which look like this:

MSFT 150

The string represents a stock symbol. The number represents the number of shares bought for that stock.

Any stock/shares can be represented any number of times in the input file. Your program will create an output file which contains each stock name once followed by the number of shares. Here is an example. If the input file contains the following data:

MSFT 150

AAL 280

MSFT 100

AAL 30

MSFT 200

the output file will contain each stock symbol once followed by the total number of shares for that stock:

AAL 310

MSFT 450

Read data from the first input file into a dynamically allocated array of STOCK structures. You may assume that the maximum size of a name string is 25. The program should use either the insertion sort algorithm or the selection sort algorithm to sort the array in ascending order by stock name. To demonstrate that the sorting algorithm works, display the sorted array to the screen. Create your own input file using the data shown on the next page. On the first line in the input file provide the number of stock/shares lines. Make sure that your program does not produce memory leaks. Run the program once and save the output at the end of the source file as a comment.

To check if memory was released properly, use CrtDumpMemoryLeaks as described below:

// . . .

  printf( _CrtDumpMemoryLeaks() ? "Memory Leak\n": "No
Memory Leak\n");
    return 0;
} // end of main()

_CrtDumpMemoryLeaks is a debug function: . returns TRUE if a memory leak is found; . otherwise, the function returns FALSE.

Required Header: #include

Input file:

in.txt

44
MSFT 150
AAL 199
CHTR 280
YHOO 89
XLNX 27
EBAY 899
MSFT 130
BBBY 80
TSLA 45
SIRI 25
CHTR 143
NLFX 133
AAPL 445
SIRI 15
YHOO 78
NLFX 89
XLNX18
AAPL 2345
TSLA 234
SIRI 34
YHOO 45
SIRI 523
NLFX 1234
TSLA 50
GOOG 123
YHOO 99
BBBY 211
TSLA 67
XLNX 122
NLFX 18
TSLA 452
XLNX 83
TSLA 125
YHOO 147
MSFT 100
XLNX 10
AAL 170
TSLA 67
GOOGL 123
XLNX 90
SIRI 1311
TSLA 343
AAPL 89
BBBY 180

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution