Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

10 Multiple Choice Questions - Introduction to Computer Science I | CS 010, Quizzes of Computer Science

Material Type: Quiz; Professor: Miller; Class: INTRO TO CS FOR SCI,MATH&ENGR I; Subject: Computer Science; University: University of California-Riverside; Term: Spring 2004;

Typology: Quizzes

2009/2010

Uploaded on 03/28/2010

koofers-user-szl
koofers-user-szl 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 010 - Spring 2004
Name_______________________ Login___________________SID________
CS 010: Introduction to Computer Science I
Lecturer: Kris Miller
Quiz 4: 12 minutes
1. (Homework 5) Which of the following statements is needed for this code fragment to output the
correct average of all numbers in a file assuming the file was connected properly to the object
fin.
int count = 0;
double number;
double sum = 0;
// loops until end of file
while (fin >> number)
{
// adds to sum each number brought in from file
????
// keep track of how many numbers brought in
count++;
}
// output avg to screen
cout << "The average of the " << count << " numbers is: "
<< (sum / count) << endl;
a. sum = number;
b. sum = number + number;
c. sum = sum + number;
d. sum = sum + sum;
2. (Section 5.1) Which of the following is a correct declaration of an input-file stream object?
a. inputstream cin;
b. in_stream fin;
c. instream filein;
d. ifstream infile;
3. (Section 5.1) Which statement connects the file, in.txt, to the input-file stream fin, assuming fin
was declared properly.
a. fin.connect(“in.txt”);
b. open(fin, in.txt);
c. fin.open(“in.txt”);
d. connect(fin, “in.txt”);
Page 1 of 3
pf3

Partial preview of the text

Download 10 Multiple Choice Questions - Introduction to Computer Science I | CS 010 and more Quizzes Computer Science in PDF only on Docsity!

Name_______________________ Login___________________SID________

CS 010: Introduction to Computer Science I

Lecturer: Kris Miller

Quiz 4: 12 minutes

  1. (Homework 5) Which of the following statements is needed for this code fragment to output the correct average of all numbers in a file assuming the file was connected properly to the object fin. int count = 0; double number; double sum = 0; // loops until end of file while (fin >> number) { // adds to sum each number brought in from file

// keep track of how many numbers brought in count++; } // output avg to screen cout << "The average of the " << count << " numbers is: " << (sum / count) << endl; a. sum = number; b. sum = number + number; c. sum = sum + number; d. sum = sum + sum;

  1. (Section 5.1) Which of the following is a correct declaration of an input-file stream object? a. inputstream cin; b. in_stream fin; c. instream filein; d. ifstream infile;
  2. (Section 5.1) Which statement connects the file, in.txt, to the input-file stream fin , assuming fin was declared properly. a. fin.connect(“in.txt”); b. open(fin, in.txt); c. fin.open(“in.txt”); d. connect(fin, “in.txt”);

e. fin(“in.txt”);

  1. (Section 5.1) Which of the following is the correct way to determine if the input-file stream fin opened correctly? a. if (fin.open(“in.txt”)) b. if (fin.connect(“in.txt”)) c. if (fin.fail()) d. if (fin.opened()) e. if (fail(fin, “in.txt”))
  2. (Section 5.1) Which of the following correctly closes the input-file stream fin? a. fin.close(); b. fin.close(“in.txt”); c. close(fin, “in.txt”); d. close(fin);
  3. (Section 5.1) If ball is the name of an object and bounce is the name of a member function of the object ball , which of the following is a correct call to bounce that passes in an argument of type string? a. ball.bounce(“Lakers Win!”); b. bounce.ball() = “Lakers Win!”; c. ball = bounce(“Lakers Win!”); d. bounce.ball(“Lakers Win!”); e. ball.bounce() = “Lakers Win!”;
  4. (Section 5.1) After a stream is opened, before it is used for input and output, it should be a. declared b. closed c. checked to see if it opened correctly d. none of the above
  5. (Section 5.2) What is the output of the following code fragment? cout.setf(ios::left); cout << “” << setw(7) << “12345” << “” << setw(3) << “12345” << “”; a. 1234512345 b. * 1234512345 c. *12345 12345 d. *12345 123 e. *12345 345