Question: How would I desk check this program code? // Program to create a prices text file You require an algorithm that will read and write
How would I desk check this program code?
// Program to create a prices text file
You require an algorithm that will read and write text files after adding the appropriate pre-processors.
A Defining diagram
| Input | Processing | Output |
| Enter Appropriate preprocessors | Create filename Convert file name If the file name unable to write |
The file was not successfully opened
The file has been successfully written. |
| #include |
|
|
| #include |
|
|
| #include #include #include
|
|
|
B Solution algorithm
Calculate
1
2
3
4
5
6
7
8
END
END
C Desk checking
i Input data:
|
| First data set | Second data set |
| integer |
|
|
ii Expected results:
|
| First data set | Second data set |
| final_number |
|
|
iii Desk check table:
| Statement number | integer | new_number | final_number |
| First pass |
|
|
|
| 1 |
|
|
|
| 2 |
|
|
|
| 3 |
|
|
|
| 4 |
|
|
|
| 5 |
|
|
|
| 6 |
|
|
|
| 7 |
|
|
|
| 8 |
|
|
|
This is the layout I must use. but I did it wrong... This is just to show what I've done. I couldn't figure how to breakdown the code to enter into the boxes.
#include "stdafx.h"
#include
#include
#include
#include
#include
using namespace std;
int main()
{
string filename = "prices.txt"; // put the filename up front
ofstream outFile;
outFile.open(filename.c_str()); // Converting filename
if (outFile.fail()) // If the file unable to open display error message
{
cout << "The file was not successfully opened" << endl; // displayed message
exit(1);
}
// set the output file stream formats
outFile << setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setprecision(2);
// send data to the file
outFile << "Mats " << 39.95 << endl
<< "Bulbs " << 3.22 << endl
<< "Fuses " << 1.08 << endl;
outFile.close(); // close file
cout << "The file " << filename
<< " has been successfully written." << endl; // displays success message
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
