jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
// William Byrd II

#include <iostream>
#include <string>
using namespace std;

class Person
{
public:
    Person(const string name)
    {
    myName = name;
    }
    
    bool operator==(const Person& p) const
    {
	return (myName == p.myName);
    }

private:
    string myName;
};

// declares Student class as publicly inheriting from the Person class
class Student : public Person 
{
public:
    // implemented constructor for the Student class
    Student(const string name,
            const int studentId)
    : Person( name )
    {
        myStudentId = studentId;
    }
            
    // implemented overloaded equality operator Student class member function
    bool operator==(const Student& s) const
    {
    return (myStudentId == s.myStudentId && Person::operator==(s));
        //since we want a boolean anyway we don't need the if/else
    }

private:
    int myStudentId;
};

int main()
{
    Student app1( "William Byrd II", 8765309 );
    Student app2( "William Byrd II", 8765309 );
    
    // test overloaded == operator for Student class
    cout << "app1" << ( ( app1 == app2 ) 
        ? " == " : " != " ) << "app2"
        << " according to the overloaded == operator\n";
    
    cin.get();  //changed this from your system call
    return 0;
}

I had forgotten to mention that I fleshed out your base class == sorry about that

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you call Person::operator==(s) in the derived class and AND the results with your derived class comparison?

so like:

bool operator==(const Student& s) const
    {
    return (myStudentId == s.myStudentId && Person::operator==(s));
    }

EDIT: I did test it out and it seems to work.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I ran across this (pursuing it out of curiosity) http://services.aonaware.com/DictService/ I have never used it and I'm not sure what the licensing terms are.

ddanbe commented: He, great site! Even has C# code! +5
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Welcome to the site. For us to best help you with your assignment, please post all relevant code and any specific questions that you have.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think the pointer is not initialized so when you try to dereference it the first time *s = a; it crashes. Setting s = &a; in conjunction with s = &b; after incrementing the pointer also works. Your cout should be dereferenced to view the char.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you trace where it is in the program when it's stopping? (i.e., where the menu is not displaying-- cause you do have a loop there). I see little things here and there but I think most of it looks ok.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Is there more to main? Sounds like you want to put a while loop so you can cycle through it again once you are done with the transaction. Also, in your last post you asked about the boolean for active/inactive. I was saying you should put a member in your savings class (either public member or preferably private with getter/setter) and then toggle that when you run the status method (as you have it now, the active variable is local and will be destroyed when the method exits.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you are calling your function with a specific element of each of those arrays, you are no longer passing an int a[] you are passing in a plain int. Your definition is treating it like you are sending in the whole array of size 20.
If you are letting your function do the stepping through the array leave the definition as is and pass in e.g. booktitle (without any []) in the function call but if you are stepping through the array in main and only want your function to see one element at a time, change your definition (and declaration of course) to reflect that.

Also, please use the code tags next time even if it is just a few lines of code //your code here

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Not all overloaded operators need to be member functions. The binary operators in particular are often better suited as non-member functions because it allows a certain flexibility in the ordering of the operands.

Thank you for the explanation, Narue! :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Shouldn't OP's overloaded operators for + only take one parameter (and return real &)? (or am I missing something)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Unless you specifically send a linebreak to cout, it will keep printing on the same line, so basically you need:

cout <<" 1-10";
for loop(over the number of stars for that range)
      cout <<"*";
cout <<endl;  //go to the next line
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Never a prob.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't have a setw call in front of your calculateaverage. It's possible your grade, since it is left biased is bumping up against the average. Otherwise you can pop a few spaces in between with <<" "<< along your cout chain

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

yes and putting return 'A'; etc. within your statements

if (avgstore > 90)
    return 'A';
else if (avgstore >80)
    return 'B';
...
else
    return 'F';
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, and your function should return a char. Sry was trying to make sure you got things in the right place in main()

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can call it whatever you want in the function, but yes I meant back in main keep an intermediate variable of your average function output and then feed that back into your grade function. I was just saying don't put them all on the same line because I'm not 100% sure if the grade function will be called before the other comes back with the value.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

