Question

1. Suppose you wrote a program that reads data from cin. You are now required to...

1. Suppose you wrote a program that reads data from cin. You are now required to reimplement it so that you can read data from a file. You are considering the following changes.

I. Declare an ifstream variable in_file

II. Replace all occurrences of cin with in_file

III. Replace all occurrences of > > and get_line with the appropriate operations for ifstream objects

What changes do you need to make?

I, II, and III

II and III

I and III

I and II

2. What is the output of the following code snippet?

cout << setw(2) << setfill('0') << 9;

209

09

009

9

QUESTION 3

  1. What does the following code snippet do for a file of unknown size?

    int i = 0;
    ifstream in_file;
    string mystring;
    in_file.open("test.txt");
    while (getline(in_file, mystring))
    {
       i++;
    }
    cout << i << endl;

    Counts the number of digits in the file

    Counts the number of words in the file

    Counts the number of lines in the file

    Counts the number of characters in the file

5 points   

QUESTION 4

  1. Consider the following code snippet:

    1. int main()
    2. {
    3.    char rd;
    4.    ifstream read_file;
    5.    read_file.open("C:\network.txt");
    6.    while (read_file.get(rd))
    7.    {
    8.       cout << rd << endl;
    9.    }
    10.   return 0;
    11. }

    Which of the following statements describes the problem with this code snippet?

    The program contains an infinite loop.

    There is a syntax error in line 6.

    Line 5 does not open the file C:\network.txt.

    The variable read_file is never assigned a value.

5 points   

QUESTION 5

  1. Assuming that "out_file" is an ofstream object, what is the correct way of opening a file "Employees.txt" for writing?

    out_Employees.open(Employees.txt);

    out_file(Employees.txt);

    out_file.open("Employees.txt");

    out_file("Employees.txt");

QUESTION 6

  1. The command line argument argc has a value of 4. What does this mean?

    In fact argc must be less than 4.

    There are three command line arguments stored as character strings that are pointed to by the elements of argv[1], argv[2], and argv[3].

    There are three command line arguments stored as character strings that are pointed to by the elements of argv[0], argv[1], and argv[2].

    There are three command line arguments stored as elements of argv[1], argv[2], andargv[3].

QUESTION 7

  1. Which of the following is the correct way to call the open function on an ofstream object called writestr?

    writestr.open("File", ".txt")

    writestr.open("File.txt", "write")

    writestr.open("File.txt")

    writestr.open()

QUESTION 8

  1. Suppose you wrote a program that writes data using cout. You are now required to implement it so that you can write data to a file. You are considering the following changes.

    I. Declare an ofstream variable out_file

    II. Replace all occurrences of cout with out_file

    III. Replace all occurrences of < < and put_line with the appropriate operations for ofstream objects

    What changes do you need to make?

    I, II, and III

    II and III

    I and III

    I and II

question 9

  1. To receive command line arguments at run-time, which of the following options represents the correct way to define the main function?

    int main(int* argc, char argv)

    int main(int argc[], char* argv)

    int main(int argc, char argv[])

    int main(int argc, char* argv[])

QUESTION 10

  1. Which of the following function calls can be used to get the current position for reading from a random access file?

    strm.seekg(position)

    strm.tellg()

    strm.tellg(position)

    strm.tellp()

0 0
Add a comment Improve this question Transcribed image text
Answer #1
1.
Option D: I and II only.

2.
09 Option B

3.
C. Counts the number of lines in the file

4.
A. The program contains an infinite loop.

5.
C. out_file.open("Employees.txt");

6.
B. There are three command line arguments stored as character strings that are pointed to by the elements of argv[1], argv[2], and argv[3].

7.
C. writestr.open("File.txt")

8.
D.      I and II

9.
D. int main(int argc, char* argv[])

10.
B. strm.tellg()

Add a comment
Know the answer?
Add Answer to:
1. Suppose you wrote a program that reads data from cin. You are now required to...
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
  • C++ problem. hi heys, i am trying to remove beginning and the end whitespace in one...

    C++ problem. hi heys, i am trying to remove beginning and the end whitespace in one file, and output the result to another file. But i am confused about how to remove whitespace. i need to make a function to do it. It should use string, anyone can help me ? here is my code. #include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> using namespace std; void IsFileName(string filename); int main(int argc, char const *argv[]) { string inputfileName = argv[1];...

  • C programming Question1 (a) Write a C program that will print out all command line arguments,...

    C programming Question1 (a) Write a C program that will print out all command line arguments, in reverse order, one per line. Prefix each line with its index. 6 marks] (b) Consider this C code snippet int a- 100 int b- 42; inte p- &a; int q-b; p qi printf ("%d %d\n" ,a,*p); When this code is executed, what numbers will it print? [2 marks] (c) Consider this C program int main(int argc,char argv) char* target- "Apple" char vord[100] printf...

  • Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text...

    Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text file by removing all blank lines (including lines that only contain white spaces), all spaces/tabs before the beginning of the line, and all spaces/tabs at the end of the line. The file must be saved under a different name with all the lines numbered and a single blank line added at the end of the file. For example, if the input file is given...

  • Am I getting this error because i declared 'n' as an int, and then asking it...

    Am I getting this error because i declared 'n' as an int, and then asking it to make it a double? This is the coude: #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <algorithm> #include <vector> using namespace std; void sort(double grades[], int size); char calGrade(double); int main() {    int n;    double avg, sum = 0;;    string in_file, out_file;    cout << "Please enter the name of the input file: ";    cin >> in_file;   ...

  • If you already answer this question, please skip, thanks C Programming. Fill in ... This program...

    If you already answer this question, please skip, thanks C Programming. Fill in ... This program will be called with one command line argument that contains a string followed by an asterisk and an integer. Print out the string as many time as indicated by the integer. For example, when called as prog Hi*3, you print HiHiHi. Hint: Look for the '*' starting from the back of the string. len = strlen(arg) gives you the string length. When you have...

  • Program already solved, but I need to put function documentation headers for each and every function...

    Program already solved, but I need to put function documentation headers for each and every function in your program (for the ones you write, and keep the function header I give you for the main() function). Also make sure you keep the file block header at the top of the file, and fill in the information correctly. Secondly this week you must get your indentation correct. All indentation must use 2 spaces, and you should not have embedded tabs in...

  • I am writing a program in C++, which requires me to read an input text file...

    I am writing a program in C++, which requires me to read an input text file using command line argument. However, I am using xcode on my Macbook to write C++ program, and use terminal instead of command. How do you use int main(int argc, char** argv[]) to read an input file. My professor requires us not to hard code the text file name like .open("example.txt"); Thank you!

  • T/F C Language Questions. Answer the following true/false questions. You must correctly state WHY your answer...

    T/F C Language Questions. Answer the following true/false questions. You must correctly state WHY your answer is true or false in order to receive credit. #include <stdio.h> #include <string.h> int run_through(int num, char **a) { int i; int check=0; for(i=0;i<num;i++) { printf("%s\n", *(a+i)); if(strcmp(*(a+i), "filename")==0) { check=1; } } return check; } char** find_filename(int n, char **b) { int i; int check=0; for(i=0;i<n;i++) { if(strcmp(*b, "filename")==0) { b++; break; } b++; } return b; } int main(int argc, char **argv)...

  • Hi, need this question ansered in c++, has multiple levels will post again if you can...

    Hi, need this question ansered in c++, has multiple levels will post again if you can complete every level so keep an eye out for that. here is a sketch of the program from the screenshot int main (int argc, char** argv) { enum { total, unique } mode = total; for (int c; (c = getopt(argc, argv, "tu")) != -1;) { switch(c) { case 't': mode = total; break; case 'u': mode = unique; break; } } argc -=...

  • C Language Programming. Using the program below - When executing on the command line only this...

    C Language Programming. Using the program below - When executing on the command line only this program name, the program will accept keyboard input and display such until the user does control+break to exit the program. The new code should within only this case situation “if (argc == 1){ /* no args; copy standard input */” Replace line #20 “filecopy(stdin, stdout);” with new code. Open read a text file “7NoInputFileResponse.txt” that contains a message “There were no arguments on the...

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
ADVERTISEMENT