I'm a basic C++ programmer, and I am stuck on this problem. You work for a company that collects a set of numbers. The numbers are located in a data file named "./Data_File". The data file contains two columns. My question is, how do you count a certain number on the left column.
class Company
{
public:
void load_data();
int count_nums_by_type();
private:
struct CompInfo
{
int fav_num; //number I am trying to find (nums range 1-10)
int hours_tv //num of how many hours of tv you watch per night
};
ifstream in_data1; //data from file
int num_people;
};
int main ()
{
load_data();
count_nums_by_type();
in_data1.close();
delete [] CompNums;
}
void Company::load_data(); //loads the file into the array, and counts the data
{
string line;
int size = 0;
in_data1.open(DATA_FILE);
if (in_data1.fail())
{
cout<<"cannot open instream input file\n\n";
return (FAIL);
}
while(getline(in_data1, line)) size++;
in_data1.close();
in_data1.open(DATA_FILE);
CompInfo *CompNums = new CompInfo[size];
for(int i = 0; i < size; i++)
{
in_data1>>CompNums[i].fav_num;
in_data1>>CompNums[i].hours_tv;
}
}
int Company::count_nums_by_type();
{
//This is the part I am confused on. How would I count the number of each type
//of numbers (1-10)
}
For example, you throw dice. When you get 2 for the first time, you have seen 2 once. Every time you get 2 again, you have got 2 one more time than so far. Same procedure for the other values. Thus, in the end you have a table where you have (value, count) pairs.