Home  |  Forums  |  914 Info  |  Blogs
 
914World.com - The fastest growing online 914 community!
 
Porsche, and the Porsche crest are registered trademarks of Dr. Ing. h.c. F. Porsche AG. This site is not affiliated with Porsche in any way.
Its only purpose is to provide an online forum for car enthusiasts. All other trademarks are property of their respective owners.
 

Welcome Guest ( Log In | Register )

> OT - C++ question.
Jeff Krieger
post May 13 2003, 06:05 PM
Post #1


Unregistered









Does anyone know how to modify this small program that I wrote in C++ so that for every cout statement there is a statement that writes the exact same information to the file accelfig.txt? I use this program to generate acceleration values and write them to accelfig.txt and then I read these acceleration values into another program that I wrote that numerically integrates these figures to calculate 0 to 60 mph and 1/4 mile times, speed at the end of the 1/4 mile, maximum hp, 60 mph to 0 braking distance etc. I use the free C++ compiler from http://www.bloodshed.net/dev/devcpp.html .


//CalcAccl1

#include < iostream.h >
#include < stdio.h >

// This program calculates 30 seconds worth of acceleration values, assumed
// to be in ft/s^2, and writes them to the file accelfig.txt.

main()
{ FILE *fp;

int counter;

double acceleration = 0, time = 0;

fp = fopen("accelfig.txt", "w");

for (counter = 0; counter <= 1600; counter++)
{
acceleration = time + 10;
fprintf(fp, "%20.10f\n", acceleration);
cout << "\nThe acceleration at " << time << " seconds is " << acceleration << '\n';
time = time + 0.0025;
}

for (counter = 1601; counter <= 4800; counter++)
{
acceleration = 14;
fprintf(fp, "%20.10f\n", acceleration);
cout << "\nThe acceleration at " << time << " seconds is " << acceleration << '\n';
time = time + 0.0025;
}

for (counter = 4801; counter <= 12000; counter++)
{
acceleration = 62 - 4*time;
fprintf(fp, "%20.10f\n", acceleration);
cout << "\nThe acceleration at " << time << " seconds is " << acceleration << '\n';
time = time + 0.0025;
}


fclose(fp);
}
Go to the top of the page
+Quote Post

Posts in this topic
Jeff Krieger   OT - C++ question.   May 13 2003, 06:05 PM
SirAndy   here you go:   May 13 2003, 06:13 PM
Jeff Krieger   I get an error message when I try to open it with ...   May 13 2003, 06:16 PM
john rogers   I tried the code and it works fine as the data goe...   May 13 2003, 06:21 PM
SirAndy   all you need to do is to put this line in your cod...   May 13 2003, 06:22 PM
Brad Roberts   Went fine for me also.. Alfred... he wouldnt post...   May 13 2003, 06:23 PM
SirAndy  
  May 13 2003, 07:42 PM
krk  
  May 13 2003, 07:43 PM
krk   So the <>'s appear in quoted text to me, but n...   May 13 2003, 07:44 PM
SirAndy  
  May 13 2003, 10:16 PM
Jeff Krieger  


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

- Lo-Fi Version Time is now: 12th June 2024 - 02:52 AM