NathanOliver 429 Veteran Poster Featured Poster

Are you using Visual Studio 2012? I don't know of a Visual Studio 12 unless you are talking about version 12. If you go to Help -> About you will get a window like the attached. Post it here.

NathanOliver 429 Veteran Poster Featured Poster

What compiler are you using? MSVS 2013 does not have an issue with it. Also if you want to intialize number with 4 using braces you would use int number{4};

NathanOliver 429 Veteran Poster Featured Poster

@iamthewee The OP's function uses var and val. I don't think it would compile if they had the same name. I think that would be a type redeclaration error.

NathanOliver 429 Veteran Poster Featured Poster

Well << is the shift bits to the left operator. Since the default value for FOO_ENUM is 0 you get:

unsigned char sideFilter1 = 1 << FOO_ENUM;
=unsigned char sideFilter1 = 1 << 0;
=unsigned char sideFilter1 = 1;
since 1 left shift 0 is still 1.

Line 4 is a little trickier since you are also using |. | simple says that all bits that are 1 in either number will be 1 in the result. this means 1000 | 1001 becomes 1001. With that line 4 becomes:

unsigned char sideFilter2 = (1 << FOO_ENUM) | (1 << BAR_ENUM);
=unsigned char sideFilter2 = (1 << 0) | (1 << 1);
=unsigned char sideFilter2 = (1) | (2);
// next 2 lines are showing bit representation.
=unsigned char sideFilter2 = (00000001) | (00000010);
=unsigned char sideFilter2 = 00000011;
unsigned char sideFilter2 = 3;
Jsplinter commented: Thank you for the clear explanation. +2
NathanOliver 429 Veteran Poster Featured Poster

Are you trying to enter a name like "Nathan Oliver"? if so you need to use getline() and not >>. Don't forget to flush the input stream when mixing getline() and >>

NathanOliver 429 Veteran Poster Featured Poster

When I read an unknown amount of data from a file I will use the following

std::vector<int> data;
ifstream fin("sampleData.txt");
int temp;  // used to store the data from the file temporarily

//use >> operator to control the loop so you end on the last good read
while (fin >> temp)
{
    data.push_back(temp);
}

Alternatively you can use std::copy and istream iterators

std::vector<int> data;
ifstream fin("sampleData.txt");

std::copy(std::istream_iterator<int>(fin), std::istream_iterator<int>(), std::back_inserter(data));
NathanOliver 429 Veteran Poster Featured Poster

Line 35 should use rowSize not colSize. This is because you are stepping through each row and deleting all of the columns.

NathanOliver 429 Veteran Poster Featured Poster

If you call transform on both haystack and needle and have them both lower case then it should work.

NathanOliver 429 Veteran Poster Featured Poster
do
{
    your_homework();
} while (in_school)
NathanOliver 429 Veteran Poster Featured Poster

@ tinstaafl You wouldn't write a function like void push (stack *, std::string) if the function is a member of the class. You would write it like void push (std::string) and externally it would be void stack::push (std::string)

NathanOliver 429 Veteran Poster Featured Poster

Since you are dealing with strings shouldn't ostream_iterator<int> output(cout," "); be ostream_iterator<string> output(cout," ");?

NathanOliver 429 Veteran Poster Featured Poster

This would be the simplest way I can think of to do it.

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string info = "R Y, 123-45-6789, ya123, abcd1234";
    // social starts 2 places after the first coma
    size_t ssStart = info.find_first_of(",", 0) + 2;
    info.erase(ssStart, 11);
    info.insert(ssStart, "XXX-XX-XXX");

    // password starts 1 place after the last space
    size_t passStart = info.find_last_of(" ") + 1;
    size_t passSize = info.size() - passStart;
    // get rid of the password
    info.erase(passStart);
    // make a string with all X's the size of the password and ad it to the end
    info += string(passSize, 'X');
    cout << info;
    cin.get();
    return 0;
}

All done in 24 lines with comments and blank lines(fist pump).

NathanOliver 429 Veteran Poster Featured Poster

Okay, lets break this down a little. If we want to print the backwards Z and we have a nested for loop like you have what are the conditions of i and j that would print an X

   jjjjj
   01234
i0 XXXXX
i1  X      
i2   X    
i3    X  
i4 XXXXX

From the above picture we can see that if i == 0 or i == 4 print X so that coves the top and bottom rows. Now to get the diagonal you can see that i and j equal each other where there is an X so that would be if i == j print X. So to pat that all together we get (this is pusedo code):

for i = 0 to i == 4
    for j = 0 to j == 4
        if i == 0  or i == 4 print "X"
        else if i == j print "X"
        else print " "

For printing the normal Z the first if is still code but wee need to change the second one.

   jjjjj
   01234
i0 XXXXX
i1    X    
i2   X    
i3  X    
i4 XXXXX

From the above we can see a patter amerge with when to print an X. The X's are at (i, j): (1, 3) , (2, 2) , (3, 1). If you add the pairs for each one of those you get 4 so you would have an if like if i + j == 4 print …

NathanOliver 429 Veteran Poster Featured Poster

This is how I would structure the code. If you are going to use OO principles then use them fully.

class Student
{
private:
    string lastName;
    string firstName;
public:
    /// default constructor
    Student() {}
    /// default destructor
    ~Student() {}
    /// getter functions
    string getLastName() const { return lastName; }
    string getFirstName() const { return firstName; }
    /// setter functions
    void setLastName(string ln) { lastName = ln; }
    void setFirstName(string fn) { firstName = fn; }
};

Then you need a classroom that will hold on to the students and where the classroom is located. The classroom should have functions to add and remove a student and also a way to acess the vector so you can get a list of all of the students in the class room. You will need your standard setters and getters as well. I'll leve that for you to code.

class ClassRoom
{
private:
    int floor;
    int roomNumber
    vector<Student> students;
public:
    //...
};

Then your school class will hold a 2D vector of of classrooms.

class School
{
private:
    int floors;
    int rooms;
    vector<vector<ClassRoom>> classRooms;
public:
    /// constructor
    School(int _floors, _int rooms, int seats)
    {
        floors = _floors;
        rooms = _rooms;
        // make the floors
        classRooms.resize(floors);
        // step through each floor and set the rooms
        for (int i = 0; i < floors; i++)
        {
            classRooms[i].resize(rooms);
        }
        // step through each classroom and set the room and floor
        for (int i = 0; i < floors; i++)
        {
            for (int …
NathanOliver 429 Veteran Poster Featured Poster

You can use cout to debug. Just output parts that are questionable or you are not sure what the value is. You don't need to actually step through a debugger to debug code.

NathanOliver 429 Veteran Poster Featured Poster
if (!(assignment == complete))
    if (today > dueDate)
        return failure;
    else
        output << "Get working on your code.  We only give help to those that show effort and code!!"
ddanbe commented: Witty! +15
NathanOliver 429 Veteran Poster Featured Poster

That doesn’t make operator overloading bad. Even Java has certain types that have operator overloads because it is so natural for that type. Take string for example. The + operator works with it even though it shouldn’t since there is no operator overloading in the language. If anyone ever gave me code with Strawberry operator+(Apple a, Orange b) in it I wouldn’t blame the language, I would fire the programmer.

NathanOliver 429 Veteran Poster Featured Poster

Change

while(std::getline(fin,line))
{
    for(i=0;i<line.length();i++)
    {
        line.substr(0,'32');


    }
    cout<<line<<endl;

}

To

while(std::getline(fin,line))
    cout << line.substr(0, line.find_first_of(" ", 0)) << endl
NathanOliver 429 Veteran Poster Featured Poster

I can vouch that iamthewee knows what he is doing with c++. Think about your system. You normally have different types of transportation in any fleet do you need a base bus class and then you can derive from there the different kinds of buses that you have. You need a passanger class for the passengers of the bus. you normally have different types of passengers like first class, business class, and coach so passenger could be a base and you can derive from there for each type of passenger. The passenger base / children work well for polymorphism since your bus classes would hold a pointer to the base class and you can use virtual functions to handle the dynamic dispatching. This is all just off the top of my head so there is probably more you can do.

NathanOliver 429 Veteran Poster Featured Poster

Hate to burst your bubble but according to your guidelines you are to late to submitt this. What kind of idea do you need to start this? The sheet gave you three references you could use as a basis for your project.

NathanOliver 429 Veteran Poster Featured Poster

What have you done so far? What part of the problem dont you understand? You have to put in an effort if you want help.

OM3NN commented: hi +0
NathanOliver 429 Veteran Poster Featured Poster

Well you have a couple ways to approach this. If all of the forms connect back to a central server then the server can hold on to the reference number and everytime a new form is open it would increment the number by one. This way every form has a unique number. If that cant be done then you need to look into using some sort of GUID algorithm. Here is a wiki on GUID.

NathanOliver 429 Veteran Poster Featured Poster

You need a destructor for MyCon that frees the memory. Something like this should work.

~MyCon()
{
    delete [] matA
    delete [] matB
}
NathanOliver 429 Veteran Poster Featured Poster

Did you already ask this here? Schol-R-LEA and mike_2000_17 did a really go job explaining in that post.

NathanOliver 429 Veteran Poster Featured Poster

Nevermind. Deceptikon you beat me to it. I will say that you can make this work for sentences with more then 3 words using stringstreams and a vector.

NathanOliver 429 Veteran Poster Featured Poster

So what do you have so far? This site is not about giving it is about helping. If you put in the effort we will help you. help does not equal do.

ddanbe commented: Well said! +15
NathanOliver 429 Veteran Poster Featured Poster

All of your code is compiled by the compiler. As far as you loop question is concerned look at this:

for (int i = 0; i < 10; i++)
{
    for (int j = 0; j < 5; j++)
    {
        std::cout << j * i << std::endl
    }
}

The above cout statement will execute 50 times. The inner loop executes 5 times for every loop of the outer loop. Since the outer loop runs 10 times that gives you 10 * 5 = 50. So when calculating how many times the code in the inner loop will run you take the number of times the outer loop runs and multiply it ny the number of times the inner loop runs. This holds true when adding any number of nested loops. If you have this:

for (int i = 0; i < 10; i++)
{
    for (int j = 0; j < 5; j++)
    {
        for (int k = 0; k < 20; k++)
        {
            for (int l = 0; l < 15; l++)
            {
                std::cout << "inner most loop executed" << std::endl
            }
        }
    }
}

The cout statement will run 15,000 times. You multiply all of the numbers of times each loop runs and you get 10 * 5 * 20 * 15 = 15,000

NathanOliver 429 Veteran Poster Featured Poster

There was a thread that I participated in a few years back and maybe you will get some insight from it. It was a natural string comparison challenge by Narue. As an FYI I wouldn't post anything to that thread since it so old. http://www.daniweb.com/software-development/cpp/threads/259447/c-challenge-natural-sorting

NathanOliver 429 Veteran Poster Featured Poster

You could pipe the cmd text to a file and then parse that file for the information that you need.

NathanOliver 429 Veteran Poster Featured Poster

Okay. Now what?

NathanOliver 429 Veteran Poster Featured Poster

Try this and let me know If you get the second cout statement

#include <iostream>
using namespace std;

class A
{
private:
   int _dmember;

public:
   void func()
   {
     cout<<"Inside A!! "<<endl;
     cout<<_dmember; // 
   }
};

int main ()

{

    A *a=NULL;

    a->func(); // prints "Inside A!!!" 

    cout << "We are now outside a->func().  If you can see this then your program didnt crash

    return 1;
}
CoolAtt commented: yes it crashed +2
NathanOliver 429 Veteran Poster Featured Poster

@Tumlee I know there is one for strings but it does not have a way to control how many characters are received in. The getline for char* does have that ability though.

NathanOliver 429 Veteran Poster Featured Poster

Have you ever used getline()? you would have to use a char* but it should work nicely.

NathanOliver 429 Veteran Poster Featured Poster

No you can not overload ::. Why would you want to?

NathanOliver 429 Veteran Poster Featured Poster

You need to do the work. We will not do it for you. What code have you written so far?

NathanOliver 429 Veteran Poster Featured Poster

Well the problem you are having is you are not doing what the assignment asks. When you add to the letter if you exceed the bounds of the character set you need to wrap around to the beginning. You also don't want to modify anything that isn't a character. All you are doing is adding the rotation value to the letter. As a hint I'll give you a way to add to a letter and if past 'z' or 'Z' it will start over at 'a' or 'A' respectivly.

int rot = 4;
char ch = 'W';

if (ch >= 'a' && ch <= 'z')
    ch = (((ch + rot) < 'z') ? ch + rot : 'a' + ((ch + rot) - 'z' - 1));
else
    ch = (((ch + rot) < 'Z') ? ch + rot : 'A' + ((ch + rot) - 'Z' - 1));
NathanOliver 429 Veteran Poster Featured Poster

Why are you looking for spaces in a csv file? csv stands for comma seperated values. Your file should look like

1.1,1.2,1.3
2.1,2.2,2.3
...
NathanOliver 429 Veteran Poster Featured Poster

Well if the map is set up like this:

map<"user-id", map<"movie-id", "rating">

Then if you want to see how many movies a person has rated you could do this:

std::map<int, map<int, int> > m;

// add stuff to m

int numberOfMoviesRated = m["some-user-id"].size();

In the above example the call to size calls the size function of the map for that particular user id. If you want to see all of the movies and ratings then you could do this:

std::map<int, map<int, int> > m;

// add stuff to m

for (auto it = m["some-user-id"].begin(); it != m["some-user-id"].end(); ++it)
{
    std::cout << "movie id: " << it->first << "\trating: " << it->second << std::endl;
}
nitin1 commented: awesome!! short, concised, well explained!! +3
NathanOliver 429 Veteran Poster Featured Poster

A should actually look like this

if (x == 0) then     //constant (1)
  for i = 1 to n do // linear(n)
       a[i] = i; //constant (1)

Resenje:
T(n) = O(1) + O(n) * O(1) = O(n)

B should look like this

i = 1; //constant (1)
repeat
    a[i] = b[i] + c[i]; //constant (1)
    i = i +1;  //constant (1)
until (i == n); // linear(n)

T(n) = O(1) + O(1) * O(n) = O(n)
NathanOliver 429 Veteran Poster Featured Poster

Yes what you came up with is correct. If you want to write it in big-O notation it would be O(n).

NathanOliver 429 Veteran Poster Featured Poster

@ nitin1

std is a namespace that all of the standard c++ functions and classes are in. A namespace is just another level of orginizing your code. You can equate it to the file cabinet metaphor. The function is a piece of paper. The file the function is in is a folder. The namespace is the drawer that the folder is in. Your project is the file cabinet that contains it all.

nitin1 commented: awesome metaphor!! +3
NathanOliver 429 Veteran Poster Featured Poster

Do you know the STL? If not check this out.

NathanOliver 429 Veteran Poster Featured Poster

Just as an FYI. If you call erase on a vector and you are using iterators any iterator that is after the begining will be invalidated.

NathanOliver 429 Veteran Poster Featured Poster

I would suggest using something other than graphics.h. it is not supported by any modern compilers and it will only work in a dos enviroment.

NathanOliver 429 Veteran Poster Featured Poster

what compiler are you using? if you are using msvc++ you have to pick a win32 console application.

NathanOliver 429 Veteran Poster Featured Poster

You are trying to initialize a 2d array when you onlty declared a 1d array. You can change it to

char arrayOnes[][10] = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}

If you can use strings I would suggest doing this

std::string arrayOnes[10] = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}
NathanOliver 429 Veteran Poster Featured Poster

do you know the % operator? do you know how to use an loop? do you know how to use an array? those are really all you need to figure this out.

NathanOliver 429 Veteran Poster Featured Poster

I am amazed that people don’t even try to Google for an answer. Most of the time the first page has the answer and so much more.

NathanOliver 429 Veteran Poster Featured Poster

You can use the same method. Instead of using cin you would use the file stream you create.

ifstream fin("testfile.txt");  //create ifstream object to read the file
string line;
vector<string> fileContents;

while(getline(fin, line))
    fileContents.push_back(line);

As you can see from the above example fin is the file stream to read from the file. fileContents is a vector that will store each line of the file. The while loop uses the return value from getline to know if a line was read from the file. If the getline operation fails the loop stops and nothing more is read from the file. Inside the while loop the contents of the variable line are then added to the back of the vector.

If you want a good reference site I would suggest visiting cplusplus.com. They have a lot of tutorials and references. And of course if you have problems come back here and someone should be able to help.

furalise commented: Excellent answer. Thanks for the help. +0
NathanOliver 429 Veteran Poster Featured Poster

@ sanyam.mishra char* argv[FILENAME_MAX] is an array of pointers so it is a 2d array.

@ DarrelMan have you walked through the code with the debugger to see what is inside argv[0]? If you dont know how to step through the code with the debuger you could just output the contents of argv[0] to the console using a cout statement. That should at leat tell you what you have. it could be there is a slight mismatch.