#I made a code, but im not sure if i did it right??

4 messages · Page 1 of 1 (latest)

cold elk
#

Attached Files: File Mech_Eng_Cos_Num_Projs.txt

Project 2 - Frequency Distribution

Using the data file attached - calculate the following using arrays:

  1. fequency distribution
  2. cummulative frequency distribution
  3. relative frequency distribution
  4. cummulative relative frequency distribution

Use the following bins to determiine the frequency distribution:
Bins
10 Num of projs less or equal to 10
20 Num of projs 11 - 20
30 Num of projs 21 - 30
40 Num of projs 31 - 40
50 Num of projs 41 - 50
60 Num of projs 51 - 60
70 Num of projs 61 - 70
80 Num of projs 71 - 80
90 Num of projs 81 - 90
100 Num of projs 91 - 100

onyx horizonBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

cold elk
#
#include <string>
#include <fstream>
#include <iomanip>
#include <cstring>

using namespace std;

struct Distribution
{
    double frequency_distribution;
    double cummulative_frequency_distribution;
    double relative_frequency_distribution;
    double cummulative_relative_frequency_distribution;
};


int main()
{
    ifstream inFile;
    ofstream outFile;
    inFile.open("Mech_Eng_Cos_Num_Projs.txt");
    outFile.open("Mech_Eng_Cos_Num_Projs.Results");
    outFile << fixed << showpoint << setprecision(2);

    Distribution bins[10] = {};

    int record_bins;
    int total_bins = 0;

    while (inFile >> record_bins)
    {
        total_bins++;

        cout << record_bins << endl;

        if (record_bins == 0)
            bins[0].frequency_distribution += 1.0;
        else
            bins[(record_bins - 1) / 10].frequency_distribution += 1.0;
    }

    int cummulative_total = 0;

    for (int index = 0; index < 10; index++)
    {
        cummulative_total += bins[index].frequency_distribution;
        bins[index].cummulative_frequency_distribution = cummulative_total;
        bins[index].relative_frequency_distribution = bins[index].frequency_distribution / total_bins;
        bins[index].cummulative_relative_frequency_distribution = cummulative_total / total_bins;

        int lower, upper;
        if (index == 0)
        {
            lower = 0;
            upper = 10;
        }
        else
        {
            lower = index * 10 + 1;
            upper = (index + 1) * 10;
        }```
#
        cout << "\n This is the cummulative frequency distribution using arrays from bins " << lower << "-" << upper << ": " << bins[index].cummulative_frequency_distribution << "\n";
        cout << "\n This is the relative frequency distribution using arrays " << lower << "-" << upper << ": " << bins[index].relative_frequency_distribution << "\n";
        cout << "\n This is the cummulative relative frequency distribution ussing arrays " << lower << "-" << upper << ": " << bins[index].cummulative_relative_frequency_distribution << "\n";
    }
}```