Question

I am sorry for the confusing but here is what i would to be done in...

I am sorry for the confusing but here is what i would to be done in C++.

What to expect as output:

1- Report how many lines in the file.

2- How many columns in each row.

3- How many different classes in the file (last column)

4- You should have at least one function in your solution.

5.1 0.222222 3.5 0.625 1.4 0.067797 0.2 0.041667 setosa
4.9 0.166667 3 0.416667 1.4 0.067797 0.2 0.041667 setosa
4.7 0.111111 3.2 0.5 1.3 0.050847 0.2 0.041667 setosa
4.6 0.083333 3.1 0.458333 1.5 0.084746 0.2 0.041667 setosa
5 0.194444 3.6 0.666667 1.4 0.067797 0.2 0.041667 setosa
5.4 0.305556 3.9 0.791667 1.7 0.118644 0.4 0.125 setosa
6.4 0.583333 2.7 0.291667 5.3 0.728814 1.9 0.75 virginica
6.8 0.694444 3 0.416667 5.5 0.762712 2.1 0.833333 virginica
5.7 0.388889 2.5 0.208333 5 0.677966 2 0.791667 virginica
5.8 0.416667 2.8 0.333333 5.1 0.694915 2.4 0.958333 virginica
6.4 0.583333 3.2 0.5 5.3 0.728814 2.3 0.916667 virginica
6.5 0.611111 3 0.416667 5.5 0.762712 1.8 0.708333 virginica
7.7 0.944444 3.8 0.75 6.7 0.966102 2.2 0.875 virginica
4.6 0.083333 3.4 0.583333 1.4 0.067797 0.3 0.083333 setosa
5 0.194444 3.4 0.583333 1.5 0.084746 0.2 0.041667 setosa
4.4 0.027778 2.9 0.375 1.4 0.067797 0.2 0.041667 setosa
4.9 0.166667 3.1 0.458333 1.5 0.084746 0.1 0.01 setosa
6.4 0.583333 2.7 0.291667 5.3 0.728814 1.9 0.75 virginica
6.8 0.694444 3 0.416667 5.5 0.762712 2.1 0.833333 virginica
5.7 0.388889 2.5 0.208333 5 0.677966 2 0.791667 virginica
5.8 0.416667 2.8 0.333333 5.1 0.694915 2.4 0.958333 virginica

Here is the file.

Homework Answers

Answer #1

The program is below. Save it file in count_lines.cpp

#include <iostream>
#include <fstream>
using namespace std;

// returns number of words in a str
unsigned count_words(char *str) {
int state = 0;
unsigned wc = 0; // word count
  
// Scan all characters
while (*str)
{
// If next character is a separator, set the flag state
if (*str == ' ' || *str == '\n' || *str == '\t')
state = 0;
  
// If next character is not a word separator increment word count
else if (state == 0){
state = 1;
++wc;
}
// check next character
++str;
}
return wc;
}

void find_column() {
ifstream fin;
   fin.open("file.txt");
   char str[80];
   int count=0;
   while(!fin.eof())
   {
       fin.getline(str,80);
       break;
   }
   fin.close();
   cout << "Column count "<< count_words(str);
}

void count_lines(){
   ifstream fin;
   fin.open("file.txt");
   char str[100];
   int count=0;
   while(!fin.eof())
   {
       fin.getline(str,100);
       count++;
   }
   cout<<"Number of lines in the file is: "<<count<<endl;
   fin.close();
}

int main() {
count_lines();
find_column();
return 0;
}

Output :

