is asked to select an option. Reporting, buying, or selling? (0=quit, 1=report, 2=buy, 3=sell): Use doubly linked list of stock_t structures. stock_t structure looks like this: #define MAX_TICKER_LENGTH 6 typedef struct stock_t {   char ticker[MAX_TICKER_LENGTH];   date_t date; // date purchased   int numShares;   double sharePrice; } stock_t; date_t structure looks like this: typedef struct date_t {   int month; Int day; int year; } date_t; Create the following files in a directory: date.h: contains the date_t structure • stock.h and stock.c: contain the stock structure and any constants and stock functions like a print stock function. • node.h,

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
How do I write the Selling function? This is a C question. The program first displays a main menu where the user is asked to select an option. Reporting, buying, or selling? (0=quit, 1=report, 2=buy, 3=sell): Use doubly linked list of stock_t structures. stock_t structure looks like this: #define MAX_TICKER_LENGTH 6 typedef struct stock_t {   char ticker[MAX_TICKER_LENGTH];   date_t date; // date purchased   int numShares;   double sharePrice; } stock_t; date_t structure looks like this: typedef struct date_t {   int month; Int day; int year; } date_t; Create the following files in a directory: date.h: contains the date_t structure • stock.h and stock.c: contain the stock structure and any constants and stock functions like a print stock function. • node.h, node.c: contain at least the node typdef and initial node function • list.h and list.c: contain the doubly linked list structure and any constants and list function. All functions that operate on the list as a whole should go here. • main.c contains the main function and, other functions such as reporting, buying, and selling functions. • Makefile: a makefile Reporting: Prints all stocks owned to standard output. After printing stocks owned, ask the user which stock to report on and print all of the details of that stock. Stocks owned are stored in binary files with the stock ticker symbol as the name in all capital letters. For example, Microsoft stocks would be in a file called MSFT.bin and Google stocks in a file called GOOG.bin. To report, the program should use the following types and functions from direct.h (“directory entry” header file). A single directory entry has information in it such as file name. o DIR* dirPtr: a pointer to a DIR, a directory. Used by the opendir function to open a directory for reading. This is analogous to a FILE* (file pointer) used for reading/writing from/to files that are not directories. o struct dirent* dirEntry: a pointer to a directory entry structure. The readdir function returns one of these, a directory entry, which can be used to get the name of the file that the entry pertains to, dirEntry->d_name o DIR* opendir( char* ): takes the path of a directory such as “.” for the current directory and opens it. It returns a DIR* or NULL if the open was unsuccessful (i.e., the directory doesn’t exist). The opendir function is analogous to the fopen function used for opening files. dirPtr  =opendir( “.” ); o struct dirent* readdir( DIR* ): takes a DIR* (a directory) and returns a structure representing the next entry in the directory. The function returns NULL if there are no more entries in the directory. while( (dirEntry = readdir( dirPtr )) != NULL ) { // use dirEntry->d_name and see if it’s a *.bin” // file. If it is, make a string out of the name // only (without the “.bin”), and print it } o int closedir( DIR* ): closes a directory pointer just like you would close a file after reading from it. closedir( dirPtr ); Buying: Prompts the user for the ticker symbol, the number of shares to buy, and the price per share. It opens a binary file for that ticker symbol in append mode: FILE* output; output = fopen( filename, "a" ); gets the date from the system, fills up a stock_t structure with this information, and writes the structure to the binary file. Closes the binary file. Selling: Prompts the user for the ticker symbol of the stock. Opens that stock’s binary file for reading. If the file doesn’t exist, print a message indicating that the user doesn’t own any of that stock. Or else, the program reads all of the stocks from the file and puts them in a queue then closes the file. The program prints out how many shares of that stock the user has and asks the user for the number of stocks to sell and the current stock price. If the user doesn’t own that many shares total, output an error message and reprint the main menu above (report, buy, sell, or quit). Or else, go through the queue of stocks removing the number of shares needed and calculating and printing the total price to buy the stocks, the total selling price, and the gains (or losses). Open the file again in write mode and writes the entire file from the updated contents of the list. Close the file. If the user sells all shares of stock in a file, then the program has to delete the file with the delete function in stdio.h which takes a filename (char *) as a parameter. delete( filename );
Reporting, buying or selling?
(0=quit, 1=report, 2=buy, 3=sell): 3
Enter stock ticker symbol: AAPL
You own 15 AAPL shares.
Enter number of shares: 15
Enter stock price: 100
Shares sold: $1500
Shares bought: $2041.85
Loss: ($541.85)
Reporting, buying or selling?
(0=quit, 1=report, 2=buy, 3=sell): 1
Stocks Owned
5
56
10
DISCA
GOOG
INTC
Enter stock ticker symbol: AAPL
You do not own any AAPL stock.
Transcribed Image Text:Reporting, buying or selling? (0=quit, 1=report, 2=buy, 3=sell): 3 Enter stock ticker symbol: AAPL You own 15 AAPL shares. Enter number of shares: 15 Enter stock price: 100 Shares sold: $1500 Shares bought: $2041.85 Loss: ($541.85) Reporting, buying or selling? (0=quit, 1=report, 2=buy, 3=sell): 1 Stocks Owned 5 56 10 DISCA GOOG INTC Enter stock ticker symbol: AAPL You do not own any AAPL stock.
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Operations of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education