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
  • Modification of original code so it can include 1) at least one array 2)*New English words...

    Modification of original code so it can include 1) at least one array 2)*New English words that are written/saved to the .txt file(s) must be in alphabetical order* (e.g, Apple cannot be in a lower line than Orange). This is what I'm really struggling with as I don't know how to organize alphabetically only the english word translation without the spanish equivalent word also getting organized. The only idea I have right now is to recreate the code using two...

  • C++ for this exercise, you will make a simple Dungeon Crawl game. For an enhanced version,...

    C++ for this exercise, you will make a simple Dungeon Crawl game. For an enhanced version, you can add monsters that randomly move around. Program Requirements While the program is an introduction to two-dimensional arrays, it is also a review of functions and input validation. check: Does the program compile and properly run? does all functions have prototypes? Are all functions commented? Is the program itself commented? Are constants used where appropriate? Are the required functions implemented? Is the dungeon...

  • Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an...

    Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an order at a fast-food burger joint. This class will be used in Part B, when we work with a list of orders. As vou work through this part and Part B, draw a UML diagram of each class in using the UML drawing tool 1) Create a new Lab5TestProject project in Netbeans, right-click on the lab5testproject package and select New>Java Class 2) Call your...

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