Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Introduction to C Programming: Objectives: 1. To learn how to design and implement functions for program development 2. To reinforce how to use pass by

Introduction to C Programming:

Objectives:

1. To learn how to design and implement functions for program development

2. To reinforce how to use pass by value and pass by reference variables

3. To learn how to use structures

Introduction:

Who doesnt love dragons? Movies about dragons and dragon training were very popular this summer. Your friend has not stopped talking about how awesome dragons are and how cool it would be to train them. To amuse your friend, you have decided to create a series of programs about dragons.

Problem:

Now that your dragon is fully trained, he or she can participate in the games at the yearly festivals! One popular game is similar to the human game of Red Rover. Dragons begin in two teams. Two dragons one from each team will compete head to head. The losing dragon must join the winners team. The game ends when an entire team is defeated.

Since your dragon is the newest trained dragon, they must prove themselves by starting as a team of one. They will face off against a team of 5 other dragons. You will need to choose your opponents carefully to maximize your dragons chances of winning the game!

Before each match, present the user with the following menu:

1) View Home Team

2) View Away Team

3) Continue

That way, you can view the stats of your dragons (the home team) and the stats of the enemy dragons (the away team). When you are ready to continue you can choose which dragons from each team that will compete.

The matches should continue until one team contains all six dragons and the other team has zero dragons left to compete.

To make the testing of the program easier, your program will read in all of the dragon data from an input file. The name of this file should be specified by the user.

Input Specification:

The input file will contain six lines of data. The first line of the file will contain the single dragon that begins on the home team. The other five lines of data will contain the five dragons that begin on the away team.

Each line of data is organized the same way:

Where is a string that is guaranteed not to exceed 19 characters and each score is an integer.

Output Specification:

All output should go to the screen.

When the user selects continue, first show them the home team. This listing should show each dragons name and combined score. Dragons should be labeled with an integer specifier starting at zero. Ask the user to select a dragon to send over.

Then, show them the away team. This listing should show each dragons name and combined score. Dragons should be labeled with an integer specifier starting at zero. Ask the user to select a dragon for the home team to target.

Then check the two selected dragons combined scores. Combined scores are obtained by adding the three dragon values together (agility, intelligence, and strength). The dragon with the higher score wins, but the home team wins if the scores are tied.

The losing dragon joins the other time. Print out the results using the following format:

defeats !

will join the team!

Where all values in < brackets > are strings.

Then update both teams. The losing dragon should be added to the last open spot of the winning team. If this causes a gap in the losing team, move the dragon in the last spot of the losing team into the gap.

Finally, check to see if either team has won. A team wins when all six dragons are on the team. Print out the winning team:

The home team has won!

or

The away team has won!

Implementation Restrictions

You must use the following constants:

#define arraylength 6

#define strlength 20

You must use the following structure to store information:

struct dragon {

char name[strlength];

int strength;

int intelligence;

int agility;

};

It is not sufficient to simply have the structure in your program. You must use it to store information and process operations throughout the program.

Though function prototypes will not be provided, it is expected that you follow good programming design and create several functions with well-specified tasks related to the solution of this problem. Make sure to pay very careful attention to parameter passing.

Hints

Create two arrays of structures: one to represent the home team and one to represent the away team. The maximum number of dragons that can be on a team is 6.

Create two integer values to represent the current size of the teams. The home team should start at size 1 and the away team should start at size 5.

Use pass by reference parameters for your functions. In your parameter list, pass the needed arrays of dragons and the size of each array to avoid out of bounds errors. This will help ensure that any changes made to the dragon teams in the functions will be reflected in main.

Use the prewritten string functions when dealing with strings:

~use strcpy whenever you want to copy the contents of one string into another, instead of the equals sign.

Whenever you add a dragon to any team, make sure you add it to the first open slot on the team.

Whenever you remove a dragon from any team, make sure you copy the dragon in the last spot on the team into the vacated spot (unless the dragon leaving the team is already in the last spot). For example, if the dragon to be removed is in index 3 and the number of dragons on the team before removal is 5, then the dragon in index 4 (the last filled index) should be copied into the dragon spot in index 3. Subsequently, the number of dragons on the team should be updated to 4.

Sample Input File (dragon.txt)

TOOTHFUL 85 20 39

SPITFIRE 50 8 34

FURY 14 4 12

NIGHTWING 45 7 15

STARFALL 61 2 20

ICICLE 91 3 17

Sample Output (corresponding to input file)

What is the name of the file?

dragon.txt

Let the game begin! What would you like to do?

1 - Print Home Team

2 - Print Away Team

3 - Continue

1

Home Team:

0 - TOOTHFUL

Score:144

What would you like to do?

1 - Print Home Team

2 - Print Away Team

3 - Continue

2

Away Team:

0 - SPITFIRE Score:92

1 - FURY Score:30

2 - NIGHTWING Score:67

3 - STARFALL Score:83

4 - ICICLE Score:111

What would you like to do?

1 - Print Home Team

2 - Print Away Team

3 - Continue

3

Please select a dragon from the home team to send over:

0 - TOOTHFUL Score:144

0

Please select a dragon from the away team to target:

0 - SPITFIRE Score:92

1 - FURY Score:30

2 - NIGHTWING Score:67

3 - STARFALL Score:83

4 - ICICLE Score:111

1

TOOTHFUL defeats FURY!

FURY will join the home team!

What would you like to do?

1 - Print Home Team

2 - Print Away Team

3 - Continue

1

Home Team:

0 - TOOTHFUL Score:144

1 - FURY Score:30

What would you like to do?

1 - Print Home Team

2 - Print Away Team

3 - Continue

2

Away Team:

0 - SPITFIRE Score:92

1 - ICICLE Score:111

2 - NIGHTWING Score:67

3 - STARFALL Score:83

What would you like to do?

1 - Print Home Team

2 - Print Away Team

3 - Continue

3

Please select a dragon from the home team to send over:

0 - TOOTHFUL Score:144

1 - FURY Score:30

1

Please select a dragon from the away team to target:

0 - SPITFIRE Score:92

1 - ICICLE Score:111

2 - NIGHTWING Score:67

3 - STARFALL Score:83

3

STARFALL defeats FURY!

FURY will join the away team!

What would you like to do?

1 - Print Home Team

2 - Print Away Team

3 - Continue

1

Home Team:

0 - TOOTHFUL Score:144

What would you like to do?

1 - Print Home Team

2 - Print Away Team

3 - Continue

2

Away Team:

0 - SPITFIRE Score:92

1 - ICICLE Score:111

2 - NIGHTWING Score:67

3 - STARFALL Score:83

4 - FURY Score:30

What would you like to do?

1 - Print Home Team

2 - Print Away Team

3 - Continue

3

Please select a dragon from the home team to send over:

0 - TOOTHFUL Score:144

0

Please select a dragon from the away team to target:

0 - SPITFIRE Score:92

1 - ICICLE Score:111

2- NIGHTWING Score:67

3 - STARFALL Score:83

4 - FURY Score:30

1 TOOTHFUL defeats ICICLE!

ICICLE will join the home team!

What would you like to do?

1 - Print Home Team

2 - Print Away Team

3 - Continue

3

Please select a dragon from the home team to send over:

0 - TOOTHFUL Score:144

1 - ICICLE Score:111

1

Please select a dragon from the away team to target:

0 - SPITFIRE Score:92

1 - FURY Score:30

2 - NIGHTWING Score:67

3 - STARFALL Score:83

2

ICICLE defeats NIGHTWING!

NIGHTWING will join the home team!

What would you like to do?

1 - Print Home Team

2 - Print Away Team

3 - Continue

3

Please select a dragon from the home team to send over:

0 - TOOTHFUL Score:144

1 - ICICLE Score:111

2 - NIGHTWING Score:67

1

Please select a dragon from the away team to target:

0 - SPITFIRE Score:92

1 - FURY Score:30

2 - STARFALL Score:83

1

ICICLE defeats FURY!

FURY will join the home team!

What would you like to do?

1 - Print Home Team

2 - Print Away Team

3 - Continue

3

Please select a dragon from the home team to send over:

0 - TOOTHFUL Score:144

1 - ICICLE Score:111

2 - NIGHTWING Score:67

3 - FURY Score:30

0

Please select a dragon from the away team to target:

0 - SPITFIRE Score:92

1 - STARFALL Score:83

0 TOOTHFUL defeats SPITFIRE!

SPITFIRE will join the home team!

What would you like to do?

1 - Print Home Team

2 - Print Away Team

3 - Continue

3

Please select a dragon from the home team to send over:

0 - TOOTHFUL Score:144

1 - ICICLE Score:111

2 - NIGHTWING Score:67

3 - FURY Score:30

4 - SPITFIRE Score:92

0

Please select a dragon from the away team to target:

0 - STARFALL Score:83

0

TOOTHFUL defeats STARFALL!

STARFALL will join the home team!

The home team has won!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Finance The Role Of Data Analytics In Manda Due Diligence

Authors: Ps Publishing

1st Edition

B0CR6SKTQG, 979-8873324675

More Books

Students also viewed these Databases questions

Question

List the steps involved in an open market sale of a new bond issue.

Answered: 1 week ago

Question

What are some of the possible scenes from our future?

Answered: 1 week ago