Number of lines in the file is 21
Column count 9                                                                                                                

                                                                                            

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
We wish to determine the impact of Specification Buying, X11, on Satisfaction Level, X10. To do...
We wish to determine the impact of Specification Buying, X11, on Satisfaction Level, X10. To do so we will split the Hatco data file into two separate data sets based on the Specification Buying, X11. This variable has two categories: 1=employs total value analysis approach, evaluating each purchase separately; 0 = use of specification buying. Sort the entire Hatco data set based on Specification Buying. This will create two separate groups of records. Those records with X11 = 0 and...
Use the data in Bank Dataset to answer this question. Construct a 95% confidence interval for...
Use the data in Bank Dataset to answer this question. Construct a 95% confidence interval for the mean increase in deposits. Note that the population standard deviation σ is not known in this case. Instead the sample standard deviation s should be calculated from the sample and the t distribution should be used. 2. What is the margin of error at the 95% confidence level? Bank Dataset of Increase in deposits. Mean is 4. Sample size is 152 customers. 4.3...
The following data represent petal lengths (in cm) for independent random samples of two species of...
The following data represent petal lengths (in cm) for independent random samples of two species of Iris. Petal length (in cm) of Iris virginica: x1; n1 = 35 5.1 5.5 6.2 6.1 5.1 5.5 5.3 5.5 6.9 5.0 4.9 6.0 4.8 6.1 5.6 5.1 5.6 4.8 5.4 5.1 5.1 5.9 5.2 5.7 5.4 4.5 6.4 5.3 5.5 6.7 5.7 4.9 4.8 5.8 5.1 Petal length (in cm) of Iris setosa: x2; n2 = 38 1.4 1.6 1.4 1.5 1.5 1.6...
Data shows the times for carrying out a blood test at Rivervalley Labs Using Excel Plot...
Data shows the times for carrying out a blood test at Rivervalley Labs Using Excel Plot a histogram of the data. What type of distribution does the data appear to follow? Construct and interpret the 95% confidence interval for the population mean time for carrying out a blood test. Assume that the population standard deviation is unknown. Times for blood tests (minutes) 2.5 4.9 3.6 4.3 1.9 3.4 3.2 4.0 3.1 3.6 3.9 4.4 3.9 3.1 2.7 3.5 3.6 3.7...
The following data represent petal lengths (in cm) for independent random samples of two species of...
The following data represent petal lengths (in cm) for independent random samples of two species of Iris. Petal length (in cm) of Iris virginica: x1; n1 = 35 5.0 5.7 6.2 6.1 5.1 5.5 5.3 5.5 6.9 5.0 4.9 6.0 4.8 6.1 5.6 5.1 5.6 4.8 5.4 5.1 5.1 5.9 5.2 5.7 5.4 4.5 6.4 5.3 5.5 6.7 5.7 4.9 4.8 5.8 5.2 Petal length (in cm) of Iris setosa: x2; n2 = 38 1.6 1.6 1.4 1.5 1.5 1.6...
The following data represent petal lengths (in cm) for independent random samples of two species of...
The following data represent petal lengths (in cm) for independent random samples of two species of Iris. Petal length (in cm) of Iris virginica: x1; n1 = 35 5.3 5.9 6.5 6.1 5.1 5.5 5.3 5.5 6.9 5.0 4.9 6.0 4.8 6.1 5.6 5.1 5.6 4.8 5.4 5.1 5.1 5.9 5.2 5.7 5.4 4.5 6.4 5.3 5.5 6.7 5.7 4.9 4.8 5.7 5.2 Petal length (in cm) of Iris setosa: x2; n2 = 38 1.6 1.9 1.4 1.5 1.5 1.6...
SHOW ALL WORK. DO NOT USE SOFTWARE TO GENERATE ANSWERS. Calculate the R-chart and X-bar chart...
SHOW ALL WORK. DO NOT USE SOFTWARE TO GENERATE ANSWERS. Calculate the R-chart and X-bar chart limits for the data given below. Day A B C D 1 7.2 8.4 7.9 4.9 2 5.6 8.7 3.3 4.2 3 5.5 7.3 3.2 6.0 4 4.4 8.0 5.4 7.4 5 9.7 4.6 4.8 5.8 6 8.3 8.9 9.1 6.2 7 4.7 6.6 5.3 5.8 8 8.8 5.5 8.4 6.9 9 5.7 4.7 4.1 4.6 10 3.7 4.0 3.0 5.2 11 2.6 3.9...
1. The following data represent petal lengths (in cm) for independent random samples of two species...
1. The following data represent petal lengths (in cm) for independent random samples of two species of Iris. Petal length (in cm) of Iris virginica: x1; n1 = 35 5.1 5.9 6.1 6.1 5.1 5.5 5.3 5.5 6.9 5.0 4.9 6.0 4.8 6.1 5.6 5.1 5.6 4.8 5.4 5.1 5.1 5.9 5.2 5.7 5.4 4.5 6.4 5.3 5.5 6.7 5.7 4.9 4.8 5.9 5.1 Petal length (in cm) of Iris setosa: x2; n2 = 38 1.5 1.9 1.4 1.5 1.5...
A sociologist claims that children spent more time watching television in 1981 than children do today....
A sociologist claims that children spent more time watching television in 1981 than children do today. A study was conducted in 1981 to find the time that children watched television on weekdays. Recently, a similar study was conducted. The results of these studies (in hours per weekday) are shown below. Assume the population standard deviation is 0.7 for 1981 and 0.7 for today. At α=0.05, can you support the sociologist's claim? Complete parts (a) through (d) below. 1981 3.2 1.4...
Build a stem-and-leaf plot for these measurements 3.1 4.9 2.8 3.6 2.5 4.5 3.5 3.7 4.1...
Build a stem-and-leaf plot for these measurements 3.1 4.9 2.8 3.6 2.5 4.5 3.5 3.7 4.1 4.9 2.9 2.1 3.5 4.0 3.7 2.7 4.0 4.4 3.7 4.2 3.8 6.2 2.5 2.9 2.8 5.1 1.8 5.6 2.2 3.4 2.5 3.6 5.1 4.8 1.6 3.6 6.1 4.7 3.9 3.9 4.3 5.7 3.7 4.6 4.0 5.6 4.9 4.2 3.1 3.9 A. Describe the form of data distribution. Do you notice any unusual results? B. Use the stem-and-leaf plot to find the minimum observation....