write a program that saves records to a sequential access file named Trythis17.t
ID: 665733 • Letter: W
Question
write a program that saves records to a sequential access file named Trythis17.txt. Each record should appear on a separate line and contain two fields separated by the umber sign (#). The first field should contain numbers from 10 through 25. The second field should contain the square of the number in the first field. For example, the the first record will contain 10#100 followed by a newline character. Display the message "Numbers saved in file" if the program was able to save the numbers. (code in C++)
Explanation / Answer
working c++ code
#include<iostream.h>
#include <fstream>
int main()
{
int i,j;
ofstream myfile;
myfile.open ("Trythis17.txt");
for (i=10;i<26;i++)
{
j=i*i;
myfile<<i<<"#"<<j<<endl;
}
myfile.close();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.