NathanOliver 429 Veteran Poster Featured Poster

Post the code that you have now.

NathanOliver 429 Veteran Poster Featured Poster

You should be using a different string to read from the file. You are overwriting schools with what is in the file. This:

while(getline(campuses,schools, '\n'))
{
    schoolVector.push_back(schools);
}

Should be

string temp;
while(getline(campuses,temp, '\n'))
{
    schoolVector.push_back(temp);
}

As far as problem 2 goes what you need to do is create a bool variable and set it to false. Then as you are going through the vector if you find the school then you should set the variable to true. After the loop then check the variable and print accordingly.

JasonHippy commented: Nice spot, I missed that! +9
NathanOliver 429 Veteran Poster Featured Poster

That's because you have a newline floating in the input buffer from line 32. To get rid of the newline in the buffer you can just put cin.get() after line 32. That should at least get you into the queue1 function.

Builder_1 commented: thanks alot man....really grateful for your assistance bro +1
NathanOliver 429 Veteran Poster Featured Poster

It is really weird that the lines with the text at the end don't have a coma where the lines with a number do. Since you do not need the extra column you should be able to get away with using a stringstream to split the columns. I would do something like the following. I am not sure how you are storing the information from the file in your program so in my example each part will just be a string stored in a vector. Each vector will be stored in a vector of vectors.

std::string line;
std::vector<std::vector<std::string>> lines;
stringstream ss;
ifstream fin("filename.csv");

while (getline(fin, line))
{
    std::string temp;
    std::vector<std::string> parts;
    // load line in stringstream
    ss << line;
    // we need for columns only so use a loop 4 times
    for (int i = 0; i < 4; i++)
    {
        getline(ss, temp, ',');
        parts.push_back(temp);
    }
    lines.push_back(parts);
    ss.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    ss.clear();
}
NathanOliver 429 Veteran Poster Featured Poster

Well first off you need to write a function to compute x!. ! means factorial in math. Once you compute the factorial of the number then you need to go through each digit of the number and get the minimum digit. To do that you use the following algorithm:

min = 9;
number = factorial(x)
do
    digit = number % 10 <- this get the last digit of the number
    if digit is less than min and digit does not equal 0
        set min to equal digit
    number = number / 10 <- this drops the last digit off of the number
while number does not equal 0

and at last "cout" 886= 384

I have no idea what this means so i cant help you with that.

I would also like to point out that you have the wrong minimum for all of your answers 10! would be 2 and 11! and 12! would be 1.

NathanOliver 429 Veteran Poster Featured Poster

Can you paste about 10 lines or so from the file into here. Does every column value have a "," after it or does each line end with a newline? Generally with a CSV file if there is an empty column it is represented as ",," but I don't see that in your example. How you read in the file depends greatly on how the file format is defined.

NathanOliver 429 Veteran Poster Featured Poster

Since it was assigned to you maybe you should write it.

NathanOliver 429 Veteran Poster Featured Poster

Well you can make your own rounding function or you could use setpercision

NathanOliver 429 Veteran Poster Featured Poster

You are trashing our memory in your Sport::Add() function. You are adding a local variable to an array of pointers on line 222 which I believe is causing your issues. Have you ever thought about using vectors instead of arrays so you don't have to worry about the memory management. The same thing goes with your \Player class and the use of c-strings. If you convert your Player class to use std::string and your Sport class to use a vector, Add() would look like the following:

void Sport::Add()
{

    std::string usrName;
    int usrGrade;
    double usrGPA;

    ///GET USER INPUT, INSTANTIATE fresh PLAYER
    cout << "\nEnter Player Name: " << endl;
    cin >> usrName;

    cout << "\nEnter Player Grade: ";
    cin >> usrGrade;

    cout << "\nEnter Player GPA: ";
    cin >> usrGPA;

    // have a vector called players defined as std::vector<Player> players;
    players.push_back(Player(usrName, usrGrade, usrGPA))
}
NathanOliver 429 Veteran Poster Featured Poster

It seams to me the blackboard needs to store the message along with the user who posted it. Then the subscribers will hold a list of the users they are subscribing to. When a new message is added all subscribers would get notified of the user that posted and only the subscribers the subscribed to that user would then call back and get the message.

NathanOliver 429 Veteran Poster Featured Poster

A) You are in the wrong formum

Write an interactive program in C

B) You didn't read the rules or you ignored them.

NathanOliver 429 Veteran Poster Featured Poster

You can use the following to convet from System::String^ to std:string

#include <msclr/marshal_cppstd.h>

System::String^ xyz="Hi boys"; 

std::string converted_xyz=msclr::interop::marshal_as< std::string >( xyz);
NathanOliver 429 Veteran Poster Featured Poster

