C++ need #7 and #8
6. Write code that does the following: Opens an output file with the filename Numbers.txt, uses a loop to write the numbers 1 through 100 to the file, and then closes the file. ofstream outputFile("Numbers.txt"); for(int number = 1; number <= 100; number++) outputFile<< number << endl; outputFile.close();
7. Write code that does the following: Opens the Numbers.txt file that was created by the code you wrote in question 6, reads all of the numbers from the file and displays them, and then closes the file.
8. Modify the code that you wrote in question 7 so it adds all of the numbers read from the file and displays their total.
Answer 7:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream inputFile;
int num;
//opening the file
inputFile.open("Numbers.txt");
if (inputFile.fail()){
cout << "File open error....";
return 0;
}
//reading the numbers from user and storing in the array
while (!inputFile.eof()){
inputFile >> num;
cout<<num<<" ";
}
return 0;
}

Answer 8:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream inputFile;
int num,total=0;
//opening the file
inputFile.open("Numbers.txt");
if (inputFile.fail()){
cout << "File open error....";
return 0;
}
//reading the numbers from user and storing in the array
while (!inputFile.eof()){
inputFile >> num;
total+=num;
}
cout<<"Total : "<<total;
return 0;
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
C++ need #7 and #8 6. Write code that does the following: Opens an output file...
C++ language Write a program that 1. generates a random integer between 100 and 1000, call the number N 2. reads a file name from the keyboard 3. opens a file for output using the file name from step 2 4. generates N random numbers between 1 and 100 and writes them to the file from step 3 5. closes the file 6. opens the file from steps 3, and 4 for input 7. reads the numbers from the file...
Write a program **(IN C)** that displays all the phone numbers in a file that match the area code that the user is searching for. The program prompts the user to enter the phone number and the name of a file. The program writes the matching phone numbers to the output file. For example, Enter the file name: phone_numbers.txt Enter the area code: 813 Output: encoded words are written to file: 813_phone_numbers.txt The program reads the content of the file...
I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using namespace std; int NumOfEmployees(); int TotDaysAbsent(int); double AverageAbsent(int, int); int main() { cout << endl << "Calculate the average number of days a company's employees are absent." << endl << endl; int numOfEmployees = NumOfEmployees(); TotDaysAbsent(numOfEmployees); return 0; } int NumOfEmployees() { int numOfEmployees = 0; cout << "Please enter the number of employees in the company: "; cin >> numOfEmployees; while(numOfEmployees <= 0) { ...
I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using namespace std; int NumOfEmployees(); int TotDaysAbsent(int); double AverageAbsent(int, int); int main() { cout << endl << "Calculate the average number of days a company's employees are absent." << endl << endl; int numOfEmployees = NumOfEmployees(); TotDaysAbsent(numOfEmployees); return 0; } int NumOfEmployees() { int numOfEmployees = 0; cout << "Please enter the number of employees in the company: "; cin >> numOfEmployees; while(numOfEmployees <= 0) {...
In java language, use IntelliJ IDEA : 1. Write code that does the following: Opens a file named numberList.txt, uses a for loop to write all the even numbers between 1 and 50 to the file. 2. Write a code that does the following: Opens a file named numberList.txt, uses a for loop to append all the odd numbers between 1 and 50 to the file without deleting the existing data.
Write a C++ program that open the text file “numbers.txt”. (the numbers.txt looks like: ' 1. 6 8 ') Have a “output.txt” If summation of the numbers is bigger than 10, your code must write the first number inside “numbers.txt” in another file called “output.txt”. (use conditional statement for comparison)
I need help in Python. This is a two step problem So I have the code down, but I am missing some requirements that I am stuck on. Also, I need help verifying the problem is correct.:) 7. Random Number File Writer Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 500. The application should let the user specify how many random numbers the file...
How to write a Java file out that that reads from numbers.txt with these numbers 2 6 7 9 5 4 3 8 0 1 6 8 2 3 and write to a file called totalSum.txt that looks like: 2+6+7+9=24 and so on using this code import java.io.*; import java.util.Scanner; public class FileScanner { public static void main(String[] args) { /* For Homework! Tokens*/ Scanner file = null; PrintWriter fout= null; ...
Please write a java program with a input file "jabberwock.txt", and output the "output.txt" with following requirement. You and your partner will be writing a simple Java program that implements some basic file I/O operations. You can use this code as the basis for some of your next project. FIRST: Write code that prompts the user for the name of a text file, opens that file if it exists and reads the file one line at a time printing each...
I need to update this C++ code according to these instructions.
The team name should be "Scooterbacks".
I appreciate any help!
Here is my code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void menu();
int loadFile(string file,string names[],int jNo[],string
pos[],int scores[]);
string lowestScorer(string names[],int scores[],int size);
string highestScorer(string names[],int scores[],int size);
void searchByName(string names[],int jNo[],string pos[],int
scores[],int size);
int totalPoints(int scores[],int size);
void sortByName(string names[],int jNo[],string pos[],int
scores[],int size);
void displayToScreen(string names[],int jNo[],string pos[],int
scores[],int size);
void writeToFile(string...