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

I have a questions for you. Why does Players have a size of 1000 when you only need 128?. If you post the full code I can step through it with my debugger and see what is going on.

NathanOliver 429 Veteran Poster Featured Poster

@ Rajeev Kumar_1: how is operator overloading bad?

NathanOliver 429 Veteran Poster Featured Poster

Learner010: The string objects size is only going to give you the number of alphanumeric characters in the string. It is not going to count the null at the end since it handles it for you. In the following block of code why are you subtracting 3 from the size of the line?

while(getline(readob,line))
{
    i=line.size()-3;
    for(; i < line.size(); i++)
    {
        char c;
        c=line[i];
        total += c - '0';
    }
}

If you are trying to get the last three digits from each line you need to do this

while(getline(readob,line))
{
    // set temp to a substring of line starting from  3 back from the end
    for(int i = 0, string temp = line.substring(line.size() - 3); i < 3); i++)
    {
        char c;
        c = temp[i];
        total += c - '0';
    }
}
NathanOliver 429 Veteran Poster Featured Poster

Well if you have why Java doesnt then that answers the question. Think of it as "Why does Java not support operator overloading?".

NathanOliver 429 Veteran Poster Featured Poster

A char is an intergal type. That does not mean that a char is an int but it is of a type that will be implicitly converted to an int. 50-'0'=50 is not correct. What it is saying is take 50 and subtract the value of that char '0'. In ascii '0' = 48 so it becomes 50 - 48 = 2. The reson we right it as total += c - '0' is because if you are on a system that uses a charecter code other than ascii this will still work. the character '0' will always come before '1' in the code set so '1' - '0' = 1 (integer).

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 would read in the entire line and then break it up.

string line;
int total = 0;

ifstream fin("file.txt");

while (getline(fin, line))  // get the line
{
    // loop by three
    for (size_t i = 0; i < line.size() i += 3)
        total += atoi(line.substr(i, 3).c_str()); // get the substring and convert to int
}
NathanOliver 429 Veteran Poster Featured Poster

Well you need to do error checking in your program to make sure the input file opened. You could do this

ifstream inFile("TEST.dat");
if (!inFile)
{
    std::cout << "Error with input file!"
    return 0; // exit program
}
NathanOliver 429 Veteran Poster Featured Poster

ifstream in("TEST.dat"); on lines 49 and 70 needs to be just one decleration done before the switch statement.

NathanOliver 429 Veteran Poster Featured Poster

Given

SPLINKS contains:

1 3 4

abcmap contains;

1=> 1

2=> 2 6

3=> 1 2 4

What should the results be when the operation is finished?

Maybe this?

SPLINKS contains:

1 4

abcmap contains;

1=> 1

2=> 

3=> 1 4
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

No. We dont just give code. show us what code you have and what is wron with it and we can help you with that.

NathanOliver 429 Veteran Poster Featured Poster

how can you swap 5 numbers? What are the exact reqiurements for the assignment?

NathanOliver 429 Veteran Poster Featured Poster

What do you have so far? Do you know what a pointer is? We only help people that show effort. If you dont show your code you dont get code.

NathanOliver 429 Veteran Poster Featured Poster

@AD If I run the following code that you said to use I get the following output from the array. This is using the sample set of data the OP provided.

59 54 40 79 38 
77 71 74 91 56 
51 36 98 29 41 
52 3 24 5 4 
15 55 40 56 23 
69 13 37 96 54 
29 29 30 99 35 
64 6 6 56 80 
89 -858993460 -858993460 -858993460 -858993460 
-858993460 -858993460 -858993460 -858993460 -858993460 
-858993460 -858993460 -858993460 -858993460 -858993460 
-858993460 -858993460 -858993460 -858993460 -858993460 

This is the code I used to get that.

#include <iostream>
#include <fstream>
#include <sstream>

using namespace std;

int main()
{
    ifstream myfile("test.txt");
    ofstream fout("output.txt");

    std::string line;
    int nums[12][5];
    int row = 0;
    int col = 0;
    while(getline(myfile,line,','))
    {
        nums[row][col] = atoi(line.c_str());
        col++;
        if(col > 5)
        {
            col = 0;
            row++;
        }
    }
    for (int i = 0; i < 12; i++)
    {
        for (int j = 0; j < 5; j++)
            fout<< nums[i][j] << " ";
        fout << endl;
    }
    cin.get();
}