I have already told you. You need to convert the int's into strings. there is no built in support for integer and string concatenation. If you can use a string then you should be able to do the following. It requires includeding <sstream>

custConn->Open();
stringstream ss;
ss << "insert into Employee (Emp_ID,FirstName,LastName,Phone,Service) values(" << empid << ",'" << fname << "','Gupta'," << phone <<",'gdjdjsjsaa')"
custDA->InsertCommand = gcnew SqlCommand(ss.str(),custConn);

custDA->InsertCommand->ExecuteNonQuery();
printf("Row(s) Inserted !! ");
NathanOliver 429 Veteran Poster Featured Poster

You need to make everything a string. You can not have "some text" + int + string + "some text". Also according to the MSDN SqlCommand() takes a String not a string. I dont deal with String's so im not sure if there is a implicit conversion or not.

NathanOliver 429 Veteran Poster Featured Poster

They need to be strings in order to combine them with a string. The compiler is complaining that there is no + operator that takes an int and a string

NathanOliver 429 Veteran Poster Featured Poster

What are empid_ and phone_? Are they strings? If not they need to be.

NathanOliver 429 Veteran Poster Featured Poster

ddnabe that price is a little steep. Since he is new couldn't you cut him some slack and only charge $99,999.95?

NathanOliver 429 Veteran Poster Featured Poster

Yes. That function returns the largest of x, y, and z.

NathanOliver 429 Veteran Poster Featured Poster

string's operator == can take a string and a char so all you have to do is:

i=0;
while(i<23){
    c = char(i)
//convert c which is a character into string 
    if (S[i] == c)
     // do something here
}
NathanOliver 429 Veteran Poster Featured Poster

I would use the container availible in the STL for this. I would think some sort of map would be best for this.

NathanOliver 429 Veteran Poster Featured Poster

What exactly is the purpose of this? You are just trying to make a symbol table? Have you thought about using a map?

NathanOliver 429 Veteran Poster Featured Poster

So what do you have so far? What are you stuck on.

NathanOliver 429 Veteran Poster Featured Poster

Thanks for the guideline Mike. You are informative as always.

NathanOliver 429 Veteran Poster Featured Poster

step through the code with the debugger or use cout statements and oupt what is happening so you know what is going. Debugging is an important skill to learn.

NathanOliver 429 Veteran Poster Featured Poster

move line 28 outside of the loop.

NathanOliver 429 Veteran Poster Featured Poster

In line 30 you are using 2 delimiters. I dont think that will work. What happenes if you just have '/n?

NathanOliver 429 Veteran Poster Featured Poster

Here is a better example for you.

//...

std::string type;
int count;
int candyTotal = 0;
int costumesTotal = 0;
int decorationsTotal = 0;

std::ifstream fin("myfile.txt");  // open file

while we read in what type of item we have keep looping through the file
while(std::getline(fin, type))
{
    fin >> count;
    if (type == "candy")
        candyTotal += count;
    else if (type == "costumes")
        costumesTotal += count;
    else if (type == "decorations")
        decorationsTotal += count;

    // ignore '\n' left in buffer from `>>`
    fin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}

//...
Jinxx commented: Thanks for your help! +0
NathanOliver 429 Veteran Poster Featured Poster

First I want to apologize for #included instead of #include. I am not sure why I did that. Secondly when dealing with an incomplete type which is what a forward declaration of a class gives you you are only allowed to do certain things. There is a nice explanation on SO that you can find here.

As a side note and maybe a moderator can give me an answer if there is a post on SO that has a nice answer to a question should we just link to it or is it okay to copy it. I normally link to it since I dont want to pass of their post as my own but now with a the whole SEO thing going on I wasnt sure it we should copy it.

NathanOliver 429 Veteran Poster Featured Poster

you have to use forward declarations and pointers.

A.h

#ifndef A_H
#define A_H
class B;

class A
{
private:
    B* bclass;
public:
    //...
};
#endif

A.cpp

#included "A.h"
#included "B.h"

// code for class a goes here.

B.h

#ifndef B_H
#define B_H
#included "A.h"

class B : public A
{
    //...
}
#endif

B.cpp

#include "B.h"

// code for class goes here
NathanOliver 429 Veteran Poster Featured Poster

type is just a name for what the sales type is in the file. Every time you loop through readin the file you need to read 2 lines. You need to read the type and the amount.

NathanOliver 429 Veteran Poster Featured Poster

If you know what all of the types are then youcould do something like the folowing

while getting records from the file
    if type == candy
        add amount to candy total
    else if type == costumes
        add amount to costumes total
    else if type == decorations
        add amount to decorations total

If you do not know how many types will be involded then you will need to use 2 parallel arrays which gets a little more complicated.

NathanOliver 429 Veteran Poster Featured Poster

using standard code you could do the following

char choice;
do
{
    // your code goes here
    std::cout << "Do you want to go again (y/n): ";
    std::cin.get(choice);
} while (::tolower(choice) == 'y');
NathanOliver 429 Veteran Poster Featured Poster

What is the code you added that broke it?

NathanOliver 429 Veteran Poster Featured Poster

ifstream is a class that is used for reading files. file_in is an object of the class ifstream and it is used in the program to read from a file. Here is a good reference for what you dan do with an ifstream object.

NathanOliver 429 Veteran Poster Featured Poster

Okay. Why dont you do that then?

NathanOliver 429 Veteran Poster Featured Poster

So what do you have so far? No one is going to do you homeworkfor you.

NathanOliver 429 Veteran Poster Featured Poster

This is not a critique of your code but a way to make it look a little better. In your SplitBySpace function you can make it a lot simpler by using stringstreams.

vector<string> SplitBySpace(const string & s)
{
    stringstream ss;
    string temp;
    // load s into the stringstream
    ss << s;
    vector<string> ret;
    // while there a parts in ss load them into ret
    while(ss >> temp)
    {
        ret.push_back(temp);
        temp.clear();
    }
    return ret;
}

Using a stringstream takes advantage of the fact that white space is ignored just like using cin. I do have to agree with Mike that your code is very well done for a begginer. If only more people could put as much effort into there code when starting out.

NathanOliver 429 Veteran Poster Featured Poster

You could use regular expressions

NathanOliver 429 Veteran Poster Featured Poster

What book are you using if I might ask. It might just be that you need a better book.

Book* pA = new Book("Aardvark", "Be an Aardvark on pennies a day");

That piece of code says make a variable called pA that is a pointer to a book object and give the pointer the address of a new book object created it the parameters "Aardvark" and "Be an Aardvark on pennies a day"

Are you sure you copied the class correctly? Book& Book::operator=(const Book& b) makes no sense to me inside a class. Inside the class it should just be
Book& operator=(const Book& b).

:: is the scope resolution operator and you can see some examples of how it works on the MSDN site.

NathanOliver 429 Veteran Poster Featured Poster

coat

NathanOliver 429 Veteran Poster Featured Poster

@takuya17 - Please don't resurrect dead threads with something completely unrelated. If you want to contract a coding job you need to do so under the Jobs and resumes section in business exchange.

NathanOliver 429 Veteran Poster Featured Poster
Rectangle operator+ (const Rectangle& p1)
{
    return Rectangle(width + p1.width, height + p1.height);
}

Breaking down this function we see the return type is a Rectangle. In the parameter list we have const Rectangle& which means give me a constant Rectangle reference. & means reference and a reference is basically a pointer but you use it like a regular variable. passing a reference of an object to functions is cheaper then passing the function by value so that is why it is done. const is in there so that you can pass a constant or non constant variable. if const wasn't there you would not be able to pass constant variables to the function.

In the function width is the width of the object that is having plus called on where as p1.width is the with of the rectangle that was passed to +.

ddanbe commented: Good explanation +15
NathanOliver 429 Veteran Poster Featured Poster
NathanOliver 429 Veteran Poster Featured Poster

uonsin you are only storing the name of the item. How would you retrieve the description with the method you have?

NathanOliver 429 Veteran Poster Featured Poster
class A 
{
public:
    int x;
protected:
    int y;
private:
    int z;
};

class B : public A
{
    // x is public
    // y is protected
    // z is not accessible from B
};

class C : protected A
{
    // x is protected
    // y is protected
    // z is not accessible from C
};

class D : private A
{
    // x is private
    // y is private
    // z is not accessible from D
};
NathanOliver 429 Veteran Poster Featured Poster

You could do it that way. You could also have a function that takes an item object and returns a hash value. If you want to use standard containers then you would need to make it an external function and give that function to the container upon creation.

NathanOliver 429 Veteran Poster Featured Poster

Making things private vs protected deal with what access inherited classes have to members.

Public: everything has access to it.

Protected: Only acessible from the class or classes dervied from the class.

Private: Only accessible from the class.

NathanOliver 429 Veteran Poster Featured Poster

The callback function is used to store the results of the query into a 2d char array. This explains how to use the execute function and what the parameters are.

NathanOliver 429 Veteran Poster Featured Poster

Did you read this site? From the looks of it you need to create a connection with sqlite3_open() then pass that connection with a sql string to sqlite3_prepare() and it will give you a statement. You can use that statement with sqlite3_step() to step through each row of the results and use sqlite3_column() to grab each column from the row.

NathanOliver 429 Veteran Poster Featured Poster

@ dinad578 do not give answers to homework questions when the OP made no attempt at all to solve the problem.