int main()
{
	Stats test;
	Stats runners;
	
	
	double value;

	do
	{
		cout << "Enter a value to store: ";
		cin >> value;

	} while (test.storeValue(value));
	cout << "Total: " << test.total() << endl;
	cout << "Average: " << test.average() << endl;
	cout << "The lowest value: " << test.lowest() << endl;
	cout << "The highest value: " << test.highest() << endl;



	cout << endl << endl;


	// Second Requirement
	getData(runners);
	createReport(runners);


	return 0;
}
void createReport(Stats runners)
{
	cout << endl << "Tulsa Tigers Track Team" << endl << endl;
	cout << "Average 100 yard-dash time: " << runners.average() << " seconds" << endl;
	cout << "Slowest runner: " << runners.lowest() << " seconds" << endl;
	cout << "Fastest runner: " << runners.highest() << " seconds" << endl;
}
Example #3
0
Stats WordsGenerator::studySentence(std::string p_str, unsigned p_iter, std::ostream& out) {
    Stats results;
    clock_t start, end;
    std::vector<double> tirages;
    out << "////////////////////////////////////////////////////////////////" << std::endl << std::endl;
    out << "\tSTARTING OF STUDY OF:" << std::endl;
    out << "\t\t" << p_str << std::endl << std::endl;
    out << "////////////////////////////////////////////////////////////////" << std::endl;
    out << "----------------------------------------------------------------" << std::endl;

    time(&start);    // temps de debut

    for(unsigned i = 0 ; i < p_iter ; ++i) {        // calcul des echantillons
        out << "Round " << i+1 << ":" << std::endl;
        tirages.push_back(this->expectWord(p_str.c_str(), out));
        out << "----------------------------------------------------------------" << std::endl;
    }

    time(&end);      // temps de fin

    results.setAverage(tirages);
    results.setVariance(tirages, results.average());
    results.setRadius(results.variance(),tirages.size());
    results.setTime(difftime(end,start));

    out << "////////////////////////////////////////////////////////////////" << std::endl;
    out << "\tRESULTS:" << std::endl;
    out << "\t +\tFrequency:\t" << 1.0/(unsigned long long)results.average() << std::endl;
    out << "\t +\tAverage:\t" << (unsigned long long)results.average() << std::endl;
    out << "\t +\tDrawings:\t" << (unsigned long long)results.total() << std::endl;
    out << "\t +\tStd deviation:\t" << (unsigned long long)sqrt((unsigned long long)results.variance()) << std::endl;
    out << "\t +\tConfidence int:\t[ " << (unsigned long long)std::max(0.,(results.average()-results.radius())) << " ; " << (unsigned long long)(results.average()+results.radius()) << " ]" << std::endl;
    out << "\t +\tExecution time:\t" << results.time() << " s" << std::endl;
    out << "\t +\tUnit exe. time:\t" << results.time()/(double)tirages.size() << " s" << std::endl;
    out << "////////////////////////////////////////////////////////////////" << std::endl;

    return results;
}
void IonStatsListener::finished() {
    if (has_finished_)
        return;

    std::string statsFileEnding = "_stats.csv";
    std::string posFileEnding = "_pos.csv";

    double vel_scale = trap_params_.length_scale/trap_params_.time_scale;
    double x, y, z, rotated_x, rotated_y;
    double sqrt2 = 1.414213562;
    DataWriter writer(",");
    typedef Ion_ptr_vector::const_iterator ion_itr;
    std::list<double> rowdata;
    std::string name;

    // Write the header for each file
      std::string statsHeader="avg(r), var(r), avg(z), var(z), avg(KE), var(KE)";
      std::string posHeader="x, y, z, vx, vy, vz";
    for (auto& type : cloud_params_.ion_type_list) {
      name = base_path_ + type.name + statsFileEnding;
      writer.writeComment(name, statsHeader);
      name = base_path_ + type.name + posFileEnding;
      writer.writeComment(name, posHeader);
    }

    for (auto ion : ions_->get_ions()) {
        // Write the final position and velocity for each ion.
        name = base_path_ + ion->name() + posFileEnding;
        rowdata.clear();
        // Scale reduced units to real-world units and rotate to align to
        // axes between rods (calculation has axes crossing rods.)
        x = (ion->get_pos())[0] * trap_params_.length_scale;
        y = (ion->get_pos())[1] * trap_params_.length_scale;
        z = (ion->get_pos())[2] * trap_params_.length_scale;
        rotated_x = (x+y)/sqrt2;
        rotated_y = (x-y)/sqrt2;
        rowdata.push_back(rotated_x);
        rowdata.push_back(rotated_y);
        rowdata.push_back(z);

        x = (ion->get_vel())[0] * vel_scale;
        y = (ion->get_vel())[1] * vel_scale;
        z = (ion->get_vel())[2] * vel_scale;
        rotated_x = (x+y)/sqrt2;
        rotated_y = (x-y)/sqrt2;
        rowdata.push_back(rotated_x);
        rowdata.push_back(rotated_y);
        rowdata.push_back(z);

        writer.writeRow(name, rowdata);

        // Write the average data for each ion.
        name = base_path_ + ion->name() + statsFileEnding;
        rowdata.clear();

        Stats<double> vel = (ion->get_velStats());
        Stats<Vector3D> pos = (ion->get_posStats());
        double mon2 = (ion->get_mass())/2;
        double avg_energy = (vel.average() * vel.average()) * (mon2 * trap_params_.energy_scale);
        double var_energy = (vel.variance()/vel.average()) * (avg_energy * 1.41);
        Vector3D avg_pos = pos.average() * trap_params_.length_scale;
        Vector3D var_pos = pos.variance() * trap_params_.length_scale;

        rowdata.push_back(avg_pos[0]);
        rowdata.push_back(var_pos[0]);
        rowdata.push_back(avg_pos[1]);
        rowdata.push_back(var_pos[1]);
        rowdata.push_back(avg_energy);
        rowdata.push_back(var_energy);

        writer.writeRow(name, rowdata);
    }
    has_finished_ = true;
    log_.debug("Finished IonStatsListener.");
}