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
Which tcp/ip troubleshooting command should you use to determine whether a client and server are communicating with each other?
sesenic [268]
The answer is <span>The ping command.   The </span><span>tcp/ip troubleshooting command you should  use to determine whether a client and server are communicating with each other is The ping command.  </span><span>The </span>ping command<span> is used to verify that a device can communicate with another on a network.</span>
5 0
3 years ago
Identify the following keys. write AK for Alphanumeric keypad,NK for Numeric Keypad,CK for Cursor Key, FK for Function keys and
natali 33 [55]

Answer:need points for stuff

Explanation:

4 0
2 years ago
Finish the code to search for a 7 in the array.
guapka [62]

Answer:

The complete code is as follows:

from array import *

myArr = array('f',[3, 5, 7,3, 10])

location = myArr.index(7)

print(str("7")+" is at position "+str(location+1))

Explanation:

I made corrections to the third line of the code and I added a line

This line gets the index of 7 from the array myArr using the index keyword

location = myArr.index(7)

This line prints the position of the 7 in the array

print(str("7")+" is at position "+str(location+1))

8 0
2 years ago
HELP
Aleks [24]

Answer:

If a good friend comes to me for advice in pursuing a music career. With my knowledge of digital technology and the performing

arts, my advice to use digital technology to help build her career by <u>Delivering service to clients .</u>

Explanation:

<u>There were several reasons for this: </u>

• Being able to access work platforms and resources removed the need to travel back

to office bases because remote access allowed the completion of administrative

tasks where the practitioner was working.

• Working with clients in rural and isolated areas can prove difficult in terms of meeting

clients face to face and digital solutions helped to resolve this. This is because more

clients can be seen remotely than when practitioners must travel to see them.  

8 0
3 years ago
Calculate the number of Characters and the size of words “Caleb University Imota, Lagos”using Taro Yamen​
Fantom [35]

The code to calculate the number of characters and the size of words is as follows:

x = input("Enter your text here: ")

char=0

word=1

for i in x:

   char = char+1

   if(i==' '):

       word=word+1

print("Number of words in the given string ",word)

print("Number of characters in the given string ",char)

   

<h3>Code explanation:</h3>

The code is written in python

  • The first line of code, we store the users input in a variable called x.
  • Then we initialise the variable char to zero.
  • The variable word is also initialise to zero
  • The we loop through the user's input and count the character
  • We also look for space to know the word, then count the words .
  • Finally, we print the number of word and the number of character.

learn more on python code here: brainly.com/question/20379340

6 0
2 years ago
Other questions:
  • How many 32 bit integers can be stored in 16 byte cache block in matlab?
    15·1 answer
  • ____ are model building techniques where computers examine many potential solutions to a problem, iteratively modifying various
    5·1 answer
  • Create a structure named planet This structure will contain distance from Earth as an integer Atmosphere, language, people and p
    8·1 answer
  • Malcolm is part of a team developing a new smartphone app to track traffic patterns. Because team members are located throughout
    12·1 answer
  • If a table is designed so that every determinant is a candidate key, then that relation is in ________.
    14·1 answer
  • Which industry has the highest employment figure for both teen and young adults in July, 2014?
    6·1 answer
  • A highly agitated client paces the unit and states, "I could buy and sell this place." The client’s mood fluctuates from fits of
    15·1 answer
  • Digital printing is not suitable for printing what
    11·1 answer
  • You can use a(n) to call a function in response to an event?
    14·1 answer
  • How do we prevent electrical problems as prescribe by the course?​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!