C++ prog

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2006
Posts: 5
Reputation: Arvinth is an unknown quantity at this point 
Solved Threads: 0
Arvinth Arvinth is offline Offline
Newbie Poster

C++ prog

 
0
  #1
Mar 7th, 2006
Hi

My problem reqs a simulation code ( *.exe), which shd read the inputs from a file ( *.in) and after calculations , write the results to an output file ( *.out) .The names of the input and output files are hardcoded.

I shd be able to execute my sim code in batch mode and generate the output file. All this in C++.

Cld u please help me?

Thanks
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,692
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 267
Lerner Lerner is online now Online
Posting Virtuoso

Re: C++ prog

 
0
  #2
Mar 7th, 2006
You will probably get more help if you are more specific in what your question is and show effort of having worked on the problem yourself.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 5
Reputation: Arvinth is an unknown quantity at this point 
Solved Threads: 0
Arvinth Arvinth is offline Offline
Newbie Poster

Re: C++ prog

 
0
  #3
Mar 7th, 2006
Alright,
I do not have problems with coding or the algo.
What I have to do is integrate the .exe with another software (isight), and this .exe shd read from a .in and generate a .out. I shd also be able to run this in batch mode.

For instance,
I have 2 inputs ... length and width in .in file

The .exe calculates the area and generates the output to a .out file

I'll have to integrate all three to isight and run an optimisation process, which I can manage on my own

I need help with the way to go abt reading from a .in file in a .c sim code and generate output to a .out file.

Just the procedure will be of great help or any links if possible.

Donno if I am in the right place

Tell me what kinda code you'll require... file handling is one way I cannot go abt doing this. Figured that much.

Thanks neways
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,052
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: C++ prog

 
2
  #4
Mar 7th, 2006
shd? abt? What do these acronyms stand for???
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,468
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1477
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: C++ prog

 
0
  #5
Mar 7th, 2006
>>file handling is one way I cannot go abt doing this

The only other way I know of is to redirect the input and output on the command line.
  1. c:> myprogram < infile.in > outfile.out
That will redirect the file's contents to stdin just as if you typed the information on the keyboard, and redirect stdout to a file instead of displaying it on a console screen.

But I don't know why you can't just use FILE and associated C file handline functions to read the input file and write the output file.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 5
Reputation: Arvinth is an unknown quantity at this point 
Solved Threads: 0
Arvinth Arvinth is offline Offline
Newbie Poster

Re: C++ prog

 
0
  #6
Mar 8th, 2006
Originally Posted by Rashakil Fol
shd? abt? What do these acronyms stand for???
"shd" is should

And
"abt" is about
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 5
Reputation: Arvinth is an unknown quantity at this point 
Solved Threads: 0
Arvinth Arvinth is offline Offline
Newbie Poster

Re: C++ prog

 
0
  #7
Mar 8th, 2006
Thanks a bunch.

What I mean by running in batch mode...
At the prompt, if my file name is test.exe , on typing the file name, the output file should be generated.
Now, test.exe is created after I run my test.c file.

Is file handline fns the only way to do this?
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 5
Reputation: Arvinth is an unknown quantity at this point 
Solved Threads: 0
Arvinth Arvinth is offline Offline
Newbie Poster

Re: C++ prog

 
0
  #8
Mar 8th, 2006
Here is a code:

#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
void main()
{
char ch1[50]="The length is : ";char ch2[50]="The width is : ";
float l=8.0; float w=6.0;float a,p;
char ch3[50]="The area is : ";char ch4[50]="The perimeter is : ";
float temp1,temp2;

ofstream outfile("newone.in");

outfile<<ch1<<l<<endl<<ch2<<w;
outfile.close();
ifstream infile("newone.in");
ofstream outf("newone.out");
infile.getline(ch1,50);
infile>>l;temp1=l;
infile.getline(ch2,50);
infile>>w;temp2=w;

a=l*w;
p=2*(l+w);
outf<<ch3<<a<<endl;
outf<<ch4<<p<<endl;
infile.close();outf.close();

}



What will a .exe of this do every time I run it?

In another software, I am giving it permission to replace the values of l and w in my input file with its own randomly generated values, calculate new area and perimeter, and write it in the output file... this runs in a loop until I optimise my area. Now, after it replaces the values in the input file, it uses the .exe to do the new calculations and carry on for every run.

Doubts:
When, it runs the .exe, does it re-initialise the values of l and w?
What does running the .exe do?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC