0% found this document useful (0 votes)
32 views

CS 247 Assignment Two

This document contains a student's assignment for CS 247. It includes 4 questions asking the student to: 1) Explain the output of some sample code. 2) Describe software testing levels, the GNU Debugger (GDB), and pros and cons of printf debugging. 3) Explain lines of sample code that writes names to a file. 4) Implement code to open a file, display its contents, and close the file.

Uploaded by

karllixiangyu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

CS 247 Assignment Two

This document contains a student's assignment for CS 247. It includes 4 questions asking the student to: 1) Explain the output of some sample code. 2) Describe software testing levels, the GNU Debugger (GDB), and pros and cons of printf debugging. 3) Explain lines of sample code that writes names to a file. 4) Implement code to open a file, display its contents, and close the file.

Uploaded by

karllixiangyu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CS 247 Assignment Two Name: __LiXiangyu______

(25 Points for each question.)


1. Read tutorials on Topic 12, and complete the following tasks.
Read the following code, and explain what will be printed out for the six output statements, respectively.

The address of x is 0xbbe51ff81c


The value of x is 99
The address of y is 0xbbe51ff810
The value of y is 0xbbe51ff81c
The address of z is 0xbbe51ff808
The value of z is 0
Active code page: 65001
Press any key to continue . . .

2. Read tutorials on Topic 13, Topic 14 and Topic 15, and complete the following tasks.
a. What are the four levels of testing?
unit testing, integration testing, system testing and acceptance testing.

b. What is GDB?
GDB stands for GNU Project Debugger and is a powerful debugging tool for C (along with other
languages like C++).

c. What is a software bug?


A software bug is an error, flaw, or fault in an application.

d. What are the cons and pros with PRINTF debugging?


PRINTF may create security vulnerabilities and lack of advance features like call stack inspection,
memory analysis. But PRINTF debugging is straightforward and doesn't require any specialized
tools or setup, it is quick and easy to using.

3. Read tutorials on Topic 16, and complete the following tasks.


Explain the following code line by line from line 8 to line 17.
The purpose of this code is to create a file named "data.txt" and write the names "Jones," "Smith,"
"Willis," and "Davis" to it. After that, it closes the file, making sure the data is saved.

4. Read tutorials on Topic 17, and complete the following tasks.


Implement the code segment for the following task (Hint: Program 12-5)
a. Open a file with the name of sample.txt.
b. Display the content of the file.
c. #include <iostream>
d. #include <fstream>
e. #include <string>
f.
g. using namespace std;
h.
i. int main() {
j. ifstream inputFile("sample.txt"); // Open the file for input
k.
l. if (inputFile.is_open()) {
m. string line;
n. cout << "Content of the file 'sample.txt':" << endl;
o.
p. while (getline(inputFile, line)) {
q. cout << line << endl; // Display each line of the file
r. }
s.
t. inputFile.close(); // Close the file when done
u. } else {
v. cout << "Unable to open the file 'sample.txt'" << endl;
w. }
x.
y. return 0;
z. }
aa.

You might also like