Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Halp plz, C++

Name: Anonymous 2007-11-28 10:39

Hi /prog/, I have a problem...

I'm a noob at C++ (I learned it at school, so, yeah...) and I've got to make a program, which I find pretty difficult. i'm coming here seeking your help because I NEED a good grade if I want to validate my semester, and programming is highly coefficiented, so if you don't help me, i'm pretty much fucked...

So here's the deal:

Make a program which allows the input of a serie of integers and stocks them in a table, then display the table as it is and then display the table with the numbers sorted out in growing order...

I am a total noob at C (as I already mentioned) and I have no fucking clue about how to do this kind of shit.

So your help would be really, really, REALLY appreciated...
Pretty please?

Name: Anonymous 2007-11-28 17:18

>>1
If I were you I wouldn't insult >>2, the answer he gave you was very helpful. Now, stop being brain-atrophied and learn how to think by yourself.

I am a total noob at C (as I already mentioned) and I have no fucking clue about how to do this kind of shit.

DA TEACHAR DIDN TEL ME HOW 2 DU DIS BUT I NO TEH TEORI TO LURN BY MYSELF OW 2 DO IT

how to sort arrays in a simple way for retarded dumbfucks :
Make an other array(newarray)
Get the biggest value of the array
in a loop in which i is the count, starts at 0 and stops when i is not smaller than the length of the array
{
Get the smallest value of the array and put it in newarray[i] then set array[i] to a bigger value than the biggest one
}
and return the new array

I just did everything for you, faggot.

http://en.wikipedia.org/wiki/Quicksort
http://en.wikipedia.org/wiki/Bubble_sort
http://en.wikipedia.org/wiki/Selection_sort

Name: Anonymous 2007-11-28 17:18

>>35
by table I meant 'un tableau' that is, something like a list or a table in which you can put numbers and stuff

Name: Anonymous 2007-11-28 17:19

Learn to fucking indent, I'll check it then.

Name: Anonymous 2007-11-28 17:24

>>41
I apologize to >>2, if I seemed rude (I probably was) it was only because I had a shitty day, blablabla personal life you don't care about. I know, I overreacted, and again, I apologize humbly.

Then, I don't know what arrays are (maybe they are what i call table, that would be horrible, but as I don't know the exact terms it is possible)




Holy shit, I just understood your post, for serious...

I'm baffled... O_O;;

Name: Anonymous 2007-11-28 17:32

Oh well, I'm off to bed, I can't even think clearly anymore.

Goodafternoon everyone

Name: Anonymous 2007-11-28 17:45

>>40
What the fuck?

That's hideous. Seriously, everything is wrong about that.

Name: Anonymous 2007-11-28 18:11

>>44
array = tableau
>>40
Hideous use what I answered in >>41

Name: Anonymous 2007-11-28 18:48

Fucking die in a fire you good-for-nothing fucking french faggot.

#include <iostream>
#include <vector>
#include <algorithm>

typedef NumT int;
typedef std::vector<NumT> ListT;

void print_list( const ListT& list ) {
    for ( ListT::const_iterator i = list.begin();
        i != list.end(); ++i )
        std::cout << *i << " ";
}

int main( int argc, char* argv[] ) {
    ListT list;   
    while( std::cin.good() ) {
        NumT tmp;
        std::cin >> tmp;
        list.push_back( tmp );
    }

    print_list( list );
    std::cout << std::endl;
    std::sort( list.begin(), list.end() );
    print_list( list );
}

Name: Anonymous 2007-11-28 19:22

HHAHAHA I LOVE THIS FRENCHY GUY ~♀~

Name: Anonymous 2007-11-28 19:43

>>48
"yup, still haven't solved my problem (link provided by >>16 was helpful, but I can't use it, because we're supposed to use for, while, if and table [i.e. arrays] only (sorry I didn't mention it firsthand))."

Name: Anonymous 2007-11-28 20:01


class Class {
  public static void main(String[] args) {
    ArrayList<Integer> a = new ArrayList<Integer>(1000);
    for (i : a) {
      i.add(Math.random() * Integer.MAX_VALUE);
    }
    System.out.println(a);
    mergesort(a);
    System.out.println(a);
  }
  //The rest of this code isn't even mine
    public static ArrayList<Integer> mergesort(ArrayList<Integer> numbers) {
        if (numbers.size() <= 1)
            return numbers;
        int middle = numbers.size() / 2;
        ArrayList<Integer> left = new ArrayList<Integer>();
        ArrayList<Integer> right = new ArrayList<Integer>();
        for (int i = 0; i < middle; i++)
            left.add(numbers.get(i));
        for (int i = middle; i < numbers.size(); i++)
            right.add(numbers.get(i));
        left = mergesort(left);
        right = mergesort(right);
        return merge(left,right);
    }
 
    public static ArrayList<Integer> merge(
            ArrayList<Integer> left, ArrayList<Integer> right) {
        ArrayList<Integer> result = new ArrayList<Integer>();
        while (left.size() > 0 && right.size() > 0) {
            if (left.get(0) < right.get(0)) {
                result.add(left.get(0));
                left.remove(0);
            } else {
                result.add(right.get(0));
                right.remove(0);
            }
        }
        if (left.size() > 0) {
            for (int i = 0; i < left.size(); i++)
                result.add(left.get(i));
        }
        if (right.size() > 0) {
            for (int i = 0; i < right.size(); i++)
                result.add(right.get(i));
        }
        return result;
    }
}

Name: Anonymous 2007-11-28 21:05

>>50
Oh, snap.

