Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Create organized functions with the single lines of code by declaring the functions, calling the function, then defining the function. Please help me make this look cleaner... The code should operate the same. C++

#include <iostream>
#include <vector>
#include <string>
#include <ctime>
using namespace std;


int main()
{
srand(static_cast<unsigned int> (time(0)));
const int N = 4;
string wordP[N] = { "engineer",
"cooper union", "final", "new york university" };


for (int i = 0; i <= N; i++) {
cout << wordP[i]<< endl;
}

label:

int z = rand() % N;
string word = wordP[z];
string scrambled = word;

const int rp = scrambled.size();

for (int letter = 0; letter < rp; letter++) {

int z = rand() % rp;
char game = scrambled[z];
scrambled[z] = scrambled[letter];
scrambled[letter] = game;
}

unsigned int t1 = time(0);

string begin;
do {
cout << "Lets play a game.." << endl << " Unscramble the following words in order to proceed" << " " <<endl<< "word:"<<" "<<scrambled << endl;
cin >> begin;
if (begin == word) {
cout << "Congratulations you beat the game" << endl;
break;
}

} while (begin != "Quit");
unsigned int t2 = time(0);
unsigned int score = (t2 - t1);
cout << "It took " << score << "seconds" << endl;
cout << " Thank you, come again!!" << endl;
char approval;
cout<<"Do you wish to play again (y for yes, n for no): ";
cin>>approval;
if(approval == 'y'){
     cout<<"\n\n";
     goto label;
}
 else
     cout<<"\nExiting....";
return 0;
}

 

Expert Solution
Check Mark
Step 1

Answer:

I have done code  and also I have attached code and code screenshot as well as output 

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education