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
Which layer in the Transmission Control Protocol/Internet Protocol (TCP/IP) model is responsible for delivering data between two
s2008m [1.1K]

Answer:

Network.

Explanation:

The Transmission Control Protocol/Internet Protocol (TCP/IP) model is a standard networking protocol which allows network devices such as routers, switches, and host computers to interconnect and communicate with one another over a network. The Transmission Control Protocol/Internet Protocol (TCP/IP) model comprises of four (4) layers and these includes;

I. Application layer.

II. Transport layer.

III. Internet layer.

IV. Network layer.

The network layer in the Transmission Control Protocol/Internet Protocol (TCP/IP) model is responsible for delivering data between two nodes.

Basically, this layer known as network layer is the fourth layer of the Transmission Control Protocol/Internet Protocol (TCP/IP) model and it is typically responsible for the transmission of packets from one network device to another.

4 0
3 years ago
Snap Me on <br>samxavier.18​
Ahat [919]

Answer:no thank you ima goody

Explanation:

7 0
2 years ago
Read 2 more answers
What is the difference between hardware and software?
alina1380 [7]
A Hardware is any physical device used in. You can touch hardware, but you cannot touch software. Hardware is physical, and software is virtual. (brainliest) ??
4 0
3 years ago
Some people use the term _____ to refer to the case that contains and protects the motherboard, internal hard drive, memory, and
Volgvan

Answer:

System unit.

Explanation:

Some people use the term system unit to refer to the case that contains and protects the motherboard, internal hard drive, memory, and other electronic components of the computer from damage.

A system unit also referred to as chassis or tower can be defined as a hardware case that is typically used as a protective case for the main component or primary devices such as power supply, random access memory (RAM), graphics card, CD-ROM drive, Harddisk drive, motherboard, internal cables, central processing unit (CPU) that makes up a computer system.

Basically, the main purpose of a system unit is to properly house the main components of a computer, serve as an electrical insulator and to prevent them from any form of damage.

7 0
2 years ago
40 points to answer ALL
Kamila [148]

Answer:

#1 Use case diagram is one of them and its specific purpose is to gather system requirements and actors. Use case diagrams specify the events of a system and their flows.

#2 Software architecture refers to the high level structures of a software system and the discipline of creating such structures and systems. Each structure comprises software elements, relations among them, and properties of both elements and relations.

#3 Definition. A programming paradigm is a style, or “way,” of programming. Some languages make it easy to write in some paradigms but not others. Never use the phrase “programming language paradigm.” A paradigm is a way of doing something (like programming), not a concrete thing (like a language).

#4 Object-oriented programming (OOP) refers to a type of computer programming (software design) in which programmers define not only the data type of a data structure, but also the types of operations (functions) that can be applied to the data structure.

#5 Each flow chart is concerned with one particular process or system. ... Flow charts are an important tool for the improvement of processes. By providing a graphical representation, they help project teams to identify the different elements of a process and understand the interrelationships among the various steps.

#1 Programming style, also known as code style, is a set of rules or guidelines used when writing the source code for a computer program. It is often claimed that following a particular programming style will help programmers read and understand source code conforming to the style, and help to avoid introducing errors.

#2 Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. For the examples in this book, you will use software source code as the files being version controlled, though in reality you can do this with nearly any type of file on a computer.

#3 a manual detailing the house style of a particular publisher, publication, etc.

#4 Agile software development is a process that turns a vision for a business need into solutions. We use agile because it results in software that better supports our customer needs on a faster timeline.” The Agile movement is based on the overarching goal of building software more simply.

Explanation:

20 points not 40 i need the rest

5 0
2 years ago
Read 2 more answers
Other questions:
  • ____ languages create source code using words and structures similar to spoken language.​
    15·1 answer
  • What happens when you press the Enter key at the end of a line of bulleted text?
    14·2 answers
  • Help!!!!!!!!!!!!!!!!!
    11·1 answer
  • What is the difference between a rack and a tower?
    8·1 answer
  • 1)Which of the following statements about the print statement are TRUE? (Check all that apply)
    8·1 answer
  • What is the smartest person ever
    15·2 answers
  • WHAT IS ONE WAY A PIVOTTABLE COULD COMBINE THE FOLLOWING DATA
    10·1 answer
  • Examples of email use that could be considered unethical include _____.
    14·2 answers
  • Jamal wants to create a program that will play music during the afternoon. Which kind of loop should be used in the program?
    6·2 answers
  • Design an Application called Student Course Management create interface called Student Course add an abstract method called ad C
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!