If I run my version of the code changed to use a 2d array I get

59 54 40 79 38 
28 98 77 71 74 
24 91 56 82 51 
74 36 98 29 41 
39 10 52 3 24 
30 5 4 70 15 
29 55 40 56 23 
8 94 69 13 37 
79 96 54 53 29 
12 29 30 99 35 
63 87 64 6 6 …
NathanOliver 429 Veteran Poster Featured Poster

If you are going a comparision which i think you are since you are returning a bool you need to change this:

bool operator=( const PCB& other )
{
    return other.getTau() = this->getTau();
}

To

bool operator ==( const PCB& other )
{
    return other.getTau() == this->getTau();
}
NathanOliver 429 Veteran Poster Featured Poster

Since the file is formatted like

59,54,40,79,38
28,98,77,71,74

Will that getline work? What happens when it hits the newline between 38 and 28 since you overwrite the default delimiter?

NathanOliver 429 Veteran Poster Featured Poster

They are for getting input and pushing out output. cin is a input stream object and if you use cin >> someVariable you can think of it as from cin put value into someVariable. cout is a output stream and when you write cout << someVariable you can think of that as put someVariable into the output stream.

NathanOliver 429 Veteran Poster Featured Poster

@AD What does line 7 do? I have never seen that.

NathanOliver 429 Veteran Poster Featured Poster

I would think you should be able to do this. I have not tested this.

