Flashcard Console Application <Help>

I am trying to put together something that will help me learn medical terms. The idea is that the words will be randomly selected and displayed and then I have to guess the definitions.

Here is what I have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <string>
#include <stdio.h>      /* printf, scanf, puts, NULL */
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */

using namespace std;

int main() {
	int word;
	string a;
	
	srand (time(NULL));
	
	string rootList[7] = {"acr/o", "cardi/o", "cyan/o", "cyt/o", "dermat/o", "duoden/o", "electro"};
	word = rand() % 7 + 1;
	
	cout << rootList[word] << endl;
	cin >> a;
	
	
	return 0;
}


My question is how do I get the definitions of each word from rootList assigned to each word?
For example, how could I link definitions from one list to the words in another?

Thanks for any insight.

D
Last edited on
how could I link definitions from one list to the words in another

I wouldn't. I'd make it a list (an array) of word/definition pair structs (at least to start with.)

But you should consider using either a std::map or a std::vector of std::pairs.

And maybe reading your data from file? (tab delimited would be easy to code and work with Excel.)

Andy

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
55
56
57
58
59
60
61
#include <iostream>
#include <string>
//#include <cstdio>    // printf, scanf, puts, NULL
//don't want this
#include <cstdlib>     // srand, rand
#include <ctime>       // time

using namespace std;

#define TESTING

struct WordDef
{
    string word;
    string def;
};

int main() {
    srand (time(NULL));
    
    const WordDef rootList[] = {
    {"acr/o"  , "extreme stuff"},
    {"cardi/o", "heart stuff"},
    {"cyan/o" , "dark blue stuff"},
    {"cyt/o"  , "cell stuff"},
    {"dermat/o", "skin stuff"},
    {"duoden/o", "duodenum stuff"},
    {"electro", "a style of dance music with a fast"
                " beat and synthesized backing track"}};

    const int count = sizeof(rootList)/sizeof(rootList[0]);
    // size of whole list / size of first element

#ifdef TESTING
    // just for testing, display list
    for(int i = 0; i < count; ++i)
    {
        cout << "[" << rootList[i].word << "]\n"
             << rootList[i].def << "\n";
    }
    cout << "\n";
#endif

    for(int i = 0; i < 5; ++i)
    {
        int j = rand() % count; // do not add 1
        // (valid indices are 0 - N-1 for an array of size N)

        cout << rootList[j].word << " means?\n";
        string def;
        getline(cin, def); // use getline() function as cin >> can't deal with spaces!

        if(def == rootList[j].def)
            cout << "correct!\n";
        else
            cout << "wrong!\n";
        cout << "\n";
    }

    return 0;
}


[acr/o]
extreme stuff
[cardi/o]
heart stuff
[cyan/o]
dark blue stuff
[cyt/o]
cell stuff
[dermat/o]
skin stuff
[duoden/o]
duodenum stuff
[electro]
a style of dance music with a fast beat and synthesized backing track

electro means?
a style of dance music with a fast beat and synthesized backing track
correct!

duoden/o means?
duodenum stuff
correct!

dermat/o means?
skin stuff
correct!

cyt/o means?
stomach stuff
wrong!

acr/o means?
extreme stuff
correct!

Last edited on
Thanks!!

I'm still a bit new to programming, so I'll have to look up more about struct (I assume that's Structures), but that is definitely a good start!!

Thanks again!

D
Topic archived. No new replies allowed.