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]
3 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]3 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
A certain list, L, contains a total of n numbers, not necessarily distinct, that are arranged in increasing order. If L1 is the
Free_Kalibri [48]

In this question, we are given ,

  • A certain list, L, contains a total of n numbers, not necessarily distinct, that are arranged in increasing order.
  • L1 is the list consisting of the first n1 numbers in L.
  • L2 is the list consisting of the last n2 numbers in L.

Explanation:

As per the information given in statement 1, 17 is a mode for L1 and 17 is a mode for L2.

Therefore, we can infer that ,

  • 17 must occur in L1, either same or a greater number of times as any other number in L1.
  • 17 must occur in L1, either same or a greater number of times as any other number in L2.

As all elements in L are in ascending order, we can also conclude that

  • Each number between last occurrence of 17 in L1 and the first occurrence of 17 in L2 must be equal to 17 only.
  • Therefore, 17 occurs either same or greater number of times as any other number in L.
  • Thus, 17 is a mode for L.

However, from this statement, we cannot conclude anything about the mode of L1, L2, or L.

Hence, statement 2 is not sufficient to answer the question.

Therefore, 17 is a mode for L1 and 17 is a mode for L2.

3 0
3 years ago
Angle parking spaces are generally entered at an angle about __________ from the curb.
Artyom0805 [142]
Probably B. 45 degrees
8 0
3 years ago
Read 2 more answers
You can add chart and axes titles on the chart tools format tab or with the chart elements buttom. true or false
Zepler [3.9K]
True. You can add chart and axes titles on the chart tools format tab or with the chart elements button.
4 0
3 years ago
Which commands (constructs) do NOT have a loop when expressed in syntax graphs? Select all that apply Group of answer choices if
fiasKO [112]

Answer:

if-then-else

switch (expr) { case value: statements ;}

Explanation:

Required

Which do not represent loop

Literally, looping means repeating an action or sequence of actions as long as a given condition is true.

For options (a) to (d), we have:

(a): if-then-else:

if statements are used to test conditions; depending on the truth or falsity of the condition, only one block of code can be executed at once.

<em>In summary, if statements are not loops</em>

(b): switch statements

This is an alternate to if statements and can be used in place of if statements.

<em>Hence, switch statements are not loops</em>

(c) and (d): for and while:

The above represent loops, because they both involve repetition of operations until the condition is no longer satisfied.

5 0
2 years ago
How can you tell whether the printer has been shared?
mixas84 [53]
<span>To check whether a printer is shared or not go to devices on the computer and note whether the printer is listed for that particular computer. Do this for each computer in question. 
hope this helps</span>
4 0
3 years ago
Other questions:
  • Name size of machine screw that is used to secure switches and receptacles to device boxes
    13·1 answer
  • (If the link is not working, search for "Veritasium Levitating Barbecue". At approximately the 2 minute mark, the screen shows 8
    9·1 answer
  • Which of the Arts, A/V Technology, and Communication career cluster pathways are involved with producing a product for an audien
    8·2 answers
  • A(n ____ with a drop down menu provides consistency in function and appearance making it easy for users to learn and work with t
    7·1 answer
  • Ancestor(X,father(X)) and ancestor(david,george) is they unify or not
    11·1 answer
  • A telecom company wants to extend their horizontal cables over a distance of 510 meters. Which cable should they use?
    6·1 answer
  • Which of the following are correct? I. Hold the middle mouse button to rotate the model on the screen. II. To pan the model, hol
    15·1 answer
  • Write a program that estimates how many years, months, weeks, days, and hours have gone by since Jan 1 1970 by calculations with
    15·1 answer
  • Xxx<br>uuuuuu<br>uuuu<br>jjnmn<br>jjh
    12·1 answer
  • Select the items that can be measured.
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!