User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 425,902 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,938 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2459 | Replies: 14
Reply
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 2
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: Trying to use pointers

  #11  
May 18th, 2005
Dude, you're gonna have to give us something complete. A full program that doesn't work, and a chunk of the file that you're using so that we can actually test this and answer your question completely without all the back and forth.
Reply With Quote  
Join Date: Apr 2005
Posts: 32
Reputation: sinrtb is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
sinrtb sinrtb is offline Offline
Light Poster

Re: Trying to use pointers

  #12  
May 18th, 2005
Originally Posted by Dogtree
Dude, you're gonna have to give us something complete. A full program that doesn't work, and a chunk of the file that you're using so that we can actually test this and answer your question completely without all the back and forth.
okies sorry i was hoping it was a quick and easy answer

MAIN :
#include "pert.h"
#include <iomanip>
#include <iostream>
#include <fstream>
#include <cstdio> 
#include <cerrno>
#include <cstring>


using namespace std;

int main(int argc, char *argv[])//argc is the argument coutn argv is the the test.txt
{


    int n,              // Number of activities.
       nn;  // Largest node number.
//Activity p[51];
//Activity **p =  new Activity*[51]; seems to work
Activity *p =  new Activity [51];
  
// Activity *p =  new Activity [51];  
  float expt[51];
  float stdd[51],   
        bucket[51],
        es[51],   
        ef[51],  
        ls[51], 
        lf[51],
        totsl[51],
		rem[1],//so that it is able to be changed
        totmax[1];//see rem
  char  ask[51];
  char job[21];
  int i;
  ifstream pert;
  
cout<< "test1" << endl;
totmax[0] = 0.0;
  // Correct number of arguments?
  if ( argc != 2 ) {
    cerr << "usage: " << argv[0] << " filename\n";
    return 1;
  }

cout<< "test2" << endl;
  // Open file name given on command line.
  pert.open(argv[1]);
  if ( pert.fail() ) {
    perror(argv[0]);
    return 2;
  }


	cout<< "test3" << endl;
  // Read the number of activities (n) and highest node number (nn)
  //pert >> n >> nn;
	if ( pert.eof() ) 
	{
		cerr << argv[1] << ": is empty\n";
		return 3;
	}

	cout<< "test4" << endl;

 // Read/process activity data
	//for ( i = 0; i < 9; i++)
		//p[i] = new Activity;
		cout<< "test4.5" << endl;
	for (i = 1; i <= n; ++i ) 
	{
		cout<< "test5" << endl;
		if ((p+i)->i == NULL)
			{
				cout<< "test6" << endl;
				break;
			}
		cout<< "test7" << endl;
		// Read the activity records.
		pert >> (p+i)->i >> (p+i)->j >> (p+i)->pt 
			 >> (p+i)->prt >> (p+i)->ot;
		pert.getline((p+i)->desc,21);
		cout << (p+i)->i << endl;
	}
 
	pert.close();
	int x;
	n = i -1;

for ( nn = 0 ,  x = 1; x < i ; ++x)
{
	if ((p+i)->i > nn)
		nn = (p+i)->i;
}
for ( x = 1 ; x < i ; ++x)
{
	 if ((p+i)->j > nn)
		 nn = (p+i)->j;
}
nn = 9;
n =11;
cout << (p+i)->ot << endl;//not printing anything
/***********************************************************************************************
							BEGIN FUNCTIONS
***********************************************************************************************/
// Calculate expected times and standard deviation.
 expect_t(stdd, expt, p ,  n); 

// Clear out node buckets.
clear_bucket(bucket, nn);

// Calculate early start using forward scan rule.
early_start(rem, p, es, bucket, expt, n);

// Calculate early finish time.
early_finish(es, n, totmax, expt, ef);

// Load up node buckets.
load_bucket(totmax, bucket, nn);

// Calculate late start time using reverse scan rule.
late_start(n, p, ls, bucket, rem, expt);//

// Calculate late finish time.
late_fin(ls, expt, lf, n);

// Calculate total slack.
slack(n, ls, es, totsl);

// Calculate critical path.
critical_path(ask, totsl ,  n);

// Print Report
pert_out(p, expt,  stdd,  es,  ef,  lf,  ls,  totsl, n, ask);

  return 0;
}
pert.h
//header file for malt and main 
// contains the struct for both
#ifndef PERT_H
#define PERT_H
//defining the struct so all functions have access to it.
  struct Activity {
    int i,               // Beginning node number.
        j;               // Ending node number.
    float  pt,           // Pessimistic time. 
           prt,          // Most probable time.
           ot;           // Optimistic time.
    char desc[21];       // Activity description.
  };
