Executable File

This is a discussion on Executable File within the C++ Programming forums, part of the General Programming Boards category; I have to run this program on Unix and all of the loops have to be timed. So to time ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    84

    Executable File

    I have to run this program on Unix and all of the loops have to be timed. So to time the program I have to have a executable file. How do I make this program into a executable file in C++?
    Code:
    #include< iostream >
    #include< iomanip >
    #include< ctime >
    #include< fstream >
    
    const int vSize = 6;
    using namespace std;
    
    
    
    int main()
    {
        
    	int vec[vSize]={300, 400, 500,600, 700, 800};
    
    	//Declare the clock variables
    	clock_t start,finish, start1, finish1, start2, finish2, start3, finish3,
    		start4, finish4, start5, finish5;
    //	clock_t startAll;
    
    	//Declare and initialize all the variables
        double duration, duration1, duration2, duration3, duration4, duration5=0;
    	
        //Declare the streams and the input and output files
    	
        ofstream outFile;
        ofstream outFile2;
    	
        outFile.open("output1.txt");
        outFile2.open("output2.txt");
    
    	outFile2<<"Chapter 2 Problem 7b Implement the code in the language"<<endl;
    		outFile2<<"of your choice, and give the running time for several values of N"<<endl<<endl;
    	
    int Sum=0;
    	
    	outFile2<<"For the for loop: for(i = 0; i < n; i++)"<<endl<<endl;
    
    	for (int iterationcountselector = 0; iterationcountselector < vSize; ++iterationcountselector)
    	{
    		start=clock();
    		for(int i =0; i < vec[iterationcountselector] ; i++)
    		{
    			Sum++;
    			outFile<< Sum<<endl;
    		}
    	
    		finish=clock();
    		duration=(double)(finish-start)/CLOCKS_PER_SEC;
    		outFile2<<"Total Time Duration for vector:"<<vec[iterationcountselector]<<" "<< duration<<" ms"<< endl;
    
    	}
    
    outFile2<<endl<<endl;
    ///////////////////////////////////////////////////////////////////////
    outFile2<<"For the loops:for(int i =0; i < vec[iterationcountselector]; i++)"<<endl;
    outFile2<<"                   for(int j = 0; j < vec[iterationcountselector]; j++)"<<endl<<endl;
    Sum=0;
    	for (iterationcountselector = 0; iterationcountselector < vSize; ++iterationcountselector)
    	{
    		
    	start1=clock();
    		for(int i =0; i < vec[iterationcountselector]; i++)
    		
    		{
    			for(int j = 0; j < vec[iterationcountselector]; j++)
    			
    			Sum++;
    			outFile<< Sum<<endl;
    			
    		}
    	
    
    		finish1=clock();
    		duration1=(double)(finish1-start1)/CLOCKS_PER_SEC;
    		outFile2<<"Total Time Duration for vector:"<<vec[iterationcountselector]<<" "<<duration1<<" ms"<< endl;
    	}
    outFile2<<endl<<endl;
    //////////////////////////////////////////////////////////////////////
    outFile2<<"For the loops:for(int i =0; i < vec[iterationcountselector]; i++)"<<endl;
    outFile2<<"                   for(int j = 0; j < vec[iterationcountselector] * vec[iterationcountselector]; j++)"<<endl<<endl;
    Sum=0;
    for (iterationcountselector = 0; iterationcountselector < vSize; ++iterationcountselector)
    	{
    		
    	start2=clock();
    		for(int i =0; i < vec[iterationcountselector]; i++)
    		{
    			for(int j = 0; j < vec[iterationcountselector] * vec[iterationcountselector]; j++)
    			Sum++;
    			outFile<< Sum<<endl;
    		}
    	
    
    		finish2=clock();
    		duration2=(double)(finish2-start2)/CLOCKS_PER_SEC;
    		outFile2<<"Total Time Duration for vector:"<<vec[iterationcountselector]<<" "<< duration2<<" ms"<< endl;
    	}
    outFile2<<endl<<endl;
    /////////////////////////////////////////////////////////////////////
    outFile2<<"For the loops:for(int i =0; i < vec[iterationcountselector]; i++)"<<endl;
    outFile2<<"                  for(int j = 0; j < i; j++)"<<endl<<endl;
    Sum=0;
    for (iterationcountselector = 0; iterationcountselector < vSize; ++iterationcountselector)
    	{
    		
    	start3=clock();
    		for(int i =0; i < vec[iterationcountselector]; i++)
    		{
    			for(int j = 0; j < i; j++)
    			Sum++;
    			outFile<< Sum<<endl;
    		}
    	
    
    		finish3=clock();
    		duration3=(double)(finish3-start3)/CLOCKS_PER_SEC;
    		outFile2<<"Total Time Duration for vector:"<<vec[iterationcountselector]<<" "<< duration3<<" ms"<< endl;
    	}
    outFile2<<endl<<endl;
    ////////////////////////////////////////////////////////////////////////
    outFile2<<"For the loops:for(int i =0; i < vec[iterationcountselector]; i++)"<<endl;
    outFile2<<"                 for(int j = 0; j < i; j++)"<<endl;
    outFile2<<"                     for(int k = 0; k < j; k++)"<<endl<<endl;
    Sum=0;
    for (iterationcountselector = 0; iterationcountselector < vSize; ++iterationcountselector)
    	{
    		
    	start4=clock();
    		for(int i =0; i < vec[iterationcountselector]; i++)
    		{
    			for(int j = 0; j < i; j++)
    				for(int k = 0; k < j; k++)
    			Sum++;
    			outFile<< Sum<<endl;
    		}
    	
    
    		finish4=clock();
    		duration4=(double)(finish4-start4)/CLOCKS_PER_SEC;
    		outFile2<<"Total Time Duration for vector:"<<vec[iterationcountselector]<<" "<< duration4<<" ms"<< endl;
    }
    outFile2<<endl<<endl;
    //////////////////////////////////////////////////////////////////////
    outFile2<<"For the loops:for(int i =0; i < vec[iterationcountselector]; i++)"<<endl;
    outFile2<<"                  for(int j = 1; j < i * i; j++)"<<endl;
    outFile2<<"                      if(j % i == 0)"<<endl;
    outFile2<<"                          for(int k = 0; k < j; k++)"<<endl<<endl;
    Sum=0;
    for (iterationcountselector = 0; iterationcountselector < vSize; ++iterationcountselector)
    	{
    		
    	start5=clock();
    		for(int i =0; i < vec[iterationcountselector]; i++)
    		{
    			for(int j = 1; j < i * i; j++)
    				if(j % i == 0)
    					for(int k = 0; k < j; k++)
    			Sum++;
    			outFile<< Sum<<endl;
    		}
    	
    
    		finish5=clock();
    		duration5=(double)(finish5-start5)/CLOCKS_PER_SEC;
    		outFile2<<"Total Time Duration for vector:"<<vec[iterationcountselector]<<" "<< duration5<<" ms"<< endl;
    	}
    outFile2<<endl<<endl;
    
    	return 0;
    }//end of main

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    126

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    84

    Reply

    I am using C++ 6.0 on windows 2000

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    84

    Reply

    C++ 6.0 is the only compiler I have..

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    126
    Home come you can't just put the source on a floppy and compile it on the UNIX box?

  6. #6
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Did you try it?

    Home come you can't just put the source on a floppy and compile it on the UNIX box?
    You can! If your code is ANSI standard C++ it is portable!

    Now, I didn't read your code, and I don't know the whole standard anyway, but you didn't use any weird headers!

    EDIT
    Oops... PorkyChop's post was actually an answer... not the question.

    Drew,
    Yeah you're gonna have to re-compile on a UNIX compiler. I'm not sure if the gnu compilers will cross-compile (compile for a different platform than they are running on), but I doubt it... and it could get tricky anyway.

    Cross compiling is OK if you are doing it every day... you have the right cross-compiler... and you know what the "tricks" are... and you can test the result. But, it's probably not worth doing once.

    As your post implies, an exe will ONLY run on a particular hardware platform and a particular OS. The exe file is in the machine language which is unique to the processor (actually the processor series). And, the machine language is coded for one operating system.
    Last edited by DougDbug; 08-29-2003 at 06:28 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 09:47 AM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. using MAKE with makefile to create executable file
    By sballew in forum C Programming
    Replies: 1
    Last Post: 11-19-2001, 11:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21