lundi 23 janvier 2017

C ++ Program Exits Before Completing Full Code

My code Looks like this

#include "Polynomial.h"
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
#include <chrono>
#include <iomanip>


using namespace std;

void printTimeNaive(Polynomial naive){
    using namespace std::chrono;

    auto start = std::chrono::high_resolution_clock::now();
    double q = naive.naiveEval(3);
    auto elapsed = std::chrono::high_resolution_clock::now() - start;
    auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed).count();
    cout<<duration;
    return;

}

void printTimeHorner(Polynomial horner){
    using namespace std::chrono;

    auto start = high_resolution_clock::now();
    double q = horner.hornerEval(3);
    auto elapsed = high_resolution_clock::now() - start;
    auto duration = duration_cast<std::chrono::nanoseconds>(elapsed).count();
    cout<<duration;
    return;
 }

int main(){

double a[7] = {4, 5, 0, 2, 3, 5, -1};
Polynomial f(a,7);
double x = 3;
string output = f.str();
cout << "f := [" << output << "]"<<endl;
cout<<"deg f(x) := "<<f.degree()<<endl;
cout<<"Using Horner's method, f("<<x<<") = "<<f.hornerEval(x)<<endl;
cout<<"Using naive method, f("<<x<<") = "<<f.naiveEval(x)<<endl;
cout<<endl;

double b[7] = {12.5, 0, 0, -1, 7.2, -9.5};
Polynomial g(b,6);
x = -7.25;
output = g.str();
cout << "g := [" << output << "]"<<endl;
cout<<"deg g(x) := "<<g.degree()<<endl;
cout<<"Using Horner's method, f("<<x<<") = "<<g.hornerEval(x)<<endl;
cout<<"Using naive method, f("<<x<<") = "<<g.naiveEval(x)<<endl;
cout<<endl;

cout<<"Empirical Analysis of Naive vs Horner’s Methods"<<endl;
cout<<"on 10 Polynomials with Random Coefficients"<<endl;
cout <<"================================================"<<endl;
cout<<"Degree     Naive Time (ns)    Horner’s Time(ns)"<<endl;
cout<<"------------------------------------------------"<<endl;

double c[1000];
for (int i = 0; i < 1000; i++){
c[i] = rand() % 6;}
Polynomial p(c, 1000);
cout<<p.degree()<<"       ";
printTimeNaive(p);
cout<<"      ";
printTimeHorner(p); 

The program succesfully gets the first execution time but then gives me the errror "RUN FAILED (exit value 34,304, total time: 108ms."

My original thought would be some sort of memory issue or to do with void functions but after like 3 hours of tinkering nothing is doing.

Any help would be appreciated. I am coding using C++11 and NetBeans. Thanks!

Aucun commentaire:

Enregistrer un commentaire