1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Stells [14]
2 years ago
10

You will write a program that reads a binary file that contains records of creatures. Each record can be stored in a Creature st

ruct. You should present the user with a menu of three options: display a specific creature, display all the creatures sorted by name, or quit. If the user chooses to display a specific creature, you should ask the user which creature to display
Computers and Technology
1 answer:
yuradex [85]2 years ago
5 0

Answer:

Explanation:

main.cpp file

/******************************

Name

Date

PA1_Starter.cpp

Description

********************************/

// Headers

#include <iostream>

#include <cstdlib>

#include <string>

#include <vector>

#include <fstream>

#include <algorithm>

using namespace std;

// Global variables

const int CREATURE_NAME_SIZE = 30; // Max length of a creature name

const int CREATURE_TYPE_SIZE = 26; // Max length of a creature type

const string FILENAME = "creatures.dat"; // Name of file that contains the data

// struct used to create records in file

struct Creature

{

char name[CREATURE_NAME_SIZE]; // Name of the creature

char creatureType[CREATURE_TYPE_SIZE]; // Type of creature

int hp; // Hit points for creature

int armor; // Armor class for creature

int speed; // Speed of creature

};

// This function returns true if the name of the left creature is less than the name of the right creature

// Use this function when running the sort function

bool sortByName(const Creature &lhs, const Creature &rhs)

{

string name1(lhs.name), name2(rhs.name);

return name1 < name2;

}

// Function declarations

// You will need to code the definitions for each of these functions

int getCreatureNumber(int numCreatures);

void displayCreature(fstream& file, int num);

void displaySorted(fstream& file);

int main()

{

char choice; // choice made by user for menu

fstream creatureFile; // file stream for input file

int numCreatures; // the number of creatures saved to the file

 

// Open the creatureFile for input and binary (one statement of code)

 

// Get the number of creatures in the file (two statements of code)

// The number of creatures should be assigned to numCreatures

do

{

cout << "Menu" << endl;

cout << "1. Display a specific creature\n";

cout << "2. Display all creatures sorted by name\n";

cout << "3. Quit\n";

cout << "Enter your choice (1, 2, 3): ";

cin >> choice;

while (cin.get() != '\n');

switch (choice)

{

case '1': // Display a specific creature

displayCreature(creatureFile, getCreatureNumber(numCreatures));

break;

case '2': // Display all the creatures in order

displaySorted(creatureFile);

break;

case '3': // Quit

break;

default:

cout << "Invalid option.\n";

break;

}

if (choice != '3')

{

system("PAUSE");

system("CLS");

}

} while (choice != '3');

creatureFile.close();

 

 

// Make sure we place the end message on a new line

cout << endl;

// The following is system dependent. It will only work on Windows

system("PAUSE");

/*

// A non-system dependent method is below

cout << "Press any key to continue";

cin.get();

*/

return 0;

}

/*******************************************************************

getCreatureNumber gets and returns the record number from the file that the user would like to be displayed

PARAM: numCreatures should be the value of the total number of records (creatures) in the file

PRE: numCreatures contains a value that is equal to the number of records in the file

POST: A value between 1 and numCreatures is returned as selected by the user

NOTE: Do not allow a value less than 1 or greater than numCreatures to be returned

********************************************************************/

int getCreatureNumber(int numCreatures)

{

 

}

/*******************************************************************

displayCreature displays record number num from file

PARAM: file is a fstream that should be open for input and binary

num contains the record number that is to be read in file

PRE: file is a fstream that is open for input and binary

num is a value between 1 and the number of records in file

POST: The record number num is displayed to the monitor

********************************************************************/

void displayCreature(fstream& file, int num)

{

 

}

/*******************************************************************

displaySorted should read file into a vector. It should then sort the vector by

the name of the creature. Last it should display the vector

PARAM: file is a fstream that should be open for input and binary

PRE: file is open for input and binary

POST: Each record is displayed sorted by the name of the creature

********************************************************************/

void displaySorted(fstream& file)

{

 

}

You might be interested in
Francis has designed a picture book appropriate for third graders. He wants teachers across the world to freely download use, an
mestny [16]

Answer:

The correct answer will be "Project Gutenberg".

Explanation:

  • Project Gutenberg continues to obtain lots of requests for authorization for using printed books, pictures, as well as derivatives from eBooks. Perhaps some applications should not be produced, because authorization would be included in the objects provided (as well as for professional usages).
  • You can copy, hand it over, or m actually-use it underneath the provisions including its license that was included in the ebook.

So that the above is the right answer.

8 0
2 years ago
can I do all my work in a notebook with Penn foster or do I have to type all of the answers in that little box?
dusya [7]
Um whichever is better for you! ummm whats the point of this question?
5 0
3 years ago
Read 2 more answers
Which of the following does not accurately describe asynchronous communication?
worty [1.4K]

Answer:

A. While new media is dependent on whether users function in real-time or delayed mode, feedback is not as timely when communication is asynchronous.

Explanation:

Asynchronous communication can be defined as a data communication technique in which exchange of data between a sender and a recipient isn't in real time.

There's usually a time lag, meaning it doesn't require the recipient to respond immediately.

For example, responding to an email or text several hours later.

6 0
3 years ago
Read 2 more answers
All margins of a report are _____ inch. *<br><br> 1<br> 2<br> 3<br> 4
MA_775_DIABLO [31]

Answer:

The answer is "1 inch"

Explanation:

The margin is also known as space, it is the distance between the document 's text and edge. In default, its distance is 1, and it also allows you to customize, the new document, which is set to standard.

  • In other words, we can say that it implies the one-inch gap between the text and each edge, which is based on your specifications.
  • It also allows you to customize the margin size of the document, and other choices were wrong because it is the customize size.

6 0
3 years ago
Hiding an object, such as a diary, to prevent others from finding it is an example of:______________.
madreJ [45]

Answer:

Privacy

Explanation:

I'm not sure but it matches the description you gave.

4 0
2 years ago
Other questions:
  • Which of these is outside the scope of an art director's responsibility?
    12·2 answers
  • . Dеclarе a onе-dimеnsional array of 30 doublеs (on thе stack) namеd rainfall
    11·1 answer
  • What is the radix transformation method?
    5·1 answer
  • Which of the following code displays the area of a circle if the radius is positive. a. if (radius != 0) System.out.println(radi
    11·1 answer
  • Emerson needs to tell his browser how to display a web page. Which tool will he use?
    8·2 answers
  • Show the stack with all activation record instances, including static and dynamic chains, when execution reaches position 1 in t
    6·1 answer
  • If you wanted to buy a house that cost $150,000 and you knew you needed a down payment of five percent, how much would you need
    8·1 answer
  • To view the Picture tools tab, a user must first _____.
    10·2 answers
  • It's a holiday poop in my bitt
    10·2 answers
  • You have received an update package for a critical application you are running on a virtual machine. You have been told to insta
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!