Can some one fix my code so that the output result same as below?
BAR PLOT OF CYLINDER PRESSURE -VS- TIME
pressure is on horizontal axis - units are psi
time is on vertical axis - units are msec
0.0
20.0
40.0
60.0
80.0
100.0 120.0
+---------+---------+---------+---------+---------+---------+
0.0|*************************
1.5|*********************************
3.0|*****************************************
4.4|**************************************************
05.9|*********************************************
7.4|********************************
8.9|***********************
10.4|*****************
11.9|**************
13.3|*************
14.8|************
16.3|*********
17.8|*******
19.3|******
20.7|******
22.2|*******
23.7|*******
..........
=====================
her is my code
//#include"stdafx.h"
#include
#include
#include
#include
#include
#include
using namespace std;
const int SIZE =100;
class enginePerformance
{
public:
enginePerformance()
{TrapA =0;}
void retreiveData();
void setMaxPressure();
void setMinPressure();
void setAveragePressure();
void setCompressionRatio();
void setDeltaA();
void setPower();
void setbarPlot();
void outputReport ();
string getDataTitle()
{return dataTitle;}
string getEngineID()
{return engineID;}
string getDate()
{return date;}
double getRPM()
{return RPM;}
double getCompRatio()
{return compressionRatio;}
double getMaxPressure()
{return averagePressure;}
double getMinPressure()
{return averagePressure;}
double getAveragePressure()
{return averagePressure;}
double getTrapA()
{return TrapA;}
double getPower();
private:
string dataTitle;
string engineID;
string date;
double RPM;
double area;
double pressure[SIZE];
double volume[SIZE];
int dataCount;
double compressionRatio;
double maxPressure;
double minPressure;
double averagePressure;
double maxVolume;
double minVolume;
double TrapA;
double Power;
ifstream inputData;
ofstream report;
void openInputFile ();
void closeInputFile ();
void openOutputFile ();
void closeOutputFile ()
{report.close();}
void clearText ();
};
int main()
{
enginePerformance e;
e.retreiveData();
e.setMaxPressure();
e.setMinPressure();
e.setAveragePressure();
e.setCompressionRatio();
e.setDeltaA();
e.setPower();
/*e.setbarPlot();*/
e.outputReport();
return 0;
}
void enginePerformance::retreiveData()
{
dataCount = 0;
openInputFile();
getline(inputData, dataTitle);
getline(inputData,engineID);
getline(inputData,date);
inputData >>RPM;
//cout << RPM;
for (int i=0; i< 4; i++)
clearText();
while (!inputData.eof())
{
inputData >> pressure[dataCount];
inputData >> volume [dataCount];
//cout << pressure [ dataCount ] << " " << volume [ dataCount ] << endl;
dataCount++;
}
dataCount --;
}
void enginePerformance::openInputFile()
{
string filename;
cout <<"please name file."<
cin >>filename;
inputData.open("surface.txt");
if ( inputData.fail())
{
cout <<"Input file is missing"<
exit(1);
}
return;
}
void enginePerformance::clearText()
{
string garbage;
getline (inputData,garbage);
return;
}
void enginePerformance::setMaxPressure()
{
for(int j=0;j < dataCount;j++)
{
if (j == 0)
maxPressure = pressure[j];
if(pressure[j] >maxPressure)
maxPressure =pressure[j];
}
//cout << maxPressure;
return;
}
void enginePerformance::setMinPressure()
{
for(int j=0; j
{
if (j == 0)
{
minPressure = pressure[j];
//cout << minPressure << endl;
}
if(pressure[j]
{
minPressure = pressure[j];
//cout << minPressure << " " << j << endl;
}
}
return;
}
void enginePerformance::setAveragePressure()
{
double sum = 0;
for (int j=1; j
{
if (j ==0 )
sum =pressure[j];
else
sum =sum + pressure[j];
}
averagePressure =sum / dataCount;
return;
}
void enginePerformance::setCompressionRatio()
{
double maxVolume =0, minVolume =0;
for (int i=0; i < dataCount; i++)
{
if (i == 0)
maxVolume =minVolume = volume[i];
if (volume[i]>maxVolume)
maxVolume =volume[i];
if (volume[i]
minVolume =volume[i];
}
compressionRatio = maxVolume / minVolume;
}
void enginePerformance::setDeltaA()
{
area =0; //TrapA = 0.0;
for(int j=0; j<(dataCount-1); j++)
{
//cout << pressure [j] << " " << volume [j] << endl;
area +=0.5*(pressure[j]+pressure[j+1])*((volume [j+1]-volume[j]));
//area += TrapA;
cout<
}
//inputdataTrapA /=dataCount;
}
void enginePerformance::setPower()
{
cout << area << endl;
Power = area * 0.0254*4.45*RPM/120;
//power =work done/time interval =area under p.v area/time for 1 cycle
//time for 1 cycle =1/RPM*2
}
void enginePerformance::setbarPlot()
{
double scaleFactor;
cout << "What is the scale factor?" << endl;
cin >> scaleFactor;
int asterisks;
cout <<0.0<<""<<20.0<<""<<40.0<<""<
cout <<"+-------+---------"<
for ( int i = 0; i < dataCount; i ++ )
{
asterisks = pressure [ i ] * scaleFactor;
cout <
for ( int j = 0; j < asterisks; j ++ )
cout << "*";
cout << endl;
}
}
void enginePerformance::openOutputFile()
{
string filename;
cout<<"Please name output file." <
cin>>filename;
report.open (filename);
return;
}
void enginePerformance::outputReport()
{
openOutputFile ();
report << getDataTitle() <<"report"<
report <<"Engine ID:" << getEngineID() <
report <<"Analysis Date:" << getDate() <
report <<"Engine Performance:" <
report <<"Compression Ratio :" <
report <<"Pressure"<
report <<"Max"<
report <<"Min"<
report <<"Power"<
closeOutputFile();
return;
}
==================================inputdata below
Engine Analysis
Megatech Mark III Model TE1 Serial Number 155
January 10, 2010
1800. Engine RPM
Cylinder Pressure (psi) , Cylinder Volume (in3)
49 1.52
65 1.38
87 1.46
122 1.56
98 1.72
64 2.16
45 2.71
34 3.33
28.5 3.94
25 4.5
23 4.95
17 5.27
13 5.46
12 5.49
12.5 5.49
13 5.36
14.5 5.08
15 4.68
15.5 4.15
15.5 3.56
16 2.90
16 2.33
16 1.85
16 1.52
16 1.38
15 1.44
15 1.71
13.5 2.17
13 2.73
12 3.34
12 3.94
12 4.50
12.5 4.95
13 5.27
14 5.46
15 5.50
16 5.36
16.5 5.08
19 4.67
22 4.15
25 3.56
32 2.90
37 2.33
44 1.85
47 1.52
49 1.52
#include <iostream>
#include <iomanip>
using namespace std;
void barPlot(double arrayToPlot[], int numberInArray, double
yScale)
{
//For two points in pressure one character is
used
//Every 10th point is denoted by + in the
pressure axis
int i;
double j, time = 0.0, temp = 0.0, max =
0.0;
for(i = 0; i < numberInArray; i++){
if ( arrayToPlot[i] >
max)
max = arrayToPlot[i];
}
//Finding maximum limit of pressure axis
while(true)
{
temp += 10.0;
if (temp >=
max)
break;
}
temp += 10.0;
//Ploting
cout<<"\n";
i = 0;
//forming pressure axis
for(j = 0; j <= temp/2; j++){
if( (int)j % 10 ==
0){
if(j < 40)
i++;
cout<<setprecision(1)<<fixed<<2 * j;//Formatting
string, setprecision() is used to define no. of 0's after
decimal
}
else if( (int)j % 10
> i )
cout<<" ";
}
cout<<"\n ";
for(j = 0.0; j <= temp/2; j++){
if( (int)j % 10 ==
0)
cout<<"+";
else
cout<<"-";
}
for(i = 0; i < numberInArray; i++)
{
//printing time
axis
cout<<"\n"<<time<<"|";
time += yScale;
//plotting data
for(j = 1.0; j <=
arrayToPlot[i]/2; j++)
{
cout<<"*";
}
}
}
int main()
{
int numberInArray, i;
cout<<"\nEnter number of values: ";
cin>>numberInArray;
double arrayToPlot[numberInArray], yScale;
cout<<"\nScale of y-axis: ";
cin>>yScale;
cout<<"\nEnter pressure values
sequentially: \n";
for(i = 0; i < numberInArray; i++)
cin>>arrayToPlot[i];
barPlot(arrayToPlot, numberInArray,
yScale);
cout<<"\n";
return 0;
}
Output:
Can some one fix my code so that the output result same as below? BAR PLOT...
Fix my code, if I the song or the artist name is not on the vector, I want to user re-enter the correct song or artist name in the list, so no bug found in the program #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; class musicList{ private: vector<string> songName; vector<string> artistName; public: void addSong(string sName, string aName){ songName.push_back(sName); artistName.push_back(aName); } void deleteSongName(string sName){ vector<string>::iterator result = find(songName.begin(), songName.end(), sName); if (result == songName.end()){ cout << "The...
My code doesn't output correctly using a .txt file. How do I clean this up so it posts correctly? ----------------------------------------------- CODE ---------------------------------------------- #include <iostream> #include <string> #include <fstream> #include <iomanip> #include <fstream> using namespace std; struct Customer { int accountNumber; string customerFullName; string customerEmail; double accountBalance; }; void sortDesc(Customer* customerArray, int size); void print(Customer customerArray[], int size); void print(Customer customerArray[], int size) { cout << fixed << setprecision(2); for (int i = 0; i...
Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem to get my code to work. The output should have the AVEPPG from highest to lowest (sorted by bubbesort). The output of my code is messed up. Please help me, thanks. Here's the input.txt: Mary 15 10.5 Joseph 32 6.2 Jack 72 8.1 Vince 83 4.2 Elizabeth 41 7.5 The output should be: NAME UNIFORM# AVEPPG Mary 15 10.50 Jack 72 8.10 Elizabeth 41 7.50 Joseph 32 6.20 Vince 83 4.20 My Code: #include <iostream>...
Please help fix my code C++, I get 2 errors when running. The code should be able to open this file: labdata.txt Pallet PAG PAG45982IB 737 4978 OAK Container AYF AYF23409AA 737 2209 LAS Container AAA AAA89023DL 737 5932 DFW Here is my code: #include <iostream> #include <string> #include <fstream> #include <vector> #include <cstdlib> #include <iomanip> using namespace std; const int MAXLOAD737 = 46000; const int MAXLOAD767 = 116000; class Cargo { protected: string uldtype; string abbreviation; string uldid; int...
C++ how can I fix these errors this is my code main.cpp #include "SpecialArray.h" #include <iostream> #include <fstream> #include <string> using namespace std; int measureElementsPerLine(ifstream& inFile) { // Add your code here. string line; getline(inFile, line); int sp = 0; for (int i = 0; i < line.size(); i++) { if (line[i] == ' ') sp++; } sp++; return sp; } int measureLines(ifstream& inFile) { // Add your code here. string line; int n = 0; while (!inFile.eof()) { getline(inFile,...
Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; //function void displaymenu1(); int main ( int argc, char** argv ) { string filename; string character; string enter; int menu1=4; char repeat; // = 'Y' / 'N'; string fname; string fName; string lname; string Lname; string number; string Number; string ch; string Displayall; string line; string search; string found; string document[1000][6]; ifstream infile; char s[1000];...
Hello, I have written a code that I now need to make changes so that arrays are transferred to the functions as pointer variable. Below is my code I already have. #include<iostream> #include<string> #include<iomanip> using namespace std; //functions prototypes void getData(string id[], int correct[], int NUM_STUDENT); void calculate(int correct[], int incorrect[], int score[], int NUM_STUDENT); double average(int score[], int NUM_STUDENT); void Display(string id[], int correct[], int incorrect[], int score[], double average, int NUM_STUDENT); int findHigh(string id[], int score[], int NUM_STUDENT);...
I am having trouble trying to output my file Lab13.txt. It will say that everything is correct but won't output what is in the file. Please Help Write a program that will input data from the file Lab13.txt(downloadable file); a name, telephone number, and email address. Store the data in a simple local array to the main module, then sort the array by the names. You should have several functions that pass data by reference. Hint: make your array large...
Hi there! I need to fix the errors that this code is giving me and also I neet to make it look better. thank you! #include <iostream> #include <windows.h> #include <ctime> #include <cstdio> #include <fstream> // file stream #include <string> #include <cstring> using namespace std; const int N=10000; int *freq =new int [N]; int *duration=new int [N]; char const*filename="filename.txt"; int songLength(140); char MENU(); // SHOWS USER CHOICE void execute(const char command); void About(); void Save( int freq[],int duration[],int songLength); void...
fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str; while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title); getline(inFile, books[size].Author); getline(inFile, books[size].publisher); getline(inFile,...