Recently enrolled in a C++ class...

Hey guys...

I don't mean to be a jacka$$ or a n00b or anything... but...

I've just gone back to school and I'm currently taking a C++ class for newbies. I've done a little C++, and I MEAN A LITTLE. Anyway, the instructor told us that we are to create a few projects allong the way.

What I was wondering is if any of you great people had any ideas for a program I could write. I'd like something relatively simple and something that would kinda surprise him. Oh, btw, there are 4 freshman, including me, 10-15 sophmores and the rest are juniors. I'm the only one that has any programming experience whatsoever.

So just present your ideas. I appreciate all replies and thoughts. Thanks :D
«1

Comments

  • One of the first programs I've written in c++ class was to reduce a fraction. 4/2 = 2 sort of thing. You could try to take a polynomial ex... 2x^2 + 8x + 8, and factor it, 2(x + 2)(x + 2).
  • : Hey guys...
    :
    : I don't mean to be a jacka$$ or a n00b or anything... but...
    :
    : I've just gone back to school and I'm currently taking a C++ class for newbies. I've done a little C++, and I MEAN A LITTLE. Anyway, the instructor told us that we are to create a few projects allong the way.
    :
    : What I was wondering is if any of you great people had any ideas for a program I could write. I'd like something relatively simple and something that would kinda surprise him. Oh, btw, there are 4 freshman, including me, 10-15 sophmores and the rest are juniors. I'm the only one that has any programming experience whatsoever.
    :
    : So just present your ideas. I appreciate all replies and thoughts. Thanks :D
    :

    #include
    void main()
    {
    float number;
    cout<<"Hello, there, enter a number:
    ";
    cin>>number;
    cout<<"You entered:"<<" "<<number;
    }
    program asks for number, user enters one, program prints it back.

  • [b][red]This message was edited by Darius at 2002-8-30 22:22:13[/red][/b][hr]
    [b][red]This message was edited by Darius at 2002-8-30 22:20:0[/red][/b][hr]
    Hopefully it's not an up to date C++ class beirowerri.

    [code]
    [red]//#include deprecated
    //should be
    #include [/red]

    [red]//you'll have to use namespace std with the new C++ Standard
    using namespace std;[/red]

    [red]//void main() this was NEVER standard
    //should be
    int main()[/red]
    {
    [red]/*
    * float number;
    * cout<<"Hello, there, enter a number:
    ";
    * cin>>number;
    * cout<<"You entered:"<<" "<<number;
    */

    /*
    * This lack of proper indenting would get you killed by a lot of
    * of programmers. Especially any who would have to maintain your code.
    * Also, might as well make it double.
    * Also #2, cout<<"You entered:"<<" "; is UTTERLY ridiculous
    */
    double number;
    cout<<"Hello, there, enter a number:
    ";
    cin>>number;
    cout<<"You entered: "<<number;
    return 0; //this isn't necessary (in C++ for main ONLY)[/red]
    }
    [/code]
    : program asks for number, user enters one, program prints it back.

    Well. Your braces made it through unscathed, though personally I like my opening braces on the same line, but that's just me.


    "We can't do nothing and think someone else will make it right."
    -Kyoto Now, Bad Religion








  • : Well. Your braces made it through unscathed, though personally I like my opening braces on the same line, but that's just me.
    :

    no, its me too.
  • I like the factoring idea...thanks :D

    ehre's some code i wrote a few days ago...i've debugged it quite a few times, ran through and made a few changes, but i have couple bugs.

    it seems you have to hit Ctrl+x several times before the program exits...i dont like that. i want it to quit after one Ctrl+x character, which is 24 in ASCII i beleive.

    take a look at my syntax and tell me what u think.

    // Converter
    // Converts standard characters to ASCII format.
    // Written by Spider]-[acker
    // Last updated 8/31/02
    // Version 1.0.0.2

    #include

    main()
    {
    int ch;
    int c;
    printf("-_-_- Converter -_-_-
    ");
    printf("Converts standard characters to ASCII format.
    ");
    printf("Written by Spider]-[acker
    ");
    printf("
    !!! Pressing more than one key before pressing enter will result
    in a malfunction. You will have to restart the program. !!!
    ");

    c=' ';
    printf("
    Please type a character to be converted to ASCII.
    ");
    printf("(Enter Ctrl+X twice as character to exit)
    ");
    while (c != 24) {
    ch = getc( stdin );
    printf("ASCII = %d
    ", ch);
    c = getc(stdin);
    putchar(c);
    }
    printf("
    Quitting program...");
    return 0;
    }
  • : I like the factoring idea...thanks :D
    :
    : ehre's some code i wrote a few days ago...i've debugged it quite a few times, ran through and made a few changes, but i have couple bugs.
    :
    : it seems you have to hit Ctrl+x several times before the program exits...i dont like that. i want it to quit after one Ctrl+x character, which is 24 in ASCII i beleive.
    :
    : take a look at my syntax and tell me what u think.
    :
    : // Converter
    : // Converts standard characters to ASCII format.
    : // Written by Spider]-[acker
    : // Last updated 8/31/02
    : // Version 1.0.0.2
    :
    : #include
    :
    : main()
    : {
    : int ch;
    : int c;
    : printf("-_-_- Converter -_-_-
    ");
    : printf("Converts standard characters to ASCII format.
    ");
    : printf("Written by Spider]-[acker
    ");
    : printf("
    !!! Pressing more than one key before pressing enter will result
    in a malfunction. You will have to restart the program. !!!
    ");
    :
    : c=' ';
    : printf("
    Please type a character to be converted to ASCII.
    ");
    : printf("(Enter Ctrl+X twice as character to exit)
    ");
    : while (c != 24) {
    : ch = getc( stdin );
    : printf("ASCII = %d
    ", ch);
    : c = getc(stdin);
    : putchar(c);
    : }
    : printf("
    Quitting program...");
    : return 0;
    : }
    :

    I thought this was a C++ class? Also, see my reply to beirowerri.

    [code]
    #include

    using namespace std;

    int main(){
    cout<<"Hit Ctrl-D to end on Linux or Ctrl-Z to end on Windows
    ";
    //These correspond to EOF. A note the Windows shell (command.com) may
    //act really funny.
    char c;
    while(cin>>c) cout<<"ASCII = "<<int(c)<<endl;
    return 0;
    }
    [/code]

    "We can't do nothing and think someone else will make it right."
    -Kyoto Now, Bad Religion

  • : [b][red]This message was edited by Darius at 2002-8-30 22:22:13[/red][/b][hr]
    : [b][red]This message was edited by Darius at 2002-8-30 22:20:0[/red][/b][hr]
    : Hopefully it's not an up to date C++ class beirowerri.
    :
    : [code]
    : [red]//#include deprecated
    : //should be
    : #include [/red]
    :
    : [red]//you'll have to use namespace std with the new C++ Standard
    : using namespace std;[/red]
    :
    : [red]//void main() this was NEVER standard
    : //should be
    : int main()[/red]
    : {
    : [red]/*
    : * float number;
    : * cout<<"Hello, there, enter a number:
    ";
    : * cin>>number;
    : * cout<<"You entered:"<<" "<<number;
    : */
    :
    : /*
    : * This lack of proper indenting would get you killed by a lot of
    : * of programmers. Especially any who would have to maintain your code.
    : * Also, might as well make it double.
    : * Also #2, cout<<"You entered:"<<" "; is UTTERLY ridiculous
    : */
    : double number;
    : cout<<"Hello, there, enter a number:
    ";
    : cin>>number;
    : cout<<"You entered: "<<number;
    : return 0; //this isn't necessary (in C++ for main ONLY)[/red]
    : }
    : [/code]
    : : program asks for number, user enters one, program prints it back.
    :
    : Well. Your braces made it through unscathed, though personally I like my opening braces on the same line, but that's just me.
    :
    :
    : "We can't do nothing and think someone else will make it right."
    : -Kyoto Now, Bad Religion
    :
    :
    :
    :
    :
    : It's good enough as a simple program. I don't perfect such programs.
    :
    :

  • : : [b][red]This message was edited by Darius at 2002-8-30 22:22:13[/red][/b][hr]
    : : [b][red]This message was edited by Darius at 2002-8-30 22:20:0[/red][/b][hr]
    : : Hopefully it's not an up to date C++ class beirowerri.
    : :
    : : [code]
    : : [red]//#include deprecated
    : : //should be
    : : #include [/red]
    : :
    : : [red]//you'll have to use namespace std with the new C++ Standard
    : : using namespace std;[/red]
    : :
    : : [red]//void main() this was NEVER standard
    : : //should be
    : : int main()[/red]
    : : {
    : : [red]/*
    : : * float number;
    : : * cout<<"Hello, there, enter a number:
    ";
    : : * cin>>number;
    : : * cout<<"You entered:"<<" "<<number;
    : : */
    : :
    : : /*
    : : * This lack of proper indenting would get you killed by a lot of
    : : * of programmers. Especially any who would have to maintain your code.
    : : * Also, might as well make it double.
    : : * Also #2, cout<<"You entered:"<<" "; is UTTERLY ridiculous
    : : */
    : : double number;
    : : cout<<"Hello, there, enter a number:
    ";
    : : cin>>number;
    : : cout<<"You entered: "<<number;
    : : return 0; //this isn't necessary (in C++ for main ONLY)[/red]
    : : }
    : : [/code]
    : : : program asks for number, user enters one, program prints it back.
    : :
    : : Well. Your braces made it through unscathed, though personally I like my opening braces on the same line, but that's just me.
    : :
    : :
    : : "We can't do nothing and think someone else will make it right."
    : : -Kyoto Now, Bad Religion
    : :
    : :
    : :
    : :
    : :
    : : It's good enough as a simple program. I don't perfect such programs.
    : :
    : :
    :
    :


    thats no good attitude. you dont perfect such programs, you just write them correctly. what are big programs gonna look like if you are even too lazy to care for correctness and style on such small ones?

  • : Hey guys...
    :
    : I don't mean to be a jacka$$ or a n00b or anything... but...
    :
    : I've just gone back to school and I'm currently taking a C++ class for newbies. I've done a little C++, and I MEAN A LITTLE. Anyway, the instructor told us that we are to create a few projects allong the way.
    :
    : What I was wondering is if any of you great people had any ideas for a program I could write. I'd like something relatively simple and something that would kinda surprise him. Oh, btw, there are 4 freshman, including me, 10-15 sophmores and the rest are juniors. I'm the only one that has any programming experience whatsoever.
    :
    : So just present your ideas. I appreciate all replies and thoughts. Thanks :D
    :

    Ignore all the other replies, here is a program that will really surprise your teacher.

    This program simulates a monkey randomly pressing keys on a typewriter and outputs it all into a number of text files. It is quite fast and generated approximately 11,000,000,000 characters in 48 minutes on my 1.3Ghz celeron.

    It may have some small errors but they should not be very hard to fix.

    enjoy...


    #include
    #include
    #include

    using namespace std;

    void main (void)
    {
    int i97 (97), j97 (33), random_number, file_number (1), file_total, text_number, text_total;
    float uni, u[98], c, cd, cm, temp;

    char filename[10];

    {
    int i, j, k, l, ii, jj, m, ij (int(time (NULL) % 10000));
    float s, t;

    i = (ij/177)%177 + 2;
    j = ij%177 + 2;
    k = (ij/169)%178 + 1;
    l = ij%169;

    for (ii=1; ii<=97; ii++) {
    s = 0.0;
    t = 0.5;
    for (jj=1; jj<=24; jj++) {
    m = (((i*j)%179)*k) % 179;
    i = j;
    j = k;
    k = m;
    l = (53*l + 1) % 169;
    if ((l*m)%64 >= 32) s += t;
    t *= 0.5;
    }
    u[ii] = s;
    }

    c = 362436.0 / 16777216.0;
    cd = 7654321.0 / 16777216.0;
    cm = 16777213.0 / 16777216.0;
    }

    cout << "
    Monkey Masher
    ";

    for (;;)
    {
    cout << "
    How many files do you wish to create?: ";

    cin >> file_total;

    if (file_total < 0)
    {
    cout << "
    ~ERROR~ Invalid number
    ";
    }
    else if (file_total == 0)
    {
    return;
    }
    else
    {
    break;
    }
    }

    for (;;)
    {
    cout << "How large do you want each file to be in bytes?: ";

    cin >> text_total;

    if (text_total < 0)
    {
    cout << "
    ~ERROR~ Invalid number

    ";
    }
    else
    {
    break;
    }
    }

    cout << "
    Processing:";

    for (; file_number <= file_total; ++file_number)
    {
    ofstream file (strcat (itoa (file_number, filename, 10), ".txt"), ios::out | ios::trunc);

    for (text_number = 0; text_number < text_total; ++text_number)
    {
    uni = u[i97] - u[j97];

    if (uni < 0.0) uni += 1.0;
    u[i97] = uni;

    i97--;

    if (i97==0) i97 = 97;
    j97--;

    if (j97==0) j97 = 97;
    c -= cd;

    if (c<0.0) c += cm;
    uni -= c;

    if (uni<0.0) uni += 1.0;
    temp = uni;

    random_number = (int (temp * 100) % 28);

    switch (random_number)
    {
    case 0:
    file << '
    ';

    ++text_number;

    break;

    case 1:
    file << 'a';

    break;

    case 2:
    file << 'b';

    break;

    case 3:
    file << 'c';

    break;

    case 4:
    file << 'd';

    break;

    case 5:
    file << 'e';

    break;

    case 6:
    file << 'f';

    break;

    case 7:
    file << 'g';

    break;

    case 8:
    file << 'h';

    break;

    case 9:
    file << 'i';

    break;

    case 10:
    file << 'j';

    break;

    case 11:
    file << 'k';

    break;

    case 12:
    file << 'l';

    break;

    case 13:
    file << 'm';

    break;

    case 14:
    file << 'n';

    break;

    case 15:
    file << 'o';

    break;

    case 16:
    file << 'p';

    break;

    case 17:
    file << 'q';

    break;

    case 18:
    file << 'r';

    break;

    case 19:
    file << 's';

    break;

    case 20:
    file << 't';

    break;

    case 21:
    file << 'u';

    break;

    case 22:
    file << 'v';

    break;

    case 23:
    file << 'w';

    break;

    case 24:
    file << 'x';

    break;

    case 25:
    file << 'y';

    break;

    case 26:
    file << 'z';

    break;

    case 27:
    file << ' ';

    break;
    }
    }

    file.close ();
    }

    cout << "

    Operation Complete
    a
    ";
    }

    rai_net
    rai_net@hotmail.com
  • [green]Interesting switch statement.[/green]
    [size=2][red]

    [b]Bikram[/b][/red]
    [blue]http://www.geocities.com/nv5050[/blue]
    [red]**************************************[/red][/size]

  • : [green]Interesting switch statement.[/green]
    : [size=2][red]
    :
    : [b]Bikram[/b][/red]
    : [blue]http://www.geocities.com/nv5050[/blue]
    : [red]**************************************[/red][/size]
    :
    :

    I'm not quite sure whether that was a compliment or not but thanks anyway

    rai_net
    rai_net@hotmail.com
  • i think its no compliment but wants to say that you can replace most of you switch by random_number+'a'-1 or something.

    : : [green]Interesting switch statement.[/green]
    : : [size=2][red]
    : :
    : : [b]Bikram[/b][/red]
    : : [blue]http://www.geocities.com/nv5050[/blue]
    : : [red]**************************************[/red][/size]
    : :
    : :
    :
    : I'm not quite sure whether that was a compliment or not but thanks anyway
    :
    : rai_net
    : rai_net@hotmail.com
    :

  • : i think its no compliment but wants to say that you can replace most of you switch by random_number+'a'-1 or something.

    I don't really have much programming experience and I am not quite sure what you mean. Do you think that you could supply a small example?

    rai_net
  • [b][red]This message was edited by PeterTheMaster at 2002-9-15 1:28:16[/red][/b][hr]
    time.h should be replaced by ctime and there is no void main!
    also variables should be created as late as possible, not all of them at the top of the program!
    i wonder how newbies always come up with these bad habits.


    [code]
    switch (random_number){
    case 0:
    file << '
    ';
    ++text_number;
    break;
    case 27:
    file << ' ';
    break;
    default:
    file << random_number-1+'a';
    break;
    }
    [/code]


  • : time.h should be replaced by ctime and there is no void main!
    : also variables should be created as late as possible, not all of them at the top of the program!
    : i wonder how newbies always come up with these bad habits.

    it's the typical c/c++ mixture ;-) people programming 'c++' when all they do is use plain c and iostream instead of stdio.h
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories