jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, you're not slow, I'm just getting too far ahead of myself and trying to help you fix everything at once, apologies.

declare I out here so we can keep track of it
for loop #1 (over 0 to 50)
{
     keep a running total of sum (which you are doing just fine
     if (over 18)
           I--;  (bring it back by 1 position (we want to know how many we stepped back in the end so we can use it on the next loop)

}
Average = calculation;
for(make it small i=0 to I)
{
      output age[i] which you are doing just fine

}
output average and message
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I = 1 // the same element the Age array will be read ; You need the semicolon after 1 which you put at the end of your comment. Anything after the comment (//) is ignored. Start with that.

Then, you need to change I = 1; to I--; anyway, since with you setting I = 1 you are moving back to the beginning of the array, not just by one step.

As far as the cast goes, you are dividing two integers. If you divided 7/2 the result is 3, it truncates. If you divide anything with a quotient less than 1, it goes to zero, e.g., 3/7 = 0, even though you have a float to receive the division, it will still produce 0. So casting says that if you put Average = ((float) sum)/50; (parens could be around either numerator or denominator or both) you will get the proper answer.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You commented out your semicolon on that line. Also, I'm not sure if your file was truncated but you don't have a closing brace for main().

EDIT: Also your inner for loop is going to end before your outer one finishes calculating the average. Move that final calculation Average = sum/50; outside of the loop. I would change the loop variable on your inner for loop to something else, everything is going to get muddled with your changes to I. So just move the inner for loop to the outside of the other one.

EDIT2: You will need to cast your sum value to make your average work. Also you can move your final output of the average age outside of both loops. Summary: for loop (then close it off) | calculate average | for loop (then close it off) | display average

Apologies for the edits, I'm not quite awake yet lol

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I believe (I had to try a little example) that it's float*

float a[2] = {4.0,5.7};
	float b[2] = {1.3,9.8};
	string label1 = "label1";
	string label2 = "label2";

	map<string, float *> mymap;

	mymap[label1] = a;
	mymap[label2] = b;
	cout <<mymap[label1][1]<<endl;

output is 5.7

metdos commented: Simple, clear and fast answer. Thanks :) +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please see this: http://www.daniweb.com/forums/announcement8-2.html

We'd be glad to help you with your assignment but you must bring at least some code to the table with specific questions.

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

Couldn't he set it up like this without the LL?

int *** matrix = new int**[3];
	matrix[0] = new int*[3];
	matrix[1] = new int*[3];
	matrix[2] = new int*[3];
	matrix[0][0] = new int[size];
	matrix[0][1] = new int[n1_size];
        matrix[0][2] = new int[n2_size];
        ....
        matrix[2][2] = new int[yada];
        where size, n1_size, n2_size come from values in the code

(Post 500)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
void getLeastAmount (int FoodForMonkey[][days])
{   
    cout << "Least Amount per Monkey: " <<endl<<endl;
    
    int leastAmount;
    int leastAmountTemp=0;
    
    for (int row=0; row < monkey; row++)
    {
        leastAmount=FoodForMonkey[row][0];
        //leastAmountTemp=0;
        for (int col=1; col < days; col++)
        {
            if (FoodForMonkey[row][col] < leastAmount)
                  leastAmount=FoodForMonkey[row][col];   
        }
        //if (leastAmount)
        //leastAmountTemp; 
        cout << row+1 <<". Monkey " << " = " << leastAmountTemp << endl;
     }
      
        cout<<endl;     
}

EDIT: CP beat me to it.

I just took the lowest to be the first value in the row and compared it from there. I think that's what you were originally trying to do. Now your results should be comparable to what you were looking for (or at least not all your init values)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It is a good habit to initialize
But you are taking input first and initializing second

int main()
{
    int FoodForMonkey[monkey][days];
    
    getInput (FoodForMonkey);
    InitializeArray(FoodForMonkey);
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please read the following:
http://www.daniweb.com/forums/announcement8-2.html

...but we do want to help :) we just need to see that you've put in some effort.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Or did I misread your post?

I was wondering whether or not I had, too. It seemed to me like he wanted a "global" count of how many games had been played. I thought about writing out a binary file that kept track but I presume that's probably not in the scope of the assignment.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are you limited to using arrays or can you use vectors? You could use (brace for impact) vector<vector<vector<int> > >

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Sorry to interject as you are focused on the other functions, but how come you prompt the user for input and then overwrite the values in InitializeArray? (I'm probably missing something obvious...)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Could you do something based on the current time? See: http://www.cplusplus.com/reference/clibrary/ctime/time/ If you had two subsequent runs it would be very unlikely that they got the exact same ID.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If your options are numbers (less than 10), why not make it a char variable? If you needed the int value you could just subtract '0' from it.

char a = '1';
int b = (int)(a-'0');
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

Check out this article. It has the pseudocode right in the first paragraph. Try to convert this into code and post back once you have some specific questions.
http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Is this along the lines of what you are looking for? If so there are tons of resources about generics out there.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

C++ Primer Plus is a great text, I have an old ("well loved") 1998 copy still kicking around and while it doesn't have the latest features of the language it's published after ISO so it's got the standard flavor and what I think are a lot of solid examples. Check out the latest version on Google books (there are pages omitted for copyright reasons but you'll get the idea) to get a better idea if it's a good one for you to get.

I don't want to weigh in on the BS book because I don't have much experience with it but check out his website which I think has a lot of the good tidbits of his writing.

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

X->membervariable is a shortcut for (*X).membervariable (so it can access a member of a class or struct to which you have a pointer.
See "this" (no pun intended) for an explanation of that particular case you cited.

Here's a good reference for the vector algorithms (it has miniprograms with each to give you some good examples)

And, also, when/why do you use #ifndef something_H, #define something_H, ..., #endif?
If you have a project with a large number of files and any given file will include multiple headers, there exists the possibility of ending up two files being incorporated with the same header, which can cause problems. So the compiler looks and sees if that symbol SOMETHING_H (could be anything really, people just usually capitalize the name of the header with an underscore) is already defined. If it isn't then it will go ahead and define it and everything after it (the contents of the header). If it is already defined, it will skip to the #endif and the header contents will not be included.

AFAIK, apvector was created by the college board to make the lives of AP Computer Science students easier. It's basically an array with a built in length member, bounds checking, and a few (definitely not as many as the STL Vector) member functions.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put some //code goes here tags around your source. Also, you can add to your old post you didn't have to start a new one.

Are you allowed to use an array for this? That's probably the easiest way. Create a temporary variable to hold the high and one to hold the low, set them to appropriate values. Walk along your array and check if the current number is higher than the highest you have(in your temporary variable), if so then replace your temporary variable with the current number which is now the highest.

int lowest;
int highest;
for loop
{
      if lowest > current
             lowest = current;
      if highest < current
              highest = current;
}

Also, use #include <iostream> instead of iostream.h

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

Are you talking about Unions? They can still be used in C++ but they can still only hold one item at a time, of a predefined set of types.

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

But now you want to add the std:: to see if it will work in this context. I don't think the wide character main changed anything but try clearing it out for a regular main instead.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you select a Win32 console application at the beginning? or an empty project? (cause the empty one really is devoid of a lot of settings that need to be in place so it's easiest to do the Win32 and weed the stuff out you don't need)

I started a win32 console (w/ precompiled headers)

#include "stdafx.h"
#include <iostream>

int main()
{
	std::cout <<"Hello World"<<std::endl;
	return 0;

}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

#include <iostream> to get the standard header. Then you need either using std::cout; at the top or qualify it in the body of your code with std::cout <<"Yada"; You can also go the using namespace std; route but that brings its own problems.

EDIT: Dang... JH, does someone start a stopwatch when we begin posting?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Quoth the Dragon: gotoxy() is a function only supported by Turbo C and Turbo C++

I meant that your professor wants you to use these Borland functions :) so upgrade her/him to work with your Microsoft compiler

Salem commented: They should upgrade their professor to someone whio actually has a clue about something less than 20 years out of date +17
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See the move() method in this library. I've never used it but it claims to work with console based windows apps. You may need to dig around a bit to figure out how to use the dll with your programs. I think something like this is the closest you are going to get. Either that or upgrade your Borland professor to a Microsoft one.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you go through all of the

qmake -project    (regardless of your project name)
qmake projname.pro (your projects C++ file name+.pro)
make

steps. If not, try that. If you have done it, try dividing it up into the three files to see what happens. Qt works with a lot of macros and something out of place could gum up the works.

P.S. There's a free pdf (released by the author under Open Publication) at http://www.qtrac.eu/marksummerfield.html (the author's website). Regrettably, I never finished it but I got through the bulk of it. He develops a very very rudimentary spreadsheet application but it's neat to see the inner machinations.

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

