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
  • Command line input In C++ it is possible to accept command line arguments. Command-line arguments are...

    Command line input In C++ it is possible to accept command line arguments. Command-line arguments are given after the name of a program in command-line operating systems like Linux and are passed in to the program from the operating system. To use command line arguments in the program, it must first understand the full declaration of the main function, which until now has accepted no arguments. In fact, main can accept two arguments: one argument is number of command line...

  • 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...

  • I need help programming this question using C language. This program uses input data entered in...

    I need help programming this question using C language. This program uses input data entered in command line at the same time when the command or .exe file is entered. They are called command-line arguments. Because everything entered in command line is taken as a string, these arguments including the command itself or the .exe file name are stored in an array of char pointers, each pointer points to the first character of a string (i.e., argument). The inputs can...

  • 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;   ...

  • In C Programming Adding to your program in part A, go through the command line arguments...

    In C Programming Adding to your program in part A, go through the command line arguments and find the largest and smallest arguments by alphabetical order. Note that you should not need to sort your arguments, but instead compare them and save the smallest and largest strings as you go through. For example, if called with ./reverse one two three: It would display the output for part A:             Three two one And then it would display   The smallest string was:...

  • 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...

  • 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!

  • 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...

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