1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alja [10]
3 years ago
5

Write a program that allows the user to type in any one-line question and then answers that question. The program will not reall

y pay any attention to the question, but will simply read the question line and discard all that it reads. It always gives one of the following answers:I'm not sure, but I think you will find the answer in Chapter #N.
That's a good question.
If I were you, I would not worry about such things.
That question has puzzled philosophers for centuries.
I don't know. I'm just a machine.
Think about it and the answer will come to you.
I used to know the answer to that question, but I've forgotten it.
The answer can be found in a secret place in the woods.
These answers are stored in a file (one answer per line), and your program simply reads the next answer from the file and writes it out to the console as the answer to the question. After your program has read the entire file, it simply closes the file, reopens the file, and starts down the list of answers again.
Whenever your program outputs the first answer, it should replace the two symbols #N with a random number between 1 and 18 (including the possibility of 1 and 18). In order to choose a random number between 1 and 18, your program should call the rand() function (remember to call srand() at the beginning of the program to seed the rand() function). Also, have the program prompt the user for the name of the answer file.
Computers and Technology
1 answer:
weqwewe [10]3 years ago
6 0

<u>Solution and Explanation:</u>

//Header files

#include<iostream>

#include<string>

#include<fstream>

using namespace std;

int main()

{

           fstream fin;

           char str[]="";

           string question;

           char filename[20];

           char choice;

           string answer;

           //seed for random number

           unsigned seed=0;

           srand(seed);

           cout<<"Enter your file name : ";

           cin>>filename;

           cout<<endl;

           //if file not exist then gives message

           //reading file

           do

           {

                       fin.open(filename,ios::in);

                       if(!fin)

                       {

                                   cout<<"couldnot find the file...";

                                   std::system("pause");

                                   return 0;

                       }

                       while(!fin.fail())

                       {      

                                   cout<<endl<<"Enter your quesion"<<endl;

                                   fflush(stdin);

                                   getline(cin,question);

                                   answer="";

                                   char ch;

                                   while((ch=fin.get())!='\n'&&!fin.fail())

                                   {

                                               //reading line

                                               answer+=ch;

                                               if(ch=='#')

                                               {

                                                           int randNum=1+rand()%18;

                                                           answer +=randNum+'0';

                                                           ch=fin.get();

                                               }

                                   }

                                   cout<<answer<<endl;

                       }

                       fin.close();

                       cout<<"Do you want to continue (Y/y to continue) :";

                       cin>>choice;

           }while(choice=='y'||choice=='Y');

           //To pause the output

           system("pause");

           return 0;

}//end of main..

You might be interested in
HELP PLSSSSS!!! I WILL MARK BRAINLIEST FOR THE FIRST AND CORRECT ANSWER!!!
dalvyx [7]
The answer you are looking for would be A. Hardware can be an external tool, where as software is an internal tool. Hope this helped!
6 0
3 years ago
Read 2 more answers
What is A wage paid based on the ability to sell a product or service is (a) _____.
Fantom [35]
The answer is commissioned
5 0
4 years ago
Substance abuse is an _____ coping mechanism.
hichkok12 [17]
Mental coping mechanism.
7 0
3 years ago
Write a code to load Shepp Logan phantoms and use the radon transform for parallel beam to generate a sinogram for 360 degree ro
jeyben [28]
他們也在週四在家休息時間接受媒體訪問時指出,他們
6 0
3 years ago
let m be a positive integer with n bit binary representation an-1 an-2 ... a1a0 with an-1=1 what are the smallest and largest va
Ahat [919]

Answer:

Explanation:

From the given information:

a_{n-1} , a_{n-2}...a_o in binary is:

a_{n-1}\times 2^{n-1}  + a_{n-2}}\times 2^{n-2}+ ...+a_o

So, the largest number posses all a_{n-1} , a_{n-2}...a_o  nonzero, however, the smallest number has a_{n-2} , a_{n-3}...a_o all zero.

∴

The largest = 11111. . .1 in n times and the smallest = 1000. . .0 in n -1 times

i.e.

(11111111...1)_2 = ( 1 \times 2^{n-1} + 1\times 2^{n-2} + ... + 1 )_{10}

= \dfrac{1(2^n-1)}{2-1}

\mathbf{=2^n -1}

(1000...0)_2 = (1 \times 2^{n-1} + 0 \times 2^{n-2} + 0 \times 2^{n-3} + ... + 0)_{10}

\mathbf {= 2 ^{n-1}}

Hence, the smallest value is \mathbf{2^{n-1}} and the largest value is \mathbf{2^{n}-1}

3 0
3 years ago
Other questions:
  • Which setting indents all but the first line of a paragraph by the selected length?
    6·1 answer
  • Which osi reference model layer includes all programs on a computer that interact with the network?
    13·1 answer
  • Explain why living things store energy in lipids instead of in carbohydrates
    5·1 answer
  • When internet techonology was developed in the 1970s by the department of defense?
    10·1 answer
  • In the Dynamic Partitioning technique of memory management, the placement algorithm that scans memory from the location of the l
    11·1 answer
  • Which line of code outputs the decimal portion of a float stored in the variable x? print (x % 1000) print (x) O print (x / 1000
    13·1 answer
  • 2.13 LAB: Branches: Leap Year
    11·1 answer
  • Laptop computers use PCMCIA cards, another type of ________
    15·1 answer
  • Arrange the Jumbled letters 1.eilf ngrihsa ________________ 2.cersityu ourreecs ________________ 3. ngrihsa ________________ 4.
    12·1 answer
  • Priortization is an example of a skill that helps you reach long term goals because
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!