jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No problem. Post back whenever!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check to make sure the output isn't just scrolling off the screen. If you're running it from the command prompt, just do myprogramname > screenout.txt and you'll get an output file.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here's what I ran

#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>

using namespace std;

enum songCategory {ROCK = 0, ALTERNATIVE = 1, CLASSICAL = 2, SOUNDTRACK= 3, CHILDREN=4, OTHER=5};
struct MyLibrary
{
	string albumName;
	string songName;
	string artistName;
	string playTime;
	songCategory genre;
	string albumProducer;
};

void GetLibrary(ifstream& inFile, MyLibrary Library[]);
void PrintLibrary(ofstream& outFile, MyLibrary Library[]);
void PrintToScreen(MyLibrary Library[]);
void AddRecord(ofstream& outFile, MyLibrary Library[]);

const int MAX_SIZE = 200;



int main()
{
	ifstream inFile;
	ofstream outFile;

	inFile.open("MySongLibrary.txt");
	outFile.open("OrganizedLibrary.txt");

	MyLibrary songInfo[MAX_SIZE];

	GetLibrary(inFile, songInfo);
	PrintLibrary(outFile, songInfo);
	PrintToScreen(songInfo);
	//AddRecord(outFile, songInfo);
	


	inFile.close(); 
	outFile.close(); 

	return 0;


}

void GetLibrary(ifstream& inFile, MyLibrary Library[])
{
	for(int i = 0; i < MAX_SIZE; i++)
	{
		string category;

		getline(inFile, Library[i].albumName);
		getline(inFile, Library[i].songName);
		getline(inFile, Library[i].artistName);
		getline(inFile, Library[i].playTime);
		//getline(inFile, Library[i].genre);
		//string category;
		getline(inFile, category);
			if(category == "ROCK")
				Library[i].genre = ROCK;
			else if(category == "ALTERNATIVE")
				Library[i].genre = ALTERNATIVE;
			else if(category == "CLASSICAL")
				Library[i].genre = CLASSICAL;
			else if(category == "SOUNDTRACK")
				Library[i].genre = SOUNDTRACK;
			else if(category == "CHILDREN")
				Library[i].genre = CHILDREN;
			else if(category == "OTHER")
				Library[i].genre = OTHER;
		
		getline(inFile, Library[i].albumProducer);
	}
}


void PrintLibrary(ofstream& outFile, MyLibrary Library[])
{	
	for(int i = 0; i < MAX_SIZE; i++)
	{
		outFile << right << setw(3) << i + 1 << ") ";
		outFile << Library[i].albumName << endl;
		outFile << "     " << Library[i].songName << endl;
		outFile << "     " << Library[i].artistName << endl;
		outFile << "     " << Library[i].playTime << endl;
		outFile << "     " << Library[i].genre << endl;		
		outFile << "     " << Library[i].albumProducer << endl << endl;
	}
}

void PrintToScreen(MyLibrary Library[])
{
	for(int i = 0; i …
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

...how? Can you copy that code and paste it here?

See my edit on the previous post.
You also have your print to screen method starting from 9 for some reason. The "junk" you are seeing when this is output is due to printing uninitialized variables, which will go away once you feed it the whole songset (or keep track of the number of structs written with a counter and send that number into your printing functions as an upper limit)

MrJNV commented: Helped a major issue +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here's what I got (changing one to childrens and one to other to test it):

1) Queen - Greatest Hits
    We Will Rock You
    Queen
    204
    0
    123 Studios

 2) Queen - Greatest Hits
    We Are the Champions
    Queen
    303
    4
    123 Studios

 3) Queen - Greatest Hits
    Another One Bites the Dust
    Queen
    338
    5
    123 Studios

EDIT: I should say that was my output file, when you posted the screen printing method it was commented out.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your text file has "Rock" but your if statements are testing for "ROCK" so either you have to change the if statement or convert your input to upper case (leave your enum case the same).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It works if you get rid of getline(inFile, Library.genre); I didn't try it but it might have worked with inFile >>Library.genre, but mixing getlines and >> can cause trouble. The second argument to getline should be a string.

There are some problems in the addRecord method (you need to probably make a loop in the main method to get additional records and pass in the i value to addRecord and you need to declare albumName locally if you want to read into it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you put up a sample text file?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

genre should be of type songCategory in your struct instead of string. Then your other code should work.

Also, you do not need to specify the =0, =1, =2etc in the enum itself since those are the default values so you can have enum songCategory {ROCK,ALTERNATIVE, etc,etc}

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, you want to go from 0 to side, since you loop is j<side, in this case side is 4, giving 0 1 2 3 (so 4 stars). You don't need the star at the beginning either.

So it goes:

for loop (over the rows)
{     
         for loop over the stars
         {
                 Print stars
         }

         line break (cause once we're done here we're off to the next row 
                           in the loop)
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hint: Only use the outer for loop to control the lines, use the inner for loop to control the number of stars on each line. So therefore, you only need to put in the line breaks at a certain point.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't need it:

int i = 0;
while(input>>employee[i].spotnumber)
{
      input >> employee[i].driver_name;
      input >> employee[i].car_reg;
      i++;
}

Search the threads on this site about eof and why it's not reliable. E.g., http://www.daniweb.com/forums/thread19956.html , post #18 on that thread. (that thread/article is also the 5th sticky post down at the top of this forum)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need downcasting(downcast your base class pointer to a pointer to your derived class -- go "down" the class hierarchy). See this for a good example (aside from the initial post).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Based on your specification, you'll need to revamp your code a little bit to use a structure. So you'll need it outside of main() like:

struct rainfall_data
{
      int amount;
      string month;
      
       rainfall_data(string monthname){month = monthname;}
       //you can read anything on class constuctors too because they are
         //virtually identical
};

Then you'll need an array of those rainfall_data yearly[12]; I didn't examine your sort too carefully but it looks like it's pretty good. Now you just need to sort based on rainfall.
(see this for some info as to how you should access the members

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

And this:
ComplexInterface theComplex();
is still not right.
nor FileHandling file();

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

ok made the revisions and still getting the "undefined reference to 'complex()'" errors on the complex() lines
and "undefined reference to 'file()'" errors on the file() lines errors attached the new code
sorry to have so many problems I've been hacking away at this code for the better part of a week and am sure im missing stuff i should know also the vectors lecture is next semester so im pulling most of this from my java array list knowledge and crash coursing the internet

There shouldn't be any complex() lines or file() lines (outside of their constructor definitions in their own class files) it should be object.method() across the board.

EDIT: These are still around (in complexinterface.h):

vector<Tenants> complexList();//holds a vector of tenants
	vector<Repairs> repairsList();//holds a vector of repairs

get rid of the ()

Another random thing: tenants.h has vector.h included it should just be <vector>

Demo and file handling still have complex.h

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There are a bunch of changes

take off the () these are not methods, these are members
        vector<Tenants> complexList;//holds a vector of tenants
	vector<Repairs> repairsList;//holds a vector of repair

//take off the () on complexList, again not a method
for (int i = 0; i < numberOfUnits; ++i) {
			cout << i+1 << " " <<complexList[i].getTenantName();

//there's a ton more, like in here (I didn't change them)
cout << "Tenant Name: " << complexList()[unitNum].getTenantName() << endl;
	cout << "Unit Number: " << complexList()[unitNum].getUnitNumber() << endl;
	cout << "Balance Due: $" << complexList()[unitNum].getBalanceDue() << endl;
	cout << "Size: " << complexList()[unitNum].getUnitSize() << " BedRooms\n";
	cout << "Number Of Repairs: " << complexList()[unitNum].getAptNumberOfrepairs() << endl;

Do the same for repairslist
There are a couple of spelling errors in Tenants.cpp (repiarlist) which are also causing errors -- on top of that when they are corrected to repairsList, it's not in scope in Tenants.cpp

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I haven't figured out what's up with the error you posted but looking closer at your code, you should probably rename complex.h to something else because that's the name of the old (non-standard) complex number header. It doesn't give an error but there are warnings about it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Two choices this time too, you can put a prototype float average(int a[],int); at the top (above void displayTitle)
and then put your function definition (what I posted above) after the closing brace of main:

int main()
{

}
float average(,)
{


}

or you can skip the prototype and put the whole thing above void displayTitle()

float average(int agearr[],int count)
{

}

void displayTitle()
{

}
int main()
{


}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster


Writing a scripting language requires a lot of parsing and communication between functions, so I am starting at the ground and learning up.

To do that, I have to know exactly how C/C++ works with strings.

I gotcha. Sounds like a cool project (and automation anything is always nice). I've begun to appreciate the power of using streams to do things but getting it all from the ground up is a great way to learn a ton, so best of luck.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What is the output you are getting currently?

There are a couple of options for a function, one is you can pass in Age[] and I

e.g.,

float average(int agearr[],int count)
{
           float ave
           int sum (over all agearr)
           cast sum to a float
           ave = sum divide by I
           return ave
}

and then call it in main() Average = average(Age,I); or if you preferred you could pass in sum and I and have it do the division for you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Asking for the sake of curiosity, is there a specific reason you're not using the filestreams and <string>?
for example see this which might (I don't know for sure) have similar insides and can definitely be used in a loop.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't need the () when using a default constructor nor do you need them on the object when invoking a method (you do need them on the method call itself)

complex().setRepairPtr(file().getRapairPtr());

should be 
complex.setRepairPtr(file.getRapairPtr());

and your object declaration should be 
Complex complex;

The second part of your question I'm not sure of, but if you are dynamically allocating those objects then you'd need to take care of that in the constructor of the object being called.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There's a mismatch on your signatures

ShowAll(x, y, z, average, max, min);
vs.
void ShowAll(int x, int y, int z, float average, int min, int max)
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See http://www.cplusplus.com/reference/iostream/istream/get/ you'll want the third one down that takes a streamsize (there's an example at the bottom of the page but its got some error checking that you can probably put on hold for the time being).
As far as the two names in one field is concerned -- this may not be the best or most elegant way of doing it, but you could read the names into two temporary variables and then concatenate them into your name array.
I assume you are using char arrays based on an assignment, but if you don't have to use them look into strings instead.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not sure because I don't have a main() to test with.

You could just make a few objects that are equal and not equal to test out your operators
e.g.

Date today(12,14,2009);
Date tomorrow(12,15,2009);
Date copyofdate(12,14,2009);
cout <<"today < tomorrow "<< (today < tomorrow)<<endl;
cout << "today == tomorrow "<<(today == tomorrow)<<endl;
cout <<"copyofdate == today "<<(copyofdate == today)<<endl;

(I didn't compile the above so there may be an error or two)

EDIT: Make sure you either put your main at the end of your existing file -- if you put it in its own file, you need to split off your class declaration into a .h file and #include "yourheader.h"

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think your output and stuff was closer the first time. As of now your write statements aren't really doing anything (I can't even get them to compile like that and they have the wrong # of arguments). To be honest, I find it much easier to use ifstream and ofstream and use the >> and << operators (just like with cin and cout). Then you could use a string for employee name and all those strcpys live to fight another day. That's just my 0.015 dollars worth.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You were writing to a in the method and then trying to pass empty arr into your print function. So pass a into the print function. Remember the name of the argument that you are passing in in main and the name of the parameter of the function have nothing to do with each other. Once you run the populate function, the array is changed (by pointer) and so when you pass in the same array into print it will receive the values by pointer also.

As far as your random values, you should only have one randomization function, either in the method or in main(). The one in main and the one in the function could come up with different values and then they will conflict. There's still something about that function that it keeps coming up with the same number over and over. I had it earlier that it wasn't doing that I'm trying to isolate it now.
Here's my main() in case that helps (though I used arr, you are fine with using a for both)

int main()
{	
	
	int arr[ARRAY_SIZE] ;
	//srand((unsigned)  time (NULL ) ) ;
	
	int numberOfElementsToStore = populateArray(arr) ;
	printArray(arr,numberOfElementsToStore) ;

    
     return 0;
}

EDIT: Ok, this is one of those oddities that I'm sure someone had explained to me more than once but I just don't get it. So I took srand out of main() (housekeeping more than anything) but I put back in a cout in populate() where …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You only need to call srand() once per program.

That was my bad, I thought that it was helping but I'd also taken the cast off of the given "random function" (10+25*etc)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I put another srand((unsigned)time(NULL)); into the body of the populateArray() function and it seems to work now.
and took off the (int) cast of int numberOfElementsToStore = (int)( 10 + 25 * ((double) rand( ) / (double) RAND_MAX )) ;

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I interpreted your assignment slightly differently:

int populateArray(int a[] )
{
	int numberOfElementsToStore = (int)( 10  + 25 * ((double) rand( ) / (double) RAND_MAX )) ;
	int i = 0 ;
	for (int i = 0; i < numberOfElementsToStore; i++)
	{
		a[i] = rand() % 100;
	}

	return numberOfElementsToStore;
}
	
int printArray(int arr[],int numelements)
{
	int i = 0 ;
	for (int i = 0; i < numelements; i++)
	{
		if ((i+1) % 10 == 0)
			cout << fixed << setw(6) <<arr[i] << " " << endl ;
		else
			cout << fixed << setw(6) << arr[i] << " " ;
	}

	return i ;
}

with the random function determining the number of elements in the array. You can play around with the rand % 50 to get the range of numbers that you need. I had to rename some things and change some of your doubles to ints (again can be adjusted accordingly for your assignment).

Also, please try to avoid global variables... there wasn't much standing in the way of their being defined in main and passed in.

EDIT: There's a problem with the number of values generated it seems to be constant. I did need to take the double out from the front of srand() in main... that helped with the values but not the number of them.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
if (plainLine[i] == '\n')
                  cipherLine[i] = '\n';

If your getline method is separating based on \n anyway, would you need this statement at all? I think you're doing the right thing in reinserting \n in the ofstream

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's here:
(I helped him on the other post -- mcap, I think you got the abbreviated URL when you cut and pasted)

I think you should use std::list, and no pointers if it's not neccessary!

We can probably do some "duck typing" (go against the C++ grain for a second) on it and find it's an assignment

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think some small changes are all you need.

if (scores[pos]== -1)
	   {
		   count=1;  //you could make this a "break;" statement to get you out of the loop (move it after the next statement, though, then take out your second condition in the while loop)
		   //scores[pos]= scores[pos-1];  here was the problem
                   //you would then write the previous good score over the
                    // -1 in the array?
		   num_tests= size;
		   //also num_tests should be size, I think so you're not
                   //getting the extra score in your calculation
	   }
	   else
                 size++;
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You want to swap row 0 and row 1 instead. The way you have your function laid out it'd be accessing garbage adjacent to your 2D array when you access the non-existent row 2.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I was able to get it work as you have it with this output:

Before
1 2
3 4

After
3 4
1 2

I hate to ask, but we all get these moments, were you trying to swap rows 1 and 2?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I retooled your method a little bit:

void add_names()
{   //name *temp, *temp2;
    //temp = new name;
    name * prior = new name;// * temp;
    int ranking;
    int i=0;
    string male_name, female_name;
    ifstream in_stream("babynames2004.txt");
    
    //in_stream.open; //opens and loads names & ranks from file
    if (in_stream.fail())
   {
    cout << "File failed to open." << endl;
    cout << "Program will now close." << endl;
    system("PAUSE");
    exit(0);
   }
    
    in_stream >> ranking>>male_name >> female_name;
	
    
    prior = start_ptr;
    prior->rank = ranking;

    prior->boy_name = male_name;
    prior->girl_name = female_name;
    prior->nxt = NULL;
    
    name *temp;
	while(in_stream >> ranking >> male_name >> female_name)
    {
    
    temp = new name;
    prior->nxt = temp;
    
    temp->rank = ranking;
    temp->boy_name = male_name;
    temp->girl_name = female_name;
    temp->nxt = NULL;
    prior = temp;
    
    }
    temp->nxt = NULL;
    
    for (name * strt = start_ptr;strt->nxt !=NULL;strt=strt->nxt)
           cout<<strt->rank<<" "<<strt->boy_name<<endl;
}void add_names()
{   //name *temp, *temp2;
    //temp = new name;
    name * prior = new name;// * temp;
    int ranking;
    int i=0;
    string male_name, female_name;
    ifstream in_stream("babynames2004.txt");
    
    //in_stream.open; //opens and loads names & ranks from file
    if (in_stream.fail())
   {
    cout << "File failed to open." << endl;
    cout << "Program will now close." << endl;
    system("PAUSE");
    exit(0);
   }
    
    in_stream >> ranking>>male_name >> female_name;
	
    
    prior = start_ptr;
    prior->rank = ranking;

    prior->boy_name = male_name;
    prior->girl_name = female_name;
    prior->nxt = NULL;
    
    name *temp;
	while(in_stream >> ranking >> male_name >> female_name)
    {
    
    temp = new name;
    prior->nxt = temp;
    
    temp->rank = ranking;
    temp->boy_name = male_name;
    temp->girl_name = female_name;
    temp->nxt = NULL;
    prior = temp;
    
    }
    temp->nxt = NULL;
    
    for (name * strt = …
mcap61 commented: Saved my life on a project thanks so much +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you have 7 people, all your arrays need to be of length 7. You can't use the same for loops in this case. I would strongly (having seen another poster go through something similar) discourage you from this way of doing it...it's not just going to "work" the same way.
But, what I would recommend you do, if this is your course of action, is to write some small samples for yourself of how to read one row in the text file (there's not going to be much difference in theory, just make sure you are reading into variables that match the type of the data at that position in the text file. Once you've gotten one "row." that is each of your parallel arrays has one item in it, encase it in a loop over the length of your arrays (7). I know you're appreciative of the help, and I appreciate your appreciation, and we will still help you but you have to make sure you are getting the most out of it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do you have it set up as a Win32 console application or did you choose Win32 project?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

YW, sorry I didn't catch it in the first place. Never a prob, post back anytime :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
if (highest<num[i])
 {
       highest=num[i];
      highestindex=i;
}

did you add them there (I'm asking cause in your snippet you hadn't)?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Wow, I missed that one, not sure why. Put some braces around those two statements in the if, otherwise all it does get is the last one. Apologies....

for(int i=0; i<count; i++)
   {
  if (highest<num[i])
   [b] {[/b] 
       highest=num[i];
    highestindex = i;
    [b]}[/b]    
}

But remember you may need to add 1 to highestindex before you output it since your text file probably starts with 1. rather than 0.

What I meant by that statement was if your record is saying
1. Jane Smith 87
2. Bob Jones 89
then it's going to return index 1 for the highest number, but that's your person #2 is all.
(if only I can go back in time and write it like that yesterday)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No prob. Yeah the rules are the kind of thing where you gotta sit down with a printout of your code and the rules and check them off one by one. It's a pain, but there's not much in the way of shortcuts.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can pass around the ifstream and ofstream objects to your functions. Gosh, I can't believe there's still more to go on this assignment for you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Scope. Your filename variable is out of scope by the time you're back up to main(). So either return it from headerfn() or pass it in by reference, or just put it back up in main(). Technically since your fin and fout are global (which they probably shouldn't be) you can open the file in headerfn() and it will be available elsewhere. But, I would recommend roping fin and fout into main and pass in the filename string by reference).

Nick Evan commented: Rep for helping in this monster-thread +11
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Post up what you have at this point...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
ifstream fin;
ofstream fout;

//function definitions
int main(){
    //system("color f0");
cout<<"Please enter the name path of input file <e.g.scores.txt>: ";
    string filename;
    cin>>filename;
    //fin.open(filename.c_str());
    cout<<endl;
    
    headerfn(); //function call
        
    fin.open(filename.c_str());
    fout.open("results_scores.txt");

There is that whole section of code...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

WaltP was just pointing out that you need to take into account that row 0, row 19, column 0 and column 19 don't have neighbors to their up, down, left, and right respectively.

Also, your for loops take into account 1-19, but your array actually starts at zero, so you were missing out on some cells as you had it.

So you can make a for loop for columns 1thru19-1 and rows 1thru19-1 but evaluate row 0, row 19, column 0, column 19 each in a separate for loop counting cells that exist in the array(since the ones above/below/to the left/to the right respectively are probably not initialized and you'll either step out of bounds or get garbage in your answers).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yeah, it shouldn't be a problem. You are typing the full name with the .txt? I can't think of anything else it could be. Try making a second file with the information in it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't know what to tell you about the screen clearing aspect except to direct you to the pluses and minuses of doing such a thing in this thread (in it you can find stuff you can use but also arguments against doing so, so I don't want to recommend any method to you per se)

For the second issue (and it seems like an insulting question but it happens) are you putting in a filename that exists in the current directory. If you put in a path with a space it definitely won't like it.
I did put that section into your code and it does work for me...