pop in a variable to get that value for use in the subsequent function call

double avgstore;
..... Q6[i] << setw(8) << Final[i] << (avgstore = CalculateAvg (students, id, fname, lname, Q1, Q2, Q3, MidTerm, Q4, Q5, Q6, Final, i));
     cout <<calcGrade(avgstore);   (try it tacked onto the end of the first cout just in case, I wasn't sure if it would be evaluated in the right order)

same for out <<

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
mystruct::operator double()
{
	return x;
}

Seems to...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

defining a new functioninside main? it is possible?

Reread the replies from AD and Narue to your post from yesterday. I believe it's the same situation (and they are quite a bit more clear on it than me).

You defined the casting operator in the struct not the class. I'm not 100% on what your options are.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Cause you don't need the () on a default constructor. It thinks you defining a function.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Sorry about that, but it was just a missprint, the problem is the same with this

struct mystruct
{
  double x;
  mystruct(double x1) : x(x1) {};
};

  T x;    [b] Here you are trying to use a default constructor for your  
                 struct and there isn't one [/b]

I couldn't configure it to work using your 1 parameter constructor however, so this may be a blind alley.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you add a private bool member to your savings class and simply use your status method to set it or unset it? You could have a "getter" to check it when the need arose. So in your withdrawal case, it would be savings.status(false);

Also, put code tags around everything before your half-hour runs out and it's stuck hehe

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster


Alternative approach?

We tried to start OP down that path but she preferred this method (closer to class requirement?)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

void getProbsPerSet(int probsPerSet) should be void getProbsPerSet(int & probsPerSet) to pass in the reference to your variable. The way you had it your cin >> value was falling into the vortex. There are a lot of things in the rest of it that I'm not honestly sure what you are doing but this way you can start to debug those when you have a number of problems with which to work

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I was talking about you using cin >> in the beginning. It is incorrect. cin.get(s,80) is how you get your characters into the array and has nothing to do with the functions.

I'm saying write your functions as if they were for testing one character at a time. Send in the character, your "telephone book" is scanned for it, return which ever results necessary. In the main program, your loop will then send in another and repeat.

As you had it, sending in s[] was incorrect, since if you were sending in the entire array it would be just s. The s[] is in the declaration and definition of the function only.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

My apologies, it is not your fault.

Could you call org = (Bitmap)pictureBox1.Image.Clone(); in the button2_Click method also to get a copy of the bitmap to pass into your function? Use the picturebox as a go-between, just do some error checking to make sure something was still there.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

basically I want to put in the second function the address of changed picture and this i want to do it by pressing one button.

You have a third button that requires that the user has already thresholded the image (button2), right? So this will "click" button 2 for you if the user has not done so already. Is that what you were talking about?

Or am I totally missing it and you want a button to fill in that function parameter? Seems to me you could keep the (filename? is that what the parameter is) in a string and check it to see if empty before the function is called and if not flash the button and remind the user.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
void Test::getName( string a[])
{
       a[0] = "cookie";
       a[1] = "hello";
}

Since we're not initializing them anymore we can't use an init list.

dkalita's method would work too

(random addl info)
You need dimensions on your string array, you don't need an array of T, in main and you need to put {} after Test() and ~Test() instead of ;

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

string getName(); in the declaration should be void getName(string []);
(you're going to pass it in by pointer so you won't have to return anything)
in main() declare a string mystr[5]; (or however big you want it)
and call a.getName(mystr); Then you can access mystr directly in once you're back in main.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Line 12: Char should be char
Line 38: ) in the wrong place
Line 40: ) in the wrong place
Line 41: Extra )
Line 47: Extra )
Line 58: ) in the wrong place