// main always returns an int so dont forget to change this
int main()
{
    std::stringstream ss;
    std::string line;
    std::fstream fin("somefile.txt");
    std::vector<int> numbers;
    // read each line from the file
    while(std::getline(fin, line)
    {
        std::string temp;
        //load the line into the stringstream
        ss >> line;
        // get each number from the stream using the comma as the delimiter
        while(std::getline(ss, temp, ','))
        {
            // add number to vector
            numbers.push_back(strtod(temp.c_str(), nullptr));
        }
        // dont forget to clear out the stringstream for the next use
        ss.str(std::string());
        ss.clear();
NathanOliver 429 Veteran Poster Featured Poster

Oops my Bad. Thanks for fixing my mistake nullptr.

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 with the struct that you have and the way the file is formatted I would use the following approach.

int main()
{
    ifstream ifsSubor;
    ifsSubor.open("vstup.txt");
    string sRiadok;
    vector<OSOBA> osoby;
    double bod;
    OSOBA o;
    stringstream ss;
    while(getline(ifsSubor, sRiadok))  // use getline to control loop instead of eof()
    {
        ss << line;  // load line into strinstream
        ss >> o.meno;  // get surname
        ss. >> o.priezvisko;  // get first name
        while (ss >> bod)  // while there are points left in ss add them to body
        {
            o.body.push_back(bod);
        }
        osoby.push_back(o);
    }
    //...
NathanOliver 429 Veteran Poster Featured Poster

What does the data in the file look like?

NathanOliver 429 Veteran Poster Featured Poster

Well I gave you a solution for the problem you asked for. You can't keep changing the goal post as iamthwee has said. I'll leave it to you to figure out how change it to work for a 2d array.

NathanOliver 429 Veteran Poster Featured Poster

Well the different choices are for which clock to use. CLOCK_REALTIME uses the full system time. CLOCK_PROCESS_CPUTIME_ID uses the time in the process and CLOCK_THREAD_CPUTIME_ID uses the time from the thread. If you have c++11 I would really suggest using the high resolution clock from the chrono header.

NathanOliver 429 Veteran Poster Featured Poster

if you have a compiler that support c++11 check this out. It will show you how to use the high resolution clock available in c++11.

NathanOliver 429 Veteran Poster Featured Poster

If all you want to do is to change the zeros in a column to 99 if all of he arrays have a zero in that column then you can do the following. this is psudeo code so it wont compile.

for i = 0 until i < arraysize
{
    if  not array1[i] && not array2[i] && not array3[i]
    then array1[i] = array2[i] = array3[i] = 99
}

Its as simple as that. Then if you need to get the index and run of the consecutive zeros then you can just use on of the arrays and check for the 99's. Something like the following should work

int index = 0, run = 0;
for i = 0 until i < arraysize
{
    if array1[i] == 99
    then 
        if run not equal to 0
        then {
            index = i;
            run++;
        }
        else
            run++
    }
    else
    {
        if run > 0
        then {
            cout << index << "\t" << run << endl;
            index = 0;
            run = 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

What is your definition of a digit? A number is a digit or is made of digits so I'm not sure what you are talking about.

NathanOliver 429 Veteran Poster Featured Poster

How are you outputting the time used? Line 31 just has cout << "\nUsed time : " <<endl;. Are you dealing with threads at all? Do youknow if the execution times should be consistent for each iteration of the outer loop?

NathanOliver 429 Veteran Poster Featured Poster

Can you show the actuall code you are using?

NathanOliver 429 Veteran Poster Featured Poster

Download the file called "ekiga-4.0.1.tar.xz". It is a tarball compressed with xz looseless file compression. in windows you can open it with 7-zip.

NathanOliver 429 Veteran Poster Featured Poster

If you want the time of the run of the inner loop for every iteration of the out loop you should be able to do this

//...
std::vector<std::pair<clock_t, clock_t>> loopTimes
for (int i = 0; i < N; i++)
{
    cloct_t begin = clock();
    for (int j = 0; j < X; j++)
    {
        // do stuff
    }
    clock_t end = clock();
    loopTimes.push_back(std::make_pair(begin, end));
}

// get times
for (size_t i = 0; i < loopTimes.size(); i++)
{
    std::cout << "Sample " << i << ": " << (float)(loopTimes[i].first - loopTimes[i].second) / CLOCKS_PER_SEC << " Seconds\n"
}
NathanOliver 429 Veteran Poster Featured Poster

What part of the code dont you understand? Did you write this code? You should also look into indenting your code properly. The way you have it now makes it very hard to read. If I wrote this code it would look like this:

#include <iostream>  
using namespace std; 
int *growArray (int* p_values, int cur_size); 
int main ()
{  
    int next_element = 0;  
    int size = 10;  
    int *p_values = new int[ size ]; 
    int val; 
    cout << "Please enter a number: ";  
    cin >> val;  
    while ( val > 0 )  
    {  
        if ( size == next_element + 1 )  
        {    // now all we need to do is implement growArray    
            p_values = growArray( p_values, size );   
        }
        p_values[ next_element ] = val;   
        cout << "Please enter a number (or 0 to exit): ";   cin >> val;
    }  
} 

int *growArray (int* p_values, int cur_size) 
{
    int *p_new_values = new int[ cur_size * 2 ]; 
    for ( int i = 0; i < cur_size; ++i )
    { 
        p_new_values[ i ] = p_values[ i ];  
    } 
    delete p_values; 
    return p_new_values; 
}
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

On line 32 you have value = amp*sin(2*pi*freq*t). value is a float * so assigning amp*sin(2*pi*freq*t) to value makes no sense because value is a pointer which is an integer number. Now if you want to store the return into the float that value points to you need to do *value = amp*sin(2*pi*freq*t)

NathanOliver 429 Veteran Poster Featured Poster

???

NathanOliver 429 Veteran Poster Featured Poster

So what part are you having a problem with? We will not do your homework for you. Just posting the assignment without anything else is not the way things work on this site.

NathanOliver 429 Veteran Poster Featured Poster

You would need some sort of arbitrary precision library. The GNU MP Bignum Library is pretty good.

NathanOliver 429 Veteran Poster Featured Poster

Yes Java is multi-platform but that can misleading as well. Different java runtimes can produce different behavior. If you use something from a newer version of Java it might not work on some machines running an older runtime. I ran into this in my Java class.

jwenting commented: wrong -3
NathanOliver 429 Veteran Poster Featured Poster

What do you mean by they didn't work? You should be able to compile the following program on any standard compliant compiler.

#include <iostream>
#include <string>

int main()
{
    std::string helloWorld = "Hello World!";
    std::cout << helloWorld << std::endl;

    // to pause the program
    std::cin.get();
    return 0;
}
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

Ashley I would rewrite your last post as

void copy()
{
    string x;
    // do I still have input?
    if (cin >> x)
    {
        cout << x << endl
        copy();
    }
    // if no input remains return
    return;
}
NathanOliver 429 Veteran Poster Featured Poster

int arr_3d[4][3] means make an array with 4 rows and three columns. On line 9 you have {1, 2, 3, 4}. How many columns are in that row?

NathanOliver 429 Veteran Poster Featured Poster

What happens if you call peekfront() on an empty queue?