GStwin.com GS500 Message Forum

Main Area => General GS500 Discussion => Topic started by: JeffD on September 14, 2003, 05:18:37 PM

Title: O/T C++ class fun.
Post by: JeffD on September 14, 2003, 05:18:37 PM
Well Im taking C++ for my degree and decided to mess with my professor.  We have to write a program to input 3 numbers do the average product, and sum.  Check it out(the orange)


//Jeffrey D  MW 8am.  Comp methods

#include <iostream>
using namespace std;
int sum(int,int,int);    //int prototypes
int average(int);
int product(int,int,int);
int main()
{
   int one;
   int two;
   int three;
   cout << "Please enter an integer: ";
   cin >> one;
   cout <<  "Please enter another integer: ";
   cin >> two;
   cout <<  "Please enter another integer: ";
   cin >> three;
   cout << endl;
   int arediculouslylongvariablename;
   arediculouslylongvariablename = sum(one,two,three);
   cout << "Sum: " << arediculouslylongvariablename <<endl;
   int  anotherrediculouslylongvariablename;;
   anotherrediculouslylongvariablename = average(arediculouslylongvariablename);
   cout << "Avg: "<< anotherrediculouslylongvariablename<< endl;
   int  thelastrediculouslylongvariablename;;
   thelastrediculouslylongvariablename = product(one, two, three);
   cout << "Prod: " << thelastrediculouslylongvariablename << endl;
   return 0;
}
int sum(int a, int b, int c)
{
   int sumo;
   sumo = a +b+c;
   return sumo;
}
int average(int a)
{
   int averago;
   averago = a/3;
   return averago;
}
int product(int a,int b,int c)
{
   int prodo;
   prodo = a*b*c;
   return prodo;
}

I got bored.   :thumb:
Title: O/T C++ class fun.
Post by: Casimir on September 15, 2003, 05:03:50 AM
When I took FORTRAN 800 years ago the grader lived across the hall from me. On one program that had 20 or so variables I wrote the program then changed all the variable names to peoples' names from the dorm. Ended up making for difficult reading.  :)

On another program I added 2 lines of comments for every line of code. I commented the comments.

Ahh, geek pranks.
Title: O/T C++ class fun.
Post by: tres^ on September 15, 2003, 05:14:12 AM
hey, programming is fun! i wrote a small 3D game in VC++, using opengl library, as my diploma project 8) yes, i`m studying programming. not such a big programmer though. more like n00b  :mrgreen:
Title: O/T C++ class fun.
Post by: threatrockone on September 15, 2003, 10:16:11 AM
ahh...good 'ol c++.

another fun thing to do, but will surely lose points if applicable, is just put all the code on a single line (stylisticly speaking). if the grader has to actually look at the code, he or she will love it!  :cheers:
Title: O/T C++ class fun.
Post by: JeffD on September 15, 2003, 11:14:24 AM
gahh. were printing out our souce codes right now. but as soon as our programs get more complex I'm gona have to try that.  hehe. I could see it now.

(raise hand)  "I need some help"
(teacher/lab aid walks over)  "what"
"I'm only outputing an integer but I need a double but I cant find where I declared it."

(aide) "well you only have one line of code"
(me) "I figured it would save space."  


hehe  :thumb:
Title: O/T C++ class fun.
Post by: Kerry on September 15, 2003, 12:17:07 PM
As you know, you don't even need those 3 long-named variables; you can just call the sum(), product() and average() functions directly - inside the cout statements.

But that's not the point, right?  :)

If you want to get fancy, you could garner some inspiration from the International Obfuscated C Code Contest (http://www0.us.ioccc.org/main.html).  Check out some of the Winning Entries (http://www0.us.ioccc.org/years.html) from past years.
Title: O/T C++ class fun.
Post by: Rema1000 on September 15, 2003, 05:08:19 PM
Quote from: JeffD
(aide) "well you only have one line of code"
(me) "I figured it would save space."  

Reminds me of a classmate who used ed instead of vi: he claimed that it was such a pain to switch from one line to another, that he wrote tighter code as a result  :bs:

:)