Question
in c++

Description A dictionary is a collection of words that contain at least one definition. One way to represent a dictionary is

Things to consider: 1. How will you make sure one array is just as long than the other? 2. How would you pass each array to t
sample output


How many terms do you want the dictionary to hold? 5 Enter Term 1: Lion Enter the definition for Lion: A ferocious animal t
0 0
Add a comment Improve this question Transcribed image text
Answer #1


Comment down for any queries

Please give a thumb up

Code:

#include <bits/stdc++.h>
using namespace std;

void readEntries(string *words, string *meanings, int directorySize) {
for(int i = 0; i < directorySize; i++) {
// 2.a Ask for the word
cout << "Enter Term "<<i+1<<": ";
// 2.c Store the word in array
getline(cin,words[i]);
// 2.b Ask for the definition
cout << "Enter the definition for " << words[i]<<": ";
// 2.d Store the definition in array
getline(cin,meanings[i]);
}
}

void writeEntries(string *words, string *meanings, int directorySize) {
// 3. Output entries which were stored
cout << endl << "You entered: " << endl;
for(int i = 0; i < directorySize; i++) {
cout <<i+1<<". "<< words[i] << ": " << meanings[i] << endl;
}
}
int main() {

int directorySize;
// 1. Ask the user for directory size
cout << "How Many terms do you want the directory to hold? ";
cin >> directorySize;
string ln;
getline(cin,ln);

// Initialize arrays
string *words = new string[directorySize];
string *meanings = new string[directorySize];

//Read user input
readEntries(words, meanings, directorySize);
//Print user input
writeEntries(words, meanings, directorySize);

// 4. Clear memory
delete words;
delete meanings;
}

Output and compilation:

D:!1Programming\main\bin\Debug\main.exe How Many terms do you want the directory to hold? 2 Enter Term 1: Yankey Doodle Enter


Comment down for any queries

Please give a thumb up


Add a comment
Know the answer?
Add Answer to:
in c++ sample output Description A dictionary is a collection of words that contain at least...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT