Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) write a program that analyzes a data file that has been determined to contain

ID: 3625116 • Letter: 1

Question


1)
write a program that analyzes a data file that has been determined to contain only integer values and white spaces. The program should print the number of lines in the file and the number of integer values (not integer digits)

2)
write a program that reads a file containing data values computed by an accounting software package. while the file contains only numerical information, the values may contain embedded commas and dollar signs, as in $3,200, and negative values are enclosed in parentheses, as in (200.56). write a program to generate a new file that contains the values with the commas and dollar signs removed, and with a leading minus sign instead of the parentheses. do not change the number of values per line in the file.

RATE LIFE SAVER

Explanation / Answer

//Headerfile section

#include<iostream>

#include<fstream>

using namespace std;

void main()

{ //Start main function

   int linecounter,counter,num,sum; //Variable declaration

   ifstream infile;

   counter=0;

   linecounter=0;

   infile.open("numbers.txt");//opening file

   infile>>num;

   //Logic

   while(infile)

   {

     sum=0;

     while(num==-999)

     {

       linecounter++;

     }

     counter++;

     infile>>num;

   }//End of while loop

   cout<<"Number of Lines:"<<linecounter<<endl;

   cout<<"Number of Integers:"<<counter<<endl;

   infile.close();//closing file

   system("pause");

}//End of main