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
Suppose you are choosing between the following three algorithms:
Pavel [41]

Answer:

Algorithm C is chosen

Explanation:

<u>For Algorithm A </u>

T(n) = 5 * T ( n/2 ) + 0(n)

where : a = 5 , b = 2 , ∝ = 1

attached below is the remaining part of the solution

6 0
3 years ago
....is an act of introducing an invention into market on business basis for profit​
jonny [76]

Answer:

Entrepreneurship

Explanation:

6 0
3 years ago
Print person1's kids, call the incNumKids() method, and print again, outputting text as below. End each line with a newline.
Brilliant_brown [7]

Answer:

Explanation:

The following code was written in Java and modifies the code so that for the given input such as 3 it outputs the exact information shown in the sample output.

import java.util.Scanner;

class CallPersonInfo {

   public static void main(String [] args) {

       Scanner scnr = new Scanner(System.in);

       PersonInfo person1 = new PersonInfo();

       int personsKid;

       System.out.println("How many kids do you have:");

       personsKid = scnr.nextInt();

       person1.setNumKids(personsKid);

       /* Your solution goes here */

       System.out.println("Kids: " + person1.getNumKids());

       person1.incNumKids();

       System.out.println("New Baby, kids now: " + person1.getNumKids());

   }

}

class PersonInfo {

   private int numKids;

   public void setNumKids(int setPersonsKids) {

       numKids = setPersonsKids;

   }

   public void incNumKids() {

       numKids = numKids + 1;

   }

   public int getNumKids() {

       return numKids;

   }

}

4 0
3 years ago
In every programming language, when you access data stored in an array, you must use a ____ containing a value that accesses mem
Mariulka [41]
An array is an indexed collection of data elements. First you must declare an array, give its name and data. <span>Once your arrays are declared, you access the elements in an array with the array name, and the index number inside brackets [ ].
So, in every </span><span>programming language, when you access data stored in an array, you must use a command [] (brackets) containing a value that accesses memory occupied by the array.</span>
4 0
3 years ago
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
lyudmila [28]

I am not able to open the pdf kindly send the jpg form.

4 0
3 years ago
Read 2 more answers
Other questions:
  • Write a program that determines the value of the coins in a jar and prints the total in dollars and cents. Read integer values t
    5·1 answer
  • PLEASE HURRYYY Suppose your employer wants you to purchase a tablet device that you will use to run the company's custom sales s
    15·2 answers
  • ____ refers to the order in which values are used with operators.
    9·1 answer
  • Which of the following would allow for the QUICKEST restoration of a server into a warm recovery site in a case in which server
    10·1 answer
  • What 2 important components are found on a motherboard? (2 points each)
    13·1 answer
  • If a fuse block or holder has tree fuses, it may be termed a...
    7·1 answer
  • Write a program that will sort an array of data using the following guidelines - DO NOT USE VECTORS, COLLECTIONS, SETS or any ot
    10·1 answer
  • Which soft skills would these mobile app developers need to use in the situations described?
    8·2 answers
  • which of the following is acomputer program that detects, prevents. and takes action sto deactivate or remove malicious programm
    12·1 answer
  • The short-range two-way communication technology behind contactless payments is called ____.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!