//time stucture
/*struct today{
*/	
/*
preconditions:
	n = the number of  activities
	ls = array of late start ls[0] is undefined ls[n] is the last position in the array
	es = early start array es[0] is undefined es[n] is the last position in the array
	totsl = total slack each array position coresponds with each activity
*/
	float* slack(int n, float ls[], float es[], float totsl[]);
/*
postconditions:
	undefined if any of the variables are not what are defined in preconditions
	returns totsle
*/
/*
preconditions:
	ls = array of late start ls[0] is undefined ls[n] is the last position in the array
	expt = array of expected finish time
	lf = array of the latest finish times
	n = the number of  activities
*/
	float* late_fin(float ls[], float expt[], float lf[], int n);
/*
postconditions:
	undefined if any of the variables are not what are defined in preconditions
	returns lf
*/
/*
preconditions:
	n = the number of  activities
	p = struct containing all pertinent information for the activity
	bucket = value holding array
	rem = variable holder
	expt = array of exptected finish time
*/ 
	float* late_start(int n, struct Activity p[],float ls[], float bucket[], float rem[], float expt[]);
/*
postconditions:
	undefined if any of the variables are not what are defined in preconditions
	returns rem

*/
/*
preconditions:
	totmax = variable holder
	bucket = value holding array
	int nn = largest node number
*/
	float* load_bucket(float totmax[], float bucket[], int nn);
/*
postconditions:
undefined if any of the variables are not what are defined in preconditions
	returns bucket
*/
/*
preconditions:
	es = early start array es[0] is undefined es[n] is the last position in the array
	n = the number of  activities
	rem = variable holder
	expt = array of expected finish time
	ef = array of early finish times

*/
	float* early_finish(float es[], int  n, float totmax[], float expt[], float ef[]);
/*
postconditions:
undefined if any of the variables are not what are defined in preconditions
	returns totmax
*/
/*
preconditions:
	rem = variable holder
	activity = is the struct containing the information from the file
	es = early start array es[0] is undefined es[n] is the last position in the array
	bucket = value holding array
	expt = array of expected finish time
	n = the number of  activities

*/
	float* early_start(float rem[], struct Activity p[] , float es[], float bucket[], float expt[], int n);  
/*
postconditions:
undefined if any of the variables are not what are defined in preconditions
	returns rem
*/
/*
preconditions:
	bucket = value holding array
	int nn = largest node number
*/
	float* clear_bucket(float bucket[], int nn);
/*
postconditions:
undefined if any of the variables are not what are defined in preconditions
	returns bucket
*/
/*
preconditions:
	array = array to be printed
*/
	void prnt_array(char* array);
/*
postconditions:
undefined if any of the variables are not what are defined in preconditions
	returns nothing 

*/
/*
preconditions:
	ask = array that holds '*' in position for critical path marking
	totsl = total slack each array position coresponds with each activity
	n = the number of  activities

*/
	char* critical_path(char ask[], float totsl[] , int n);
/*
postconditions:
undefined if any of the variables are not what are defined in preconditions
	returns an array of '*' if the corresponding job is critical

*/
/*
preconditions:
	stdd = array of standard deviation
	expt = array of expected finish time
	activity = is the struct containing the information from the file
	n = the number of  activities
	
*/
  	float* expect_t(float stdd[], float expt[], struct Activity p[] , int n); 
/*
postconditions:
undefined if any of the variables are not what are defined in preconditions
	returns expt
*/
/*
preconditions:
*/	
	int pert_out(struct Activity *p, float expt[], float stdd[], float es[], float ef[], float lf[], float ls[], float totsl[], int n, char ask[]);
/*
postconditions
*/
/*
preconditions:
*/
	int date_time(void);
/*
postconditions
*/
#endif
pert_out.cpp
#include "pert.h"
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdio>

 
using namespace std;

int pert_out(struct Activity *p, float expt[], float stdd[], float es[], float ef[], float lf[], float ls[], float totsl[], int n, char ask[])
{
//cout << "12345678901234567890123456789012345678901234567890123456789012345678901234567890" << endl;

//system("CLS");
cout << setw(44) << "PERT ANALYSIS"<< endl << endl;
date_time(); 
cout << endl;
cout << " ACTIVITY    JOB       EXP.      STD    EARLY   EARLY    LATE    ";
cout << "LATE   TOTAL  C" ;

cout << endl; 

cout << "  I   J  DESCRIPTION   TIME      DEV    START  FINISH   START  FINISH   SLACK  P";
cout << endl;
cout << endl;
cout << fixed;
//cout << "n = "<<  n <<   endl;
for ( int i = 1; i <= n; ++i ){
	char job[21];

	//i and j out put
	cout << "";
	cout.width(3);
	cout <<  (p+i)->i; 
	cout << " ";
	cout.width(3) ;
	cout <<  (p+i)->j;
	cout.fill(' ');
	cout << " ";
	

	//converting job to a printable array
	for(int x = 1 ; x <= 11; ++x)
	{	
		job[x] = (p+i)->desc[x];
	}
	prnt_array(job);
	
	
//exp time
	cout << "  ";
	cout << setprecision(1);
	cout.width(6);
	cout << expt+i;
//std dev
	cout << "   ";
	cout << setprecision(2);
	//cout.fill('');
	cout.width(6);
	cout << stdd[i];

//early start
	cout << "   ";
	cout << setprecision(2);
	cout.width(6);
	cout << es[i];

//early finish
	cout << "   ";
	cout << setprecision(1);
	cout.width(5);
	cout << ef[i];

//late start
	
	cout << "   ";
	cout << setprecision(1);
	cout.width(5);
	cout << fixed;
	cout << ls[i];
//late finish
	cout << "   ";
	cout << setprecision(1);
	cout.width(5);
	cout << lf[i];
//total slack
	cout << "   ";
	cout << setprecision(1);
	cout.width(5);
	cout << totsl[i]; 
	cout << "  ";
	cout << ask[i];


	cout << endl;

	}
return 0;
}




The rest of the functions just do math on the arrays but as you can see from main there is alot of them. If you want them i will add them on.
Reply With Quote  
Join Date: Apr 2005
Posts: 32
Reputation: sinrtb is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
sinrtb sinrtb is offline Offline
Light Poster

Re: Trying to use pointers

  #13  
May 18th, 2005
Sample file to be read
 1 2 1 2 4 ORD.FIXTURES
 1 4 1 2 3 EXCAVATION
 1 7 3 4 5 ORD. TREES SHRUBS
 2 3 3 4 5 MANUF. FURNIT.
 3 6 1 2 2 DELIVER FURNIT.
 4 5 4 5 6 ERECT STRUC. STL
 4 8 1 3 5 BACK FILLING
 5 6 3 5 6 MASONRY WORK
 6 9 1 5 7 INSTALL FURNIT.
 7 8 2 3 4 FINAL GRADING
 8 9 4 5 7 PLT TREES,SHRUBS
Reply With Quote  
Join Date: Apr 2005
Posts: 32
Reputation: sinrtb is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
sinrtb sinrtb is offline Offline
Light Poster

Re: Trying to use pointers

  #14  
May 18th, 2005
The point of the assignment is to make it so that the file can be dealt with using pointers, in the origional code everything worked as it was supposed. But there was no pointers used (example in my origional post.
Reply With Quote  
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 2
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: Trying to use pointers

  #15  
May 18th, 2005
Here's a trick for fixing problems like this one. Cut out all of the fluff from your program so that it's absolute bare-bones, but still has the problem. Errors are easier to see when you don't have a lot of code all around them diverting your attention. There are three rules to follow:

1) Use a single source file. No headers except the required standard ones.
2) Output is irrelevant unless the problem is with formatting. Remove all pretty-print functionality.
3) Hardcode everything. User input is nice, but it bulks up a program.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 7:44 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC