![]() |
OT: Look what I can do...
My first C++ program.
Yay me. http://forum.shrapnelgames.com/images/smilies/laugh.gif <font class="small">Code:</font><hr /><pre> //************************************************** ******* //* * //* CIS 233.01 Program Lab 1: Chapter 3, Ex 4 (Pg 143) * //* Written by: George Perley * //* Date: April 18, 2005 * //* * //************************************************** ******* #include <iostream> // Must include for cin and cout #include <fstream> // Must include for file input and output functions #include <iomanip> // Must include for setw , fixed and setprecision functions using namespace std; // This is so the program knows how to use cin and cout int main() // Start of main function { const double taxableAmountRate = .92; // Set constant for amount of assesed value that is taxable const double taxRate = 1.05; // Set constant for tax per $100 of taxable value double assesedValue; // declare variable for assesed value of property double taxableAmount; // declare variable for caluclated taxable value of property double propertyTax; // declare variable for calculated property tax amount ofstream fout; // declare file output command fout.open("Lab1OutputFile.txt"); // open text file cout << "Please enter the assesed value of the property: "; // Prompt user for assesed value cin >> assesedValue; // Get assesed value input from user cout << endl; // carriage return before displaying results taxableAmount = assesedValue * taxableAmountRate; // Calculate taxable portion of proprety value propertyTax = (taxableAmount / 100) * taxRate; // Calculate property tax cout << setfill(' '); // set fill to blank spaces for formatting of output to screen cout << fixed << showpoint << setprecision(2); // desplay numbers on screen in two digit decimal notation. cout << left << "Assessed Value: " << setw(25) << right << assesedValue << endl; // Screen output cout << left << "Taxable Amount: " << setw(25) << right << taxableAmount << endl; // Screen output cout << left << "Tax Rate for each $100.00: " << setw(14) << right << taxRate << endl; // Screen output cout << left << "Property Tax: " << setw(27) << right << propertyTax << endl; // Screen output cout << endl; fout << setfill(' '); // set fill to blank spaces for formatting of output to file fout << fixed << showpoint << setprecision(2); // display numbers in file in two digit decimal notation. fout << left << "Assessed Value: " << setw(25) << right << assesedValue << endl; // Write to file fout << left << "Taxable Amount: " << setw(25) << right << taxableAmount << endl; // Write to file fout << left << "Tax Rate for each $100.00: " << setw(14) << right << taxRate << endl; // Write to file fout << left << "Property Tax: " << setw(27) << right << propertyTax << endl; // Write to file fout.close(); // close file } // This is the end of the main function, and my program </pre><hr /> |
Re: OT: Look what I can do...
Interested in doing my Python homework? http://forum.shrapnelgames.com/images/smilies/wink.gif
|
Re: OT: Look what I can do...
That can't be right. I don't see "hello world" anywhere in that code.
|
Re: OT: Look what I can do...
Yeah, that program is all wrong.
|
Re: OT: Look what I can do...
I don't believe you can legally have a first C++ program without it including "Hello World". http://forum.shrapnelgames.com/images/smilies/laugh.gif
|
Re: OT: Look what I can do...
It only means that geo's really first programm was written in Basic.
But he will never admit it http://forum.shrapnelgames.com/images/smilies/wink.gif |
Re: OT: Look what I can do...
Yea? Look what I can do: C++ hat random container template library addition
|
Re: OT: Look what I can do...
Lemme tell you, that is C http://forum.shrapnelgames.com/image...ies/tongue.gif not C++ it might be C++ syntax but C++ implies OO programming. dunno if you guys see that.
having a single main aint a good sign http://forum.shrapnelgames.com/images/smilies/wink.gif but if it's meant to be procedural it looks like a well structured program. |
Re: OT: Look what I can do...
C++ is not strictly object oriented. It is well suited for procedural programming (more so than the ever so clunky C). http://forum.shrapnelgames.com/image...ies/tongue.gif
|
Re: OT: Look what I can do...
Aww you guys are tough. http://forum.shrapnelgames.com/images/smilies/happy.gif
Yeah we did the "Hello world" stuff in class. Everything up to this point was copying down code that the instructor did or doing the step by step stuff in the book. This one was the first one that I wrote on my own. All I had to work with was what the input and required output was supposed to look like. And as far as it being C instead of C++, all I have to say to that is, even better. I'm bilingual! http://forum.shrapnelgames.com/images/smilies/laugh.gif |
Re: OT: Look what I can do...
Suggestion for version 2:
Separate input, output and processing into their own functions. It's real good exercise. Something like main(){ get_input( variables ) process_input( variables ) put_output(screen) put_output(file) } My brother never learned to use functions, and now he codes his entire programs all in main(). So now he can't write big programs, because after a while it becomes too much to follow in one function. Try reading a 500-line function! One page is plenty. |
Re: OT: Look what I can do...
Nothing compared to my 500 or so lines of spagetti code written in qbasic.
|
Re: OT: Look what I can do...
Quote:
And most wont admit it. http://forum.shrapnelgames.com/images/smilies/happy.gif |
Re: OT: Look what I can do...
I don't believe "cout" or "cin" is in C, so it must be C++.
|
Re: OT: Look what I can do...
Quote:
And I don't know about the rest of you, but I started in C, at 14 years old. A year later I learned "BASIC", but it was the version in my TI calculator, not this Visual nonsense. I technically still haven't "learned" VB, but really, do I need to? I can read the stuff, and if I'm ever asked to write it for some horrid reason... well, I'll burn that bridge when I get to it. |
Re: OT: Look what I can do...
Gotta take my hat off to anyone who's got the initiative to learn a programminglanguage this "late in the game". http://forum.shrapnelgames.com/images/smilies/cool.gif
|
Re: OT: Look what I can do...
Quote:
All my variables were 4 or 5 character acronyms. And it had no elses or block-ifs, since I didn't know about them at the time. Instead, I used If-Dosomething-Goto http://forum.shrapnelgames.com/images/smilies/laugh.gif I'd estimate that up to 10% of the instructions in that program were gotos! But at least it was neat, well organized spaghetti code. http://forum.shrapnelgames.com/images/smilies/eek.gif |
Re: OT: Look what I can do...
Quote:
|
Re: OT: Look what I can do...
Anyone who knows more than one language would be hard pressed to tell you to learn or not learn any particular programming language without afew more answers. In other words, dont bother learning VB unless and until you have a reason to. Something that you want to do, which it does well. Same goes for any other language. They all have their pros and cons
|
Re: OT: Look what I can do...
My first program was indeed a hello world program written in BASIC, on the Apple IIE. I was so happy and proud to be learning how to program a computer. That was a long long time ago. That year I went on to write spagetti code. In those days, each line of code had a line number and you had stuff like, "100 goto 250".
Then when I took my first programming course in university, on the first day the professor asked, "put up your hand if your first programming language was BASIC". I put up my hand, along with about half the people in the class. The professor says, "You are all contaminated - you learned to write spagetti code!". That course used Modula-2, and they were very strict about your code being neatly organized. That was a good thing, because I got rid of the bad habits I picked up earlier. |
Re: OT: Look what I can do...
What is spagetti code/a "Hello World" program?
|
Re: OT: Look what I can do...
Quote:
"Hello World" is the traditional first program. All it does is output the text "Hello World" to standard output, then exits. |
Re: OT: Look what I can do...
The 500 or so lines of spagetti code was my first time creating a fairly good program. It was "Guess the Animal", kinda like twenty questions where the computer will ask you a question, and you answer it. It did very good, and would even learn from its mistakes http://forum.shrapnelgames.com/images/smilies/happy.gif I even implimented a save and load feature, complete with my own file type! And it had a nice blue background http://forum.shrapnelgames.com/image...es/biggrin.gif
|
Re: OT: Look what I can do...
aaaahm so we are taking a walk down memory lane and sharing our 'First' Programming experience..
For me it was Atari Basic on the Atari 800 Computer. Aaah, the good old ways of line numbering and GOTO, GOSUB.. But the Atari let you place multiple commands on one line so you could cheat. http://forum.shrapnelgames.com/images/smilies/wink.gif On the PC My first programming was with GW-Basic which came with the computer and I eventually graduated to Quick Basic 4.5 which allowed me to 'compile executables' allthough it was still an interpreted language when coding. I'm still waiting for an 'Interpreted C language, I hate having to code, compile, run, code compile run,.. I miss the code, run, code, run, compile, share method. nuf said, Cheers! http://forum.shrapnelgames.com/images/smilies/happy.gif |
Re: OT: Look what I can do...
For me it was a TRS-80 at Radio-Shack in Bellevue Square Mall. I read the book in the mall, and it had the traditional
10 PRINT "Hello, World!" It also told of the GOTO statment, and I got to wondering what would happen if I made the program go back to the beginning. So I went back into Radio Shack, and wrote: 10 PRINT "Hello, World!" 20 GOTO 10 The screen filled to overflowing and would have run forever! They had to shut it down! I was hooked. |
Re: OT: Look what I can do...
|
Re: OT: Look what I can do...
David E. Gervais said:
I'm still waiting for an 'Interpreted C language, I hate having to code, compile, run, code compile run,.. I miss the code, run, code, run, compile, share method. Python might be what you are looking for. It is loosely based off of C++ and is interpreted. Unfortunately it lacks all of the fancy syntax characters, but it is an attempt to get away from all of that and have a more "natural" programming language, with white space syntax instead of explicit funky characters. Or, you could always use PHP. It is much closer to C++ (and C) stylistically and is of course interpreted. You would have to use it through a browser, but there is no reason why you could not do things locally with it. Run some sort of web server that is cut off from the rest of the world, and viola! http://forum.shrapnelgames.com/images/smilies/wink.gif |
Re: OT: Look what I can do...
Quote:
-- I try to avoid BASIC anymore since I saw the example of..(singing) This is the code that never ends, it just goes on and on my friends. Some people started GOTOing not knowing what it was And now they keep GOTOing it forever just because This is the code that never ends, it just goes on and on my friends. (inspired by Lambchop's song..http://www.zutroy.com/stuff/neverend/) HINT: you can get this song-virus out of your head by eating ice cream too fast. Gandalf Parker |
Re: OT: Look what I can do...
Quote:
|
Re: OT: Look what I can do...
POKE PROGRAM OF DOOM!
10 A = 1 20 POKE A, INT(RND * 256) 30 A = A + 1 40 GOTO 20 Run it, and watch the funky colors http://forum.shrapnelgames.com/images/smilies/happy.gif I'm not responsible for any damages from this program though, so don't sue me! |
Re: OT: Look what I can do...
My first programming was in Fortran, on punch cards, run on a "room full" of computer at a college 15 miles away from my college. My college didn't have a computer, but we did have a card punch machine!
Those were the days. I think we did 6-8 programs in an entire semester. |
Re: OT: Look what I can do...
Vic 20. I had one going once where there where two floors and you could climb up ladders and this thing would drop stuff on you.
Of course, Greybeard wins for oldest program... |
Re: OT: Look what I can do...
Anyone try my poke program of doom?
|
Re: OT: Look what I can do...
heehee I can still read punch cards. And I remember a "room full of computer" (one computer) that offered 32 bit programming as 32 toggle switches and an enter key.
Null, I did try your program (with a limit on the doom part). My basic didnt seem to like it. But then Im using a basic which I can use on both windows and linux so Im not surprised that it didnt want to do it. Gandalf Parker |
Re: OT: Look what I can do...
Quote:
Like Fyron said, try Python. Quote:
Oh, and I think I was the one who told you to buy C for dummies (by Dan Gookin). Just to put you all to shame, I know *all* of the following languages, each to varying amounts: C/C++ C# Java J# PHP (It can be compiled, PHP.NET) Perl (it is more of a script though) Java (J2SE, J2ME) Fortran (77/95ish) COBOL (old school hardcore!) Intel IA32 Assembly Visual Basic (.NET the best) AppleBasic (Apple IIe baby!) JavaScript (again, more of a script) JCL (more of a script) SQL (a query language, really) Some of those I haven't used for a while, so I probably couldn't make a super huge program in each. You have to be using it to know it well. Right now, I'm deep into the internals of Java on the J2ME platform. I plan on learning 64 bit assembly when I get a 64 bit computer. I hope to get Python learned sometime soon, and maybe some Ruby, Ada, or maybe Eiffel. Smalltalk would be nice too. D would be relatively easy to learn, so maybe I'll try that. Oh, and Visual Foxpro, and some Delphi would be nice too. Yes, I'm a pitiful geek. But a well learned one! |
Re: OT: Look what I can do...
I used to make all sorts of variations of my Random Hockey Madness / Random Baseball Madness simulators - first in a language called Turing, then to various degrees in good ol' basic, qbasic, and lastly visual basic. The programs were fun, but unfortunately lost in that HD crash a couple of years ago. I never got back into programming after that.
|
Re: OT: Look what I can do...
I used to spend hours writing spaghetti code in AMOS- a bulky but easy version of Basic for my old Amiga. I was entirely self-taught, but I taught myself to use procedures/ functions rather than GOTOs (although I never understood how or why I should pass a parameter to a procedure).
I used to produce some really cool scrolltexts and joystick-driven animated menus for compilations of (other people's) games, with lots of neat home-pixelled graphics/ fonts with brilliant dance music by a friend of mine, who used Fasttracker or Octamed or something similar. It was spaghetti code, it was all entirely unplanned (I always had a vision of how I wanted it to look, but never knew how to plan code- just started typing) but it all worked. Some of it was fairly sophisticated, too. I remember I had one scrolltext that went from the bottom of the screen to the top, casting a shadow-text beneath moving at a third the speed. All the while I had a 2-player "Tron" game running on the other half of the screen. Then I got a girlfriend. I'd love to look back over those programs. Unfortunately all the data is on floppy, and PCs won't read amiga floppies, even with emulators. |
Re: OT: Look what I can do...
Since we are on this subject.....
I would be interested in a CGI which is the simplest possible for UPLOADING a file to a linux webserver. Such as, if I click it then it goes the full path to "C://program files/Space Empires IV/mygame/myturn.fil" and uploads it. No questions, no options, no checks and verifications. |
Re: OT: Look what I can do...
Quote:
|
Re: OT: Look what I can do...
1 Attachment(s)
For you people who are curious, here's my QBasic program. It should be fairly easy to figure out what to do http://forum.shrapnelgames.com/images/smilies/happy.gif
|
Re: OT: Look what I can do...
Quote:
|
Re: OT: Look what I can do...
Quote:
|
Re: OT: Look what I can do...
No on the learning. Ive got a ton of books and help sites on that. I just want something that I click and it sends
"D:\Program Files\Space Empires IV Gold\Empires\mine.emp". No questions, no choices. If its simple enough then it will serve my purpose of being able to modify it on the fly. I thought there might be someone here who writes their own CGI's. If not then no problem, I can keep asking around. |
Re: OT: Look what I can do...
What kind of webserver you running? I assume some kind of Apache, right?
|
Re: OT: Look what I can do...
Quote:
Im half trying to move toward handling some PbEM games from the SysAdmin upward side of it rather than the WebMaster downward side usually used. The one stumbling block that I keep meaning to work on and never do, is an upload routine. Simple, single file going to a single location, no options. If someone can do that, great. If not then I will put it back on the back-burner till I get around to it. |
Re: OT: Look what I can do...
Quote:
|
Re: OT: Look what I can do...
http://cgi-lib.berkeley.edu/ex/fup.html
Something like the above? It looks to be a fairly common Perl lib that takes a HTTP POST from the HTML form. |
Re: OT: Look what I can do...
Quote:
Gandalf Parker |
Re: OT: Look what I can do...
Well, I don't understand what you want then. You want a webpage you visit to automatically upload a file from the user's computer? That just isn't very possible with standard Perl/PHP/HTML stuff. You can create a default value for the HTML input, if that is what you mean.
|
Re: OT: Look what I can do...
I think he wants a script that will upload a file in a specific location on his computer to a specific location on his webpage, so that if he wants to upload something different, all he has to do is change the addressing.
|
All times are GMT -4. The time now is 03:24 AM. |
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.