Question: Magic the Gathering Collection : For this assignment, write a C++ program on the Linux system that keeps track of your most valuable Magic Cards.

Magic the Gathering Collection : For this assignment, write a C++ program on the Linux system that keeps track of your most valuable Magic Cards. Instead of saving cards to a file,you will load your card collection into memory, so they can be listed and searched. When the program starts, your program will ask the user to enter the name of an input file, which your program will open and use to load the card collection into memory using an array of structs. The struct definition is listed below struct cardInfo { char name[STR_SIZE]; double price; char set[STR_SIZE]; char type[STR_SIZE]; int count; The input text file will use the same comma separated value format. After the file is loaded, the program will enter a user-controlled loop. Inside of the loop, the program will ask the user what they want to do. In addition to searching and listing, the user will have the option to add another card to the collection, but only in memory; you do not need to add the new card information to the text file for this project. So, the options that the user can (Search for a card by name.List all of the cards.Add a new card to the memory database.Quit)There are 4 functions that you will be required to write for this project in addition to main: loadCards(), addACard(), searchCards(), and listCards(). Call loadCards() when the program starts. Call the other functions in the user-controlled loop. See below for example output and function prototypes.

*****Example Output (User Input in Bold)****** Welcome to the magic card collection program. What is the name of the card file? notAFile.txt notAFile.txt was not found. Try again or type 'quit' to exit the program. What is the name of the card file? cardCollection.txt Successfully loaded 7 cards.

Name Price Set Type Count ------------------------------------------------------------------------------------------------------------------------------------------ All In Good Time 13.22 Archenemy Scheme 1 Enlightened Tutor 14.25 Eternal Masters Instant 3 Helm of Obedience 17.39 Alliances Artifact 4 Liliana the Last Hope 25.55 Eldritch Moon Planeswalker 2 Chaos Orb 7300.00 Beta Artifact 1 Ugin the Spirit Dragon 32.80 Fate Reforged Planeswalker 2 Temporal Trespass 1.77 Fate Reforged Sorcery 4 Zodiac Dragon 239.99 Portal Three Kingdoms Creature 1

What would you like to do? (S)earch for a card, (A)dd a card, (L)ist all cards, or (Q)uit? A What is the name of the card? Living Lands What is the price of the card? 117.00 What set is the card in? Alpha What type is the card? Enchantment How many of this card do you have? One You must enter a positive number. Please try again: -3 You must enter a positive number. Please try again: 1 Successfully added Living Lands to the database.

What would you like to do? (S)earch for a card, (A)dd a card, (L)ist all cards, or (Q)uit? S What is the name of the card? Lady Sun The card Lady Sun was not found in the database.

What would you like to do? (S)earch for a card, (A)dd a card, (L)ist all cards, or (Q)uit? S What is the name of the card? Chaos Orb Information on the card Chaos Orb is as follows: Price: $7300.00, Set: Beta, Type: Artifact, Count: 1

What would you like to do? (S)earch for a card, (A)dd a card, (L)ist all cards, or (Q)uit? L

Name Price Set Type Count ---------------------------------------------------------------------------------------------------------------------- All In Good Time 13.22 Archenemy Scheme 1 Enlightened Tutor 14.25 Eternal Masters Instant 3 Helm of Obedience 17.39 Alliances Artifact 4 Liliana the Last Hope 25.55 Eldritch Moon Planeswalker 2 Chaos Orb 7300.00 Beta Artifact 1 Ugin the Spirit Dragon 32.80 Fate Reforged Planeswalker 2 Temporal Trespass 1.77 Fate Reforged Sorcery 4 Zodiac Dragon 239.99 Portal Three Kingdoms Creature 1 Living Lands 117.00 Alpha Enchantment 1

What would you like to do? (S)earch for a card, (A)dd a card, (L)ist all cards, or (Q)uit? Q Terminating Program.

*****Programming Requirements****** Dont use the string library or any of the STL containers such as vectors. Use the library and c-strings (char arrays) to store strings. You may use a reasonable length for your c-strings, such as 128 or 256, declared as a global constant (remember not to use literals in your code for things like array size): const int STR_SIZE = 256; const int arraySize = 256; Create your array of structs in the main function. Do not use any global variables (constant globals are OK). Make sure you check for index out of bounds before adding new data to the array. When loading data, compare the index to the arraySize constant. If they are equal, there is no more room, so stop loading data. Suppose you use a variable called index to know where to place new data in the array of structs. Index will start out at zero (the first location in the array), and then add 1 to move to the next index: index++; You can check if the array is out of room with an if statement: if(index >= arraySize) // dont load the new data. There are two functions where you need to do this check: loadCards() and addACard(). See below for more details. You must create at least four functions in addition to the main function. One of the functions must be to load the data from the file (loadCards()), the second must be to search the array for the name of the card (searchCards()), the third will be to add a new card (addCard()), and the last function will be to list all of the cards (listCards()). You may create more than those four functions, but you must implement at least those four. Check to make sure that the input file is open before reading from it, using ifstream.is_open(). Ask the user to try a different file name if the file does not open or have them type quit to quit the program at that point (if they dont have a collection file). Make sure that you check for negative numbers and bad data when reading number data from the user. You may assume that the input file is formatted correctly, so no error checking is necessary when reading from the file. There are two different ways to check for non-number input. The first method is to check for input failure, and the other is to use atoi(), found in the library. Suppose you have a variable called cardCount set up to take input from cin. After storing the input, use a while statement to check for input failure and negative values: cout << "How many of this card do you have? "; cin >> cardCount; while(cin.fail() || cardCount <= 0) { cin.clear(); // clear the fail state. cin.ignore(LARGE_NUMBER, ); // remove chars from the input buffer. cout << "Please enter a positive number: "; . }

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!