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 is less than 5, your code must write last number inside “numbers.txt” in “output.txt”, else it must write the number in between in “output.txt”
(use conditional statement for comparison)
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
#include <iostream>
#include <fstream>
using namespace std;
int main() {
int sum_of_num = 0, fist_num, lst_num, cnt = 0; // summation of the
numbers in file initialized to 0
int a; // variable 'a' holds each integer after reading it
ifstream File; // File object creation
File.open("numbers.txt"); // numbers.txt is opened
if (!File) {
cout << "Error opening file";
return 0;
}
freopen("output.txt", "w", stdout);
int i=0;
while (File >> a) { // reading each integer and summing it
up
if(i==0){
fist_num = a;
i++;
}
lst_num = a;
sum_of_num = sum_of_num + a;
cnt++;
}
File.close();
if(sum_of_num>10){
cout << fist_num << "\n";
}
else{
if(sum_of_num<5){
cout << lst_num << "\n";
}else{
File.open("numbers.txt");
i = 0;
while (File >> a) { // reading each integer and summing it
up
if(i!=0 && i < cnt-1 ){
cout << a << "\n";
}
i++;
}
File.close();
}
}
return 0;
}
Kindly revert for any queries
Thanks.
Write a C++ program that open the text file “numbers.txt”. (the numbers.txt looks like: ' 1....
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)
Write a program that reads the integer numbers in a text file
(numbers.txt) and stores the numbers to a binary file
(binaryNumber.dat). (5 pts)
The number.txt file contains the following numbers:
1 2 3 4 5 6 7 8 9 0
7. Write a program that reads the integer numbers in a text file (numbers.txt) and stores the numbers to a binary file (binaryNumber.dat). (5 pts) The number.txt file contains the following numbers: 1 2 3 4 5 6 7...
Write a program that reads the integer numbers in a text file
(numbers.txt) and stores the numbers to a binary file
(binaryNumber.dat). (5 pts)
The number.txt file contains the following numbers:
1 2 3 4 5 6 7 8 9 0
IN JAVA PLZ
7. Write a program that reads the integer numbers in a text file (numbers.txt) and stores the numbers to a binary file (binaryNumber.dat). (5 pts) The number.txt file contains the following numbers: 1 2 3 4...
Lab 10 Write a program that reads the integer numbers in a text file (numbers.txt) and stores the numbers to a binary file (binaryNumber.dat). The number.txt file contains the following numbers: 1 2 3 4 5 6 7 8 9 0
Lab 10 Write a Java program that reads the integer numbers in a text file (numbers.txt) and stores the numbers to a binary file (binaryNumber.dat).The number.txt file contains the following numbers: 1 2 3 4 5 6 7 8 9 0
python
Create a program to open a text file for reading, find the maximum number in the file, determine if that maximum number is even, and write to an output text file. You should either write Yes if the number is even, otherwise write the maximum number. You should note the following: • Your input file must be named input.txt • The input file has one integer number per line • Your output file must be named output.txt • Your...
Write a C++ program that reads text from a file and encrypts the file by adding 6 to the ASCII value of each character. See section 5.11 in Starting out with C++ for information on reading and writing to text files. Your program should: 1. Read the provided plain.txt file one line at a time. Because this file has spaces, use getline (see section 3.8). 2. Change each character of the string by adding 6 to it. 3. Write the...
If you have a file named phone-numbers.txt that looks like this: 207-568-6723 617-277-2343 207-822-9645 603-314-5892 800-233-3413 Doing "sort phone-numbers.txt" will end up sorting by area code. What if you want to sort by the last 4 numbers? sort -n phone-numbers.txt sort -t\- -k3 phone-numbers.txt sort [[:allnum:]]$ phone-numbers.txt cat -r phone-numbers.txt | sort -rn
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; ...
using C++ , write a program that will open a file called "first.txt" and will count how many lines are in the file. Inside the file "first.txt" looks like below but without the spaces inbetween. S D D F G H J