GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 25-Sep-2005, 20:48
Elsydeon Elsydeon is offline
Junior Member
 
Join Date: Aug 2005
Posts: 45
Elsydeon is on a distinguished road

File linking and Structure Manipulation lab... lost


Well, here's my newest one... I'm not at all familiar with structure manipulation though from what I understand it's very similar to using classes. Just lacks the member methods.

1.
Download the solution to the previous lab and make sure it compiles
and runs properly.


2.
Divide the file so that the object class and all related methods (including
the #includes ABOVE the class) are in one file called "rat5Nest.h" ("h" for
header) and everything else is in a second file called "rat5Nestdr.cpp" ("dr"
for driver). Place a statement similar to the following after the other #include
statements in driver program:
#include "rat5Nest.h"
Close the file with the .h suffix, then compile and run the driver program.
If it fails to compile, examine the path.


3.
Divide "rat5Nest.h" again by placing the implementation in a file called
"rat5Nest.cpp". Leave the interface in "rat5Nest.h".

Place the following in interface as the first executable line of code:
#ifndef RAT5NEST_H
#define RAT5NEST_H

At the bottom of the interface, place the following:
#include "rat5Nest.cpp"
#endif


4.
Place the correct path to rat5Nest.cpp in the include line above.

Now close everything except the driver program. Compile and execute it. If
it does not execute, recheck each of the steps above.

5.
a. Develop a menu-driven test driver program that uses the object. Ignore
error trapping.
b. Develop implementations for the constructor, allOK, adding, and finding
stock.
Here's my rat5nest.h
CPP / C++ / C Code:
#include <iostream.h> // for cerr
#include <stdlib.h> // for exit(1)

class rational
{	// represents a rational number in the form numerator / denominator.
	// conditions maintained in class:
	//   denominator > 0, sign maintained in numerator
	public:
		// methods
			rational (); // mirrors original constructor
				// declares a rational number and initializes it to 0/1
			rational (int numerator, int denominator);
				// declares and initializes the rational number
			void initialize (int numerator, int denominator, bool &ok);
				// initializes the rational number.  ok= (denominator > 0)
			int returnNumerator ();   // returns the numerator of the rational number
			int returnDenominator (); // returns the denominator of the rational number
			void reduce ();
			void add (rational fraction);
			void subtract (rational fraction);
			void multiply (rational fraction);
			void divide (rational fraction);
			bool operator== (rational fraction);
	private:
		int numer, denom;
		void rational::makeCommonDen (rational &fr1, rational &fr2);
		int rational::GCD (int a, int b);
}; // class rational

bool rational::operator== (rational fraction) {
	return (numer==fraction.numer && denom==fraction.denom);
} // rational::operator==

rational::rational()
{	bool ok;
	initialize (0, 1, ok);
} //rational::rational

rational::rational (int numerator, int denominator)
{	bool ok;
	initialize (numerator, denominator, ok);
	if (!ok)
		cerr <<"Error: denominator is " <<denominator;
						// writes an error message to standard error stream
} // rational::rational

void rational::initialize (int numerator, int denominator, bool &ok)
{	if (denominator <= 0)
		ok= false;
	else
	{	ok= true;
		numer= numerator;
		denom= denominator;
	} //if
} // rational::rational

int rational::returnNumerator ()
{	return (numer);
} // rational::returnNumerator

int rational::returnDenominator ()
{	return (denom);
} // rational::returnDenominator

void rational::reduce () {
	int x= GCD (numer, denom);
	numer /= x;
	denom /= x;
} // rational::reduce

int rational::GCD (int a, int b)
// determines the greatest common divisor of a and b
// note: better algorithms exist!
{	int possCD, GCDsoFar= 1;
	a= abs(a);
	for (possCD= 2; possCD <= a; ++possCD)
		if ((a % possCD == 0) && (b % possCD == 0)) 
			GCDsoFar= possCD;
	return (GCDsoFar);
} // GCD

void rational::makeCommonDen (rational &fr1, rational &fr2)
{	bool ok;
	int commonDen= fr1.returnDenominator() *  fr2.returnDenominator() *
									GCD (fr1.returnDenominator(), fr2.returnDenominator());
	fr1.initialize (fr1.returnNumerator() * commonDen / fr1.returnDenominator(),
									commonDen, ok);
	fr2.initialize (fr2.returnNumerator() * commonDen / fr2.returnDenominator(),
									commonDen, ok);
} // makeCommonDen

void rational::add (rational fraction)
{	makeCommonDen (*this, fraction);
	numer= numer + fraction.numer;
	reduce();
} // rational::add

void rational::subtract (rational fraction) {
	makeCommonDen (*this, fraction);
	numer= numer - fraction.numer;
	reduce();
} // rational::subtract

void rational::multiply (rational fraction) {
	numer*= fraction.numer;
	denom*= fraction.denom;
	reduce();
} // rational::multiply

void rational::divide (rational fraction) {
	if (fraction.numer == 0) {
		cerr <<"Error.  0 in denominator of quotient." <<endl;
		exit(1);
	} // if
	numer*= fraction.denom;
	denom*= fraction.numer;
	reduce();
	if (denom<0) { // example: -3/-4, converts to 3/4
		numer *= -1;
		denom *= -1;
	} // if
} // rational::divide

And rat5nestdr.cpp
CPP / C++ / C Code:
#ifndef RAT5NEST_H
#define RAT5NEST_H
#include <iostream.h>
#include <iomanip.h>
#include <c:\documents and settings\matt\my documents\231 lab 5\rat5Nest.h>

void displayFraction (rational number);

void main () {

	rational fraction1 (-4, 22), fraction2 (-3, 7325), fraction3 (-3,1);
	displayFraction (fraction1);
	cout <<endl;
	fraction1.reduce ();
	displayFraction (fraction1);
	cout <<endl;

	displayFraction (fraction2);
	cout <<endl <<'/' <<endl;
	displayFraction (fraction3);
	cout <<endl <<"----------------------" <<endl;
	fraction2.divide(fraction3);
	displayFraction (fraction2);
	cout <<endl <<endl;

}

#include <c:\documents and settings\matt\my documents\231 lab 5\rat5Nest.cpp>
#endif

My rat5nest.cpp
CPP / C++ / C Code:

void displayFraction (rational number) {
	// displays number over 3 lines with values right-justified
	int sizeOfInt (int number);
	int num= number.returnNumerator(),
			den= number.returnDenominator(),
			numLength= sizeOfInt (num),
			denLength= sizeOfInt (den),
			biggestLength;
	if (numLength > denLength)
		biggestLength= numLength;
	else
		biggestLength= denLength;
	cout <<setw(biggestLength) <<num <<endl;
	for (int i= 1; i<= biggestLength; ++i)
		cout <<'-';
	cout <<endl;
	cout <<setw(biggestLength) <<den <<endl;
} // displayFraction

int sizeOfInt (int number) {
	int count= 0;
	if (number < 0) {
		number*= -1;
		count++;
	} // if
	while (number > 0) {
		count++;
		number /= 10;
	} // while
	return count;
} // sizeOfInt



And the new program, 5rationalNesting.cpp
CPP / C++ / C Code:
const int
	nameLength = 4,
	maxStocks = 50;						// maximum number of stocks

struct stockType {					// data about a stock
 char name[nameLength];			// 3 or 4 letter stock code (ex: IBM)
 float buyAt, sellLow, sellHigh;	// purchase price per share, when it goes below this price, sell?, when it goes above this price, sell?
// rational numShares;				// number of shares held
 // date datePurchased;			// add when date object purchased
}; // stockType

class portfolioClass {
	// holds an array of stockType
	// conditions maintained in object:
	//	 stock ordered by name
	//	 no repetitions
	public:
		portfolioClass();							// constructor
		void addStock (stockType stock);	// adds stock if it does not exist
		void deleteStock (char code[nameLength]);
							// deletes stock with code = name.
		void findStock (char code[nameLength], stockType &stock);
							// returns stock with name = code
		void updateStock (stockType stock);
							// locates and replaces current entry with stock
		bool allOK ();	// returns the value of ok, then resets it to yep
		int howManyStock();					// returns the number of stock in portfolio
//	private:
		stockType data[maxStocks];
		int numActive;		// number of active records in data
		bool ok;				// holds yep until an operation fails
		void locateStock (char code[nameLength], int &spot, bool &exactMatch);
}; // stockType class


bool portfolioClass::allOK(){
	bool tempok=ok;
	ok=true;
	return(tempok);
}

void portfolioClass::findStock(char code[nameLength], stockType &stock){

}

void addStock(stockType stock){

}

Now... I'm unsure I correctly followed the instructions. I'm not sure if the last addition, the one's with the #if, are in the right file. I assume it's just a way of linking the files together, but it was never explained to us what all of these things did. We were just told to do them. So I don't have a great handle on it. For that reason, I think, some pieces of my structure in the new program don't work. They're commented out.

We had no lab for this assignment so, much like the first assignment I posted here, there's little guidance. Professor was sick. From what I've gathered I'm just allowing the user to make a stock database, and find a stock. But, I don't really know how to make a database like that with a structure. Any help would be appreciated, I'll probably be messing with this late into the night. Digging through the textbook that hasn't been much help at all, etc.
  #2  
Old 25-Sep-2005, 22:00
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,245
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: File linking and Structure Manipulation lab... lost


Quote:
Originally Posted by Elsydeon
From what I've gathered I'm just allowing the user to make a stock database, and find a stock. But, I don't really know how to make a database like that with a structure. Any help would be appreciated, I'll probably be messing with this late into the night. Digging through the textbook that hasn't been much help at all, etc.
To answer this question, simply output the structure to the file. When you read the file, read into the structure. This way all the information lines up properly.

I believe what you're asking is as simple as that.
__________________

Age is unimportant -- except in cheese
  #3  
Old 29-Sep-2005, 17:55
Elsydeon Elsydeon is offline
Junior Member
 
Join Date: Aug 2005
Posts: 45
Elsydeon is on a distinguished road

Re: File linking and Structure Manipulation lab... lost


It's been cleared up some. My file linking is fine now, for some reason I had an extra file in the above post I made. I now only have to work on one piece of this program. Group project, and we don't have to do all of the methods, etc. So here's my dilemma.

CPP / C++ / C Code:
// rationl2.cpp   interface and implementation for class rational
// whats new?  implementation for reduce, add

#include "rat5Nest.h"


const int
	nameLength = 4,
	maxStocks = 50;						// maximum number of stocks

struct stockType {					// data about a stock
 char name[nameLength];			// 3 or 4 letter stock code (ex: IBM)
 float buyAt,								// purchase price per share
	sellLow,									// when it goes below this price, sell?
	sellHigh;									// when it goes above this price, sell?
 rational numShares;				// number of shares held
 // date datePurchased;			// add when date object purchased
}; // stockType

class portfolioClass {
	// holds an array of stockType
	// conditions maintained in object:
	//	 stock ordered by name
	//	 no repetitions
	public:
		portfolioClass();							// constructor
		void addStock (stockType stock);	// adds stock if it does not exist
		void deleteStock (char code[nameLength]);
							// deletes stock with code = name.
		void findStock (char code[nameLength], stockType &stock);
							// returns stock with name = code
		void updateStock (stockType stock);
							// locates and replaces current entry with stock
		int rank(stockType &stock);
		bool allOK ();	// returns the value of ok, then resets it to yep
		int howManyStock();					// returns the number of stock in portfolio
//	private:
		stockType data[maxStocks];
		int numActive;		// number of active records in data
		bool ok;				// holds yep until an operation fails
		void locateStock (char code[nameLength], int &spot, bool &exactMatch);
}; // stockType class


bool portfolioClass::allOK () {
	if (ok=true)
		return true;
	else
		return false;
	ok=true;
}

void portfolioClass::addStock (stockType stock) {
//	data[numActive]=stock;
//	numActive++;
// needs to alphabetically place stock according to name...
	bool addok=0;
	int count=numActive-1;
	int temp1, temp2;
	temp2=rank(stock);
	while(addok!=1){
		temp1=rank(data[count]);
		if(numActive>0){
			if(temp1>temp2){
				data[count+1]=data[count];
				count--;
			}
			else{
				data[count+1]=stock;
				addok=1;
		}
		if(numActive<=0){
			data[0]=stock;
			numActive++;
			addok=1;
		}
	}

}
}


void portfolioClass::findStock (char code[nameLength], stockType &stock) {
/*	bool match=1;
	int i=0;
	do {
		for (int j=0; j<nameLength; j++) {
			if (code[j] != data[i].name[j])
				match=0;
		}
		if (match)
			stock = data[i];
		i++;
	} while ((!match)&&(i<=maxStocks))*/
}

int portfolioClass::rank(stockType &stock){
	int ranking;
	

	return(ranking);
}

I'm in charge of the addStock method, and rank method. One question is simple... what's the proper code to call information out of a structure? Mainly, how do I specifically get the name from a stock that is passed to the rank method? I'll need it to give it a number ranking.

The second is I need to come up with a good way to put the stocks in alphabetical order. I've got an idea of how to do it obviously. The easiest I've figured out is to start at the end of the array, and compare. If the stock in question belongs farther into the array, move the stock in count's location of the array over and decrement count. Pop the new stock in where it needs to be. I just lack a good comparison. Should I convert the 3-4 letter name code into a number rank like I'm hoping to when I figure out how to get the name out or is there an easier way?
  #4  
Old 29-Sep-2005, 20:48
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,245
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: File linking and Structure Manipulation lab... lost


Quote:
Originally Posted by Elsydeon
I'm in charge of the addStock method, and rank method. One question is simple... what's the proper code to call information out of a structure? Mainly, how do I specifically get the name from a stock that is passed to the rank method? I'll need it to give it a number ranking.
You use stock.name to access the name if you have the structure itself. If you have a pointer to the structure, it's stock->name

Quote:
Originally Posted by Elsydeon
The second is I need to come up with a good way to put the stocks in alphabetical order. I've got an idea of how to do it obviously. The easiest I've figured out is to start at the end of the array, and compare. If the stock in question belongs farther into the array, move the stock in count's location of the array over and decrement count. Pop the new stock in where it needs to be. I just lack a good comparison. Should I convert the 3-4 letter name code into a number rank like I'm hoping to when I figure out how to get the name out or is there an easier way?
Look up bubble sort in google. It's the easiest sort to implement and should suffice for your project.
Note to others: Yes there are better sorts, but they are difficult to understand and impossible for a newbie to program. Leave the others for advanced programming techniques...
__________________

Age is unimportant -- except in cheese
  #5  
Old 29-Sep-2005, 21:09
Elsydeon Elsydeon is offline
Junior Member
 
Join Date: Aug 2005
Posts: 45
Elsydeon is on a distinguished road

Re: File linking and Structure Manipulation lab... lost


Well, I've got everything but ranking the 4 letter stock names. My sorting through the array of stocks and putting them in alphabetically seems fine (I think)....

The only code I came up with for ranking that seemed like it should do it was full of problems, and was ridiculously long.

If I put ifs in letter by letter it takes unbelievable amounts of code. It just seems like there should be a more efficient.... shorter section of code that does the same thing as 26 if statements.

At any rate:

CPP / C++ / C Code:
		if(stock.name[z]=="a"||stock.name[z]=="A"){
			if(z==0){
			temp1+=1;
			}
			if(z==1){
			temp2+=1;
			}
			if(z==2){
			temp3+=1;
			}
			if(z==3){
			temp4+=1;
			}
		}	

This won't work. I can't test to see if a location in the name is a certain letter. How do I go about that?
  #6  
Old 29-Sep-2005, 22:23
Elsydeon Elsydeon is offline
Junior Member
 
Join Date: Aug 2005
Posts: 45
Elsydeon is on a distinguished road

Re: File linking and Structure Manipulation lab... lost


Nevermind that hideous thing. I think I'm on to something with this. I've got 2 errors that come out of this, centered around the fact that I'm testing for a >0 out of the strcomp (That is what it returns, yes? How do I make it work?)

CPP / C++ / C Code:
// rationl2.cpp   interface and implementation for class rational
// whats new?  implementation for reduce, add

#include "rat5Nest.h"
#include <string.h>
#include <stdio.h>



const int
	nameLength = 4,
	maxStocks = 50;						// maximum number of stocks

struct stockType {					// data about a stock
 char *name[nameLength];			// 3 or 4 letter stock code (ex: IBM)
 float buyAt,								// purchase price per share
	sellLow,									// when it goes below this price, sell?
	sellHigh;									// when it goes above this price, sell?
 rational numShares;				// number of shares held
 // date datePurchased;			// add when date object purchased
}; // stockType

class portfolioClass {
	// holds an array of stockType
	// conditions maintained in object:
	//	 stock ordered by name
	//	 no repetitions
	public:
		portfolioClass();							// constructor
		void addStock (stockType stock);	// adds stock if it does not exist
		void deleteStock (char code[nameLength]);
							// deletes stock with code = name.
		void findStock (char code[nameLength], stockType &stock);
							// returns stock with name = code
		void updateStock (stockType stock);
							// locates and replaces current entry with stock
		int rank(stockType &stock);
		bool allOK ();	// returns the value of ok, then resets it to yep
		int howManyStock();					// returns the number of stock in portfolio
		bool operator== (rational fraction);
//	private:
		stockType data[maxStocks];
		int numActive;		// number of active records in data
		bool ok;				// holds yep until an operation fails
		void locateStock (char code[nameLength], int &spot, bool &exactMatch);
}; // stockType class


bool portfolioClass::allOK () {
	if (ok=true)
		return true;
	else
		return false;
	ok=true;
}

void portfolioClass::addStock (stockType stock) {
//	data[numActive]=stock;
//	numActive++;
// needs to alphabetically place stock according to name...
	bool addok=0;
	int count=numActive-1;
	int temp1, temp2, z=0;
	while(addok!=1){
		if(numActive>0){
			if(strcmp (stock.name[z],data[count].name[z])== >0){
					data[count+1]=data[count];
					count--;
				}
			if(strcmp (stock.name[z],data[count].name[z])== 0){
				z++;
			}
			else{
				data[count+1]=stock;
				addok=1;
			}
		}
		if(numActive<=0){
			data[0]=stock;
			numActive++;
			addok=1;
		}
	}
}
  #7  
Old 30-Sep-2005, 00:17
Elsydeon Elsydeon is offline
Junior Member
 
Join Date: Aug 2005
Posts: 45
Elsydeon is on a distinguished road

Re: File linking and Structure Manipulation lab... lost


Well, I think this actually works. However, I'm having the hardest time testing the thing.

CPP / C++ / C Code:
// rationl2.cpp   interface and implementation for class rational
// whats new?  implementation for reduce, add

#include "rat5Nest.h"
#include <string.h>
#include <stdio.h>



const int
	nameLength = 4,
	maxStocks = 50;						// maximum number of stocks

struct stockType {					// data about a stock
 char *name[nameLength];			// 3 or 4 letter stock code (ex: IBM)
 float buyAt,								// purchase price per share
	sellLow,									// when it goes below this price, sell?
	sellHigh;									// when it goes above this price, sell?
 rational numShares;				// number of shares held
 // date datePurchased;			// add when date object purchased
}; // stockType

class portfolioClass {
	// holds an array of stockType
	// conditions maintained in object:
	//	 stock ordered by name
	//	 no repetitions
	public:
		portfolioClass();							// constructor
		void addStock (stockType stock);	// adds stock if it does not exist
		void deleteStock (char code[nameLength]);
							// deletes stock with code = name.
		void findStock (char code[nameLength], stockType &stock);
							// returns stock with name = code
		void updateStock (stockType stock);
							// locates and replaces current entry with stock
		int rank(stockType &stock);
		bool allOK ();	// returns the value of ok, then resets it to yep
		int howManyStock();					// returns the number of stock in portfolio
		bool operator== (rational fraction);
//	private:
		stockType data[maxStocks];
		int numActive;		// number of active records in data
		bool ok;				// holds yep until an operation fails
		void locateStock (char code[nameLength], int &spot, bool &exactMatch);
}; // stockType class


bool portfolioClass::allOK () {
	if (ok=true)
		return true;
	else
		return false;
	ok=true;
}

void portfolioClass::addStock (stockType stock) {
//	data[numActive]=stock;
//	numActive++;
// needs to alphabetically place stock according to name...
	bool addok=0;
	int count=numActive-1;
	int z=0;
	while(addok!=1){
		if(numActive>0){
			if(strcmp (stock.name[z],data[count].name[z])== 1){
					data[count+1]=data[count];
					count--;
				}
			if(strcmp (stock.name[z],data[count].name[z])== 0){
				z++;
			}
			else{
				data[count+1]=stock;
				addok=1;
				numActive++;
			}
		}
		if(numActive<=0){
			data[0]=stock;
			numActive++;
			addok=1;
		}
	}
}

Any main driver program I write has to put data into the name for me to test this method.... and well, I can't figure out how. I haven't found a solution on the net to that one, so... does this look like it will work? Or how can I enter data to name portion of the stock?

CPP / C++ / C Code:
stockType stock1;

stock1.name="IBM";

Nothing like that seems to work. I'm still very weird on using these struct/class prefixes and manipulating data structures and strings, so it's probably a dumb mistake on my part.
  #8  
Old 30-Sep-2005, 00:29
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,245
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: File linking and Structure Manipulation lab... lost


Quote:
Originally Posted by Elsydeon
Nevermind that hideous thing. I think I'm on to something with this. I've got 2 errors that come out of this, centered around the fact that I'm testing for a >0 out of the strcomp (That is what it returns, yes? How do I make it work?)

CPP / C++ / C Code:
// rationl2.cpp   interface and implementation for class rational
// whats new?  implementation for reduce, add

#include "rat5Nest.h"
#include <string.h>
#include <stdio.h>



const int
	nameLength = 4,
	maxStocks = 50;						// maximum number of stocks

struct stockType {				// data about a stock
 char *name[nameLength];		// 3 or 4 letter stock code (ex: IBM)
 float buyAt,					// purchase price per share
	sellLow,				// when it goes below this price, sell?
	sellHigh;				// when it goes above this price, sell?
 rational numShares;			// number of shares held
 // date datePurchased;			// add when date object purchased
}; // stockType

class portfolioClass {
	// holds an array of stockType
	// conditions maintained in object:
	//	 stock ordered by name
	//	 no repetitions
	public:
		portfolioClass();					// constructor
		void addStock (stockType stock);	// adds stock if it does not exist
		void deleteStock (char code[nameLength]);
							// deletes stock with code = name.
		void findStock (char code[nameLength], stockType &stock);
							// returns stock with name = code
		void updateStock (stockType stock);
							// locates and replaces current entry with stock
		int rank(stockType &stock);
		bool allOK ();	// returns the value of ok, then resets it to yep
		int howManyStock();					// returns the number of stock in portfolio
		bool operator== (rational fraction);
//	private:
		stockType data[maxStocks];
		int numActive;		// number of active records in data
		bool ok;				// holds yep until an operation fails
		void locateStock (char code[nameLength], int &spot, bool &exactMatch);
}; // stockType class


bool portfolioClass::allOK () {
	if (ok=true)
		return true;
	else
		return false;
	ok=true;
}

void portfolioClass::addStock (stockType stock) {
//	data[numActive]=stock;
//	numActive++;
// needs to alphabetically place stock according to name...
	bool addok=0;
	int count=numActive-1;
	int temp1, temp2, z=0;
	while(addok!=1){
		if(numActive>0){
			if(strcmp (stock.name[z],data[count].name[z])== >0){
					data[count+1]=data[count];
					count--;
				}
			if(strcmp (stock.name[z],data[count].name[z])== 0){
				z++;
			}
			else{
				data[count+1]=stock;
				addok=1;
			}
		}
		if(numActive<=0){
			data[0]=stock;
			numActive++;
			addok=1;
		}
	}
}

A couple problems I see:
Your definition of stock.name seems to be wrong. For the definition
CPP / C++ / C Code:
char *name[nameLength];
1) name seems to be a string value of 3 or 4 characters. Which means you need nameLength to be 5 (one extra for the trailing NULL or '\0'). Make sure you have that '\0' at the end of each name.
2) You don't need * and [], so the definition should be simply
CPP / C++ / C Code:
char name[nameLength];
You have "== >0" which is really wrong.

Therefore, your strcmp() should be
CPP / C++ / C Code:
if (strcmp (stock.name, data[count].name) >= 0)
I think.

A couple formatting suggestions:
more SPACES between terms
use 4 SPACES instead of TABS
line up the comments vertically
Check out this tutorial for detailed information, and pass it to the rest of your team...
__________________

Age is unimportant -- except in cheese
  #9  
Old 30-Sep-2005, 00:40
Elsydeon Elsydeon is offline
Junior Member
 
Join Date: Aug 2005
Posts: 45
Elsydeon is on a distinguished road

Re: File linking and Structure Manipulation lab... lost


Well, I think I've finally gotten somewhere. I fixed the obvious error you pointed out, and I managed to incorporate the rest of the pieces from my team and get it running. The only problems now are in the main, which is just menus and input/output. So I'm good to go. I appreciate it.

By the way, I think the help I've gotten on this forum is a great deal of the reason I managed an A on the last test (one of 2 grades above a B). So I really appreciate that.
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 3) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:00.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.