This part of your code is confusing to me

fstream* file = new fstream("GameDetails.txt", fstream::out);
    
	ofstream out;
    out.open("GameDetails.txt",ios::ate);
   
        while ( more )
        {
            game.Tic_Tac_Toe_Board();
            player = game.Pick_Player();
            
            fstream* file = new fstream("GameDetails", fstream::in);
            
           *file << left << setw(30) << setw(25) << "Player"  << setw(25) << "Wins" << setw(10) << right << "LOSES" << endl;

You are trying to preparing to write, you open up an outfile, ok, but then you redeclare/define a fstream in with the same name before you tried to write to the outstream.

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

Right?

No, unfortunately. Run yourself a listing of the chars from say 1 to 600, there's a lot of repeats and they don't act like one would think they will.
viz.

char P = 592;
	std::cout <<P<<std::endl;
	int upP = (int)P;
	std::cout <<upP<<std::endl;
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...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You should create a second class called finalLab.

You have made finalLab a method of the demoClass.

finalLab will have one method, one constructor and one property.
The property will be a string called message.

This will involve having a {get; set} after the property is defined

Your main method in DemoClass should instantiate the new object of type finalLab called Final. Call the method displayMessage after instantiating the object. Set message to "I am done with CIS214" and then call displayMessage again.

It's pretty well spelled out for you there. Instantiate (with "new"), call the method (generically) object.method(). Set the string to a new value. call object.method()

I'll leave the rest of it up to you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Don't just read the names, read the names and the data all at once. Take the loop from the prior post and make it rows to 7. It works.

First0 Last0 54 34 65 34 43 23
First1 Last1 76 54 34 54 23 87
First2 Last2 87 67 45 65 87 67
First3 Last3 45 76 87 65 45 65
First4 Last4 34 65 76 87 56 87
First5 Last5 76 56 78 98 78 67
First6 Last6 87 67 76 87 78 67

was the file I made to test it

1234567890123456789012345678901234567890123456789012345678901234567890
----------------------------------------------------------------------
Student Name        Total     Program   Test      Course    Grade
                    Points    Average   Average   Average
----------------------------------------------------------------------
First0 Last0       253     51.00     33.33     42.17
First1 Last1       328     54.67     54.67     54.67
First2 Last2       418     66.33     73.00     69.67
First3 Last3       383     69.33     58.33     63.83
First4 Last4       405     58.33     76.67     67.50
First5 Last5       453     70.00     81.00     75.50
First6 Last6       462     76.67     77.33     77.00

output is off by a couple of columns but I didn't put a setw in for name

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

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.