WELL I GUESS I'M A STUPID FAGGOT TOO FOR NOT CORRECTLY READING THE FUCKING QUESTION.

Name: Anonymous 2007-11-28 21:26

ITT: A future ENTERPRISE QUALITY PROGRAMMER who will specialize in web 2.0 modular extensible user-friendly deliverables.

Name: Anonymous 2007-11-28 23:40

GTFO. /prog/ is not your personal codemonkey.

Name: Anonymous 2007-11-29 12:55

hi everyone, it's me again!

About the code posted yesterday, i know it's shit, but I didn't care at the time because, well, strangely enough it worked, so I was content with it.

This morning, during the lesson, we worked on it (because noone had been able to find it), and we finally figured out how to do it.

So here it is, enjoy:

#include <stdio.h>
#include <math.h>
#include <conio.h>

main()
{
      int i,j,taille,b;
     
      printf("entrez la taille du tableau");
      scanf("%d",&taille);
      int tab[taille];
      printf("entrez %d valeurs",taille);
      for(i=1,i<=taille,i++)
      {
            scanf("%d",&tab[i]);
      }
      for(i=1,i<=taille,i++)
      {
            printf("%d",tab[i]);
      }
      for(i=1,i<=taille,i++)
      {
            for(j=1,j<=taille,j++)
            {
                    if(tab[i]<tab[j])
                    {
                          b=tab[i];
                          tab[i]=tab[j];
                          tab[j]=b;
                    }
            }
      }
      for(i=1,i<=taille,i++)
      {
            printf("%d",tab[i]);
      }
}

Well?

Name: Anonymous 2007-11-29 13:00

Since when do indexes begin at 1, faggot?

Name: Anonymous 2007-11-29 13:00

>>55
Not bad

Name: Anonymous 2007-11-29 13:06

>>56
I know they don't, it simply is easier that way. I told you I am not an advanced coder.

>>57
Thank you. Do you see any way in which it could be improved? (I'm sure you do, however, I understand if you don't care enough to post it and just let the thread die.

>>49
I love you too.

Name: Anonymous 2007-11-29 13:08

>>55
>>56 said it. Your code is broken. Otherwise, not bad. Separate the sorting part to a function, though.

Name: Anonymous 2007-11-29 13:12

>>59
We're going to see functions next week actually

Name: Anonymous 2007-11-29 13:15

>>60
Wow, they are deliberately TEACHING you to write spaghetti code from early on?

Name: Anonymous 2007-11-29 13:20

>>61
Well, yes they are. What i wrote in >>55 was the best code we ever wrote, but then again, I'm not in a programming school, it's just part of my cursus, and there is 90% chance that I won't use it when I leave the institute.

Name: Anonymous 2007-11-29 13:39

Thank god for that

Name: Anonymous 2007-11-29 13:44

int tab[taille];
...
for(i=1,i<=taille,i++)

Epic failure.

Name: Anonymous 2007-11-29 14:34

>>55
Lis le SIPI et deviens un PROGRAMMEUR EXPERT.

Name: Anonymous 2007-11-29 20:26

>>55
YOUR CODE IS NOT VALID ANSI C YOU FUCKING FAGGOT

     for(i=1,i<=taille,i++)
     {
           scanf("%d",&tab[i]);
once i = taille you will get a segfault

#include <stdio.h>
#define WITHEVERYELEMENT(count,length) for(count=0;count<(length);count++)

void sortArray(int *, int);

int main(int argc, char **argv)
{
    int longueur = 0;
    int * valeurs = NULL;
    int i = 0;
    int count = 0;
    printf("Entrez la taille du tableau : ");
    scanf("%i", &longueur);
    if(longueur<=0) exit(0);
    valeurs = malloc(sizeof(int) * longueur);
    WITHEVERYELEMENT(i,longueur)
        scanf("%i",&valeurs[i]);
    WITHEVERYELEMENT(i,longueur)
        printf("%i ",valeurs[i]);
    printf("\n\n");
    sortArray(valeurs,longueur);
    WITHEVERYELEMENT(i,longueur)
        printf("%i ",valeurs[i]);
    free(valeurs);
    return 0;
}


void sortArray(int * tableau,int longueur)
{
    int i = 0;
    int j = 0;
    int ind = 0;
    int * buffer = malloc(sizeof(int) * longueur);
    int maxVal = 0;
    int minVal = 0;
    WITHEVERYELEMENT(i,longueur)
        buffer[i] = tableau[i];
    WITHEVERYELEMENT(i,longueur){if(maxVal < tableau[i])maxVal=buffer[i];}
    WITHEVERYELEMENT(i,longueur)
    {
        minVal = buffer[0];
        ind = 0;
        tableau[i] = buffer[0];
        WITHEVERYELEMENT(j,longueur)
        {
            if(minVal>buffer[j])
            {
            tableau[i] = buffer[j];
            minVal = buffer[j];
            ind = j;
            }
        }
        buffer[ind] = maxVal;
    }
    free(buffer);
}


Name: Anonymous 2007-12-02 0:00

I think its stupid

Name: Anonymous 2007-12-02 16:01

>>1
I've got to make a program, which I find pretty difficult.

Name: Anonymous 2007-12-03 4:55

>>40
isn't it plain C?

Name: Anonymous 2007-12-03 5:33

#define WITHEVERYELEMENT(count,length) for(count=0;count<(length);count++)
Ugh.

Name: Anonymous 2009-03-18 2:33

I'm feeling really keen, for some of that good ol' green

Marijuana MUST be legalized.

Name: Trollbot9000 2009-07-01 8:29

O fix that bug.

Name: Anonymous 2011-02-04 15:14


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List