News:

Protect your dainty digits. Get a good pair of riding gloves cheap Right Here

Main Menu

O/T C++ class fun.

Started by JeffD, September 14, 2003, 05:18:37 PM

Previous topic - Next topic

JeffD

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:
The world does revolve around us, we pick the coordinate system. -engineers

Casimir

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.
'01 GS500 - Progressive springs, Kat 600 shock, Fenderectomy, Factory Pro jet kit

tres^

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:
===83` suzuki gsx400e rider===

threatrockone

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:
the closer you are the quicker it hits you...

JeffD

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:
The world does revolve around us, we pick the coordinate system. -engineers

Kerry

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.  Check out some of the Winning Entries from past years.
Yellow 1999 GS500E
Kerry's Suzuki GS500 Page

Rema1000

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:

:)
You cannot escape our master plan!

SMF spam blocked by CleanTalk