There may be others.
When you compile please try to look over the lines which generate the errors as you can often see what went wrong.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think a circle is tough (I'm not totally familiar with the graphics lib you are using) but probably doable with putting one (dot, star etc) on the top line, on the next putting two spaced 1 away from the center dot on either side and one down,then putting 2 spaced equally apart on the next line but on the same level (since if you keep the "slope" equal to 1 you'll have a diamond.

*  * *
                                * *           * *
                             *                         *

It looks like the devil on this scale (ain't discretization grand!!) but for many dots it might look ok. And you can control the painting with something like

for (over the lines of the figure)
   { coord = center - linenumber 
      coord = center + linenumber   
      if(preset condition, say even or odd lines)
           newline
    }

You could get the slope of the line as a function of where you are (from firstPerson's post and some elementary calculus).
I know you wanted an actual loop but give it a try yourself and be creative. The ellipse would just be the circle with a different slope.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

First grab a peek at cin.get() http://www.cplusplus.com/reference/iostream/istream/get/ to see how to get those characters into that char array.

Secondly, you have to make some design decisions. Will your functions process the characters (which in your code they must devine on their own with no indicies) being fed into them one by one or the whole string? I think you want to choose one by one, it keeps the messy array from bouncing around and if you wanted to put in just 'A' to your functions one day you can.

So, use a for loop to march through your string in main, sending the chars (and chars alone) to your functions, so s. Next, clear out the s[] junk from the functions and just treat it for a char s. Compare it with your string and once it matches return the upper or lowercase character only.

Back in main I did this

for (int i = 0;s[i] !='\0';i++) 
 {
	if ( is_upper (s[i]) )
            cout <<s[i]<<"The lowercase equivalent is: "<<to_lower ( s[i] )<<endl;
        //your other fun here
}

so displaying it char by char next to the original. Change that up if you need it to meet your spec.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The code from post #4 ran on my machine and produced an output file.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That seems reasonable

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ok.....I'm on it....I can do the first part, but our professor likes to have the main program be a void main()

Would it make sense to duplicate the same process for finding the average, but instead look for the largest value that way, instead of having to convert over to a 2D array? Like this...

and somehow mesh it with the CalculateAvg averages that were previously found?

Smallest, you mean? or are you dropping the largest? you could take whichever value you want to drop, multiply the average by N to get the total back again and subtract out your dropped value and divide again.

I think as long as the CalculateAverage function is working for you, stick with it. Sometimes those mile and a half long if statements are unavoidable and with the amount of rework required to get it all situated into a 2D array it might not be worth it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ok.....I'm on it....I can do the first part, but our professor likes to have the main program be a void main()

Then we can't hold it against you personally :) (and honor thy faculty members) but every time he encourages it smile to yourself and know that you secretly know better.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

From line 33: outFile<<command<<" : is inserted"<< list.InsertItem(item)<<endl;

is the first example the compiler picks up (and then gives a billion errors from the streams) but any time you have a method directed into an output stream int must have a return value and your InsertItem is void. I think this is the case with many of the other statements as well.

There's also an extraneous statement in your main.cpp file outside of both your main() and Print() methods (?) and you try to use your ofstream object in Print() without passing it in.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Keep the names and identifiers in their own arrays still (it wouldn't take too much work to get them into a string array string identifiers[60][3]; . You can make a scores array that is int scores[60][8]; . Those declarations just have [rows][columns] after the name. You'll have to restructure your input method slightly, by taking in your names, then setting up a small for loop to take in the scores for person1.
The tricky part is that your sorting will not include the midterm scores (right? if the midterm is lowest you wouldn't drop it), so you may want to store those next to the finals so that you can sort a contiguous block within your array.
Anyway, that gives you a head start.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think what you mean is button2.PerformClick()

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Before anything else: I told you this was wrong... if (Q1[i] <= Q2[i] && Q3[i] && Q4[i] && Q5[i] && Q6[i]) should be Q1 <=Q2 && Q1<=Q3 && Q1 <=Q4 && Q1 <=Q5 && Q1<=Q6 I know what you have compiles but that doesn't mean it works the way you want it to.

Also, I didn't notice it before but don't do void main, main should always return an int (pop a return 0; at the end of your code).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
double CalculateAvg(...)
{
      if (Q1[i] < Q2[i]
          return((Q2[i]+Q3[i]+...)/7);
     else if (Q2[i] < Q3[i]
          return ((Q1[i]+Q3[i]+...)/7);
     else
          return (something else indicative of an error);   -- just covering against the "all code paths do not return a value" 
}

or you could write it with the intermediate variable average like you did

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
if
 return X;
elseif
  return Y;
elseif
  return Z;

only one will be called -- actually you should probably have an else on that chain also)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Instead of

float total = scores[0][0]+scores[0][1]+scores[0][2]+scores[0][3]+scores[0][4]+scores[0][5];
    float pavg = (scores[0][0]+scores[0][1]+scores[0][2])/3.0;
    float tavg = (scores[0][3]+scores[0][4]+scores[0][5])/3.0;
    float cavg = pavg+cavg;

try

float total[6];  or go wild and double total[6];
double pavg[6];
double tavg[6];           //I forgot if there were 3 or 6 students
double cavg[6];
for (int i = 0;i<STUDENTS;i++)   or however many students you have now)
    {
      for (int j = 0;j<5;j++)
          total[i] += scores[i][j];
    
      pavg[i] = same thing (for loop over ones you want)
     tavg [i]= same thing (for loop over ones you want)
     cavg[i] = pavg[i]+cavg[i];
}

Then for display
for (int i = 0;i<STUDENTS;i++)
      { 
       cout<<name[i][0]<<" "<<name[i][1];
       for (over scores)
               cout <<scores[i][j]<<" ";
      cout<<total<<average1[i]<<average2[i]<<average3[i]<<endl;
}

I took some liberties but you get the idea.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Then use your existing void function definition, change the return type of the function to double and instead of cout, return the value that you get for the average.

(not that you want to overhaul everything but in another post user "fbody" was recommending putting all the scores for one student in one array (or as one row of a 2D array) -- my take would be that way you could find the lowest member and its index, zero that one out and divide by 7 instead of 8)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Children cant access fields of the parent class. Add accessor and mutator methods to Animal to allow access to these fields from the children.

I reserve the right to be wrong (lol) but aren't these public members OP is trying to access via public inheritance?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Since your classes are really pointers you need the -> operator to dereference and dot them (*A.member() is the same as A->member() )

(also, instead of iostream.h #include<iostream> and instead of stdlib.h #include<cstdlib> and <ctime> in place of time.h -- these are the standard headers you should be using -- unless you're really attached to pre 1998 for some reason)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How do I test the output of the sample, so I can see what the hash table looks like for the example? They look like header files. Also, thanks, it is definitely more user friendly than other sources.

Well, to be frank, I don't think the sample above actually does anything as of yet. It all depends on your actual hash function, which has to be a rule that says I have 100 mailboxes, some function that I perform on a piece of mail will give me a number between 0 and 99. If there's already a piece of mail in that slot, go to the rulebook and it says go one more box down until I find an empty one. So the design consideration (which you have decided to use a fixed array) is what do I do if there's no more room and I have to conform to my rules. Do I copy to a larger array, how much larger?
But you must decide your rules (or maybe they are laid out for you in the assignment) -- you may decide to put it at index (1000000*value/square root of 123) if it were justified.

Then, you can reuse your function to find the index of a particular value and if not check the next, check the next ad nauseum. So in short(lol), you can just display your array.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Sorry to triple post

if ((Q1[i] < Q2[i] && Q3[i] && MidTerm[i] && Q4[i] && Q5[i] && Q6[i] && Final[i]) &&
(Q1[i] != Q2[i] && Q3[i] && MidTerm[i] && Q4[i] && Q5[i] && Q6[i] && Final[i]))

is one of those statements to which firstPerson was referring -- it needs to be if ((Q1[i] < Q2[i] && Q1[i]<Q3[i] && Q1[i] <MidTerm[i] && ....) && etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Take a look at (but for your sake do not copy) something like this(scroll down to get the C++ version). I'm not entirely sure of how to best advise you on this. Make sure you are doing your array comparisons with the proper datatype. I get that you were probably piecing stuff together from a lot of sources...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

My code is readable if you plug it into a compiler of some sort, but it isn't readable within the confines of the forum for some reason.

If this happens, copy and paste to notepad (or another plain text), save the notepad file, and copy and paste from there.