Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given that a class object needs to read something from an input stream and print

ID: 3857417 • Letter: G

Question

Given that a class object needs to read something from an input stream and print something to an output stream, pick the best signatures of the methods which would perform the read and print actions: A) read(const char * filename): /print (const char * filename) const: B) read(const string & filename): /print (const string & filename) const: C) read(ifstream & file): /print (ofstream& file) const: D) read(istream & file);/print (ostream & file) const: E) read(void);/print(void) const: Create a function object class which will be used (perhaps in a for loop) to calculate and return the maximum value of a set of [numeric] data. class Maximum [For example, here's how you might use your class to find the largest of a set of test scores. double scores[MAX] = { 42, 55.5, 82, 74.5, 62 }: size_t num_scores = 5 max. reset(scores[0]): for(size_1 s = 1: s

Explanation / Answer

21)
Ans) C
read(ifstream & file);
print(ofstream & file) const;

ifstream - stands for input file stream in c++
ofstream - stands for output file stream in c++

Using these streams, file I/O operations in c++ are performed. So choice 'C' is the right option

22)
Ans)

class Maximum {
   private:
      double max;          
   public:
      // member functions
      double max(){
         return max;
      };
      
      void max(double num){
         if(num > max) max = num;
      };      
      // method to display distance
      void reset(double num) {
         max = num;
      };
    
};

You can use function overloading to acheive the same. In the above case, i have used max with 2 different signatures. One without any parameter and another with a double type parameter.

23)
Ans) D
choice 'D' is the answer because multiple functions use the same file. It makes sense to open a file in the main function and pass to each function to do the necessary operation. Then close the file once all the functions are done. This way you are saving I/O operations in each function which causes performance issues.

24)
Ans) E
Since we have to hold multiple blocks, it is useful to read each block into an element of class type based container so it can be used for later processing rather than reading file multiple times.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote