heey guys.. i have this h.w.. i solved the first part which is based on the second part.. but not sure whether i did it right or not.. can someone check plz..
this is the Q.. i only did the first part!
First create a one dimensional array called numbers that contains the following data
(Initialize the array with the numbers listed below).
6,7,-3,-4,5,-5,10
Output the array data to a file called data.txt.
==============================================
Then:
1) Calculate how many items are there in the file.
2) Calculates the number of the positive numbers and negative numbers
3) Calculate the sum of the positive numbers only.
4) Get a target from the user to search for; e.g. 7 (as an input from the screen)
5) Sort the array’s elements in ascending order and follow exactly the file snapshot next page.
6) Then append the result of 1) to 5) to the same file.
==============================================
now i created the input file and added the numbers to it.. but after running the program.. the numbers didn't appear in the output file.. dunnu why.. is smthn wrong with my code?
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
int main ()
{
int NUMBERS [7] = {6,7,-3,-4,5,-5,10};
//declare file:
ifstream read_in;
ofstream data_out;
//initialize file:
read_in.open ("read_data.txt");
data_out.open ("data.txt");
//check file:
if (data_out.fail())
cout<<"Exit data";
if (read_in.fail())
cout<<"Exit read_data";
//use file:
for (int i=0;i>=6;i++)
{
read_in>>NUMBERS [i];
data_out<<NUMBERS [i];
}
//close file:
read_in.close();
data_out.close ();
return 0;
}