Intro to Structures and Classes

Hey, so i am having some issues with this problem i was given. I understand what they want but i dont clearly understand the syntax and format that this must be in... any help is appreciated. I have some code written down but its just stuff i put down there, i am almost confusing myself with what i have so far. Any ideas?

Assignment:
https://wiki.ittc.ku.edu/ittc/EECS168:Homework6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <string>
using namespace std;

struct pokemon
{
	string name;
	int hits, tricks, blocks, wins;
	bool alive;
}

class arena
{
public:
	void add_pokemon (pokemon a, string name, int hits, int tricks, int blocks, int wins);
	void print roster (pokemon a, string name, int hits, int tricks, int blocks, int wins);
	void battle (pokemon a, string name, int hits, int tricks, int blocks, int wins);
private:
	void create pokemon (pokemon a, string &name, int &hits, int &tricks, int &blocks, int &wins);
	void find_pokemon;
	void fight;
};

int main ()
{
	int i = 0;
	pokemon a[100];
	do {
		cout << "Welcome to pokemon battle! Please choose an option.\n";
		cout << "1. Add Pokemon\n";
		cout << "2. Print Roster\n";
		cout << "3. Battle\n";
		cout << "0. Exit\n";
		
		switch (choice)
		{
			case 1:
				create_pokemon();
			case 2:
				print_roster();
			case 3:
				battle();
		}
	}while (choice != 0)
}

void arena::add_pokemon (string &name, int &hits, int &tricks, int &blocks, int &wins)
{
	cout << "What is the name of the new pokemon?\n";
	cin >> name;
	find_pokemon (name);
	while (find_pokemon)
		cout << 
}
Hi There,

Faulty code:
1
2
3
4
5
6
7
8
9
10

switch (choice)
		{
			case 1:
				create_pokemon();
			case 2:
				print_roster();
			case 3:
				battle();
		}



You can't call these functions without first creating an Arena object and using it to call them.

After taking a look at your assignment, it's well explained there. Your Pokemon data structure as you have it is ok. For the Arena class, i suggest, you read the instructions carefully and find out what the private variables are first, and how you can manipulate them from the instructions presented for the functions.


YNWA
Last edited on
I see what you mean about syntax. Labels in C++ cannot contain spaces. So you can't have a method called print roster, you might want to use print_roster instead. The same goes for create pokemon.

Add Pokemon adds a new entry and reports if you're adding a duplicate, so it must keep a record of what's been added.

Print Roster displays the list of what's been added.

Topic archived. No new replies allowed.