.com.unity Forums

.com.unity Forums (http://forum.shrapnelgames.com/index.php)
-   Space Empires: IV & V (http://forum.shrapnelgames.com/forumdisplay.php?f=20)
-   -   OT: Look what I can do... (http://forum.shrapnelgames.com/showthread.php?t=23581)

geoschmo April 20th, 2005 12:30 PM

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 &lt;iostream&gt; // Must include for cin and cout
#include &lt;fstream&gt; // Must include for file input and output functions
#include &lt;iomanip&gt; // 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 &lt;&lt; "Please enter the assesed value of the property: "; // Prompt user for assesed value
cin &gt;&gt; assesedValue; // Get assesed value input from user
cout &lt;&lt; endl; // carriage return before displaying results

taxableAmount = assesedValue * taxableAmountRate; // Calculate taxable portion of proprety value
propertyTax = (taxableAmount / 100) * taxRate; // Calculate property tax

cout &lt;&lt; setfill(' '); // set fill to blank spaces for formatting of output to screen
cout &lt;&lt; fixed &lt;&lt; showpoint &lt;&lt; setprecision(2); // desplay numbers on screen in two digit decimal notation.

cout &lt;&lt; left &lt;&lt; "Assessed Value: " &lt;&lt; setw(25) &lt;&lt; right &lt;&lt; assesedValue &lt;&lt; endl; // Screen output
cout &lt;&lt; left &lt;&lt; "Taxable Amount: " &lt;&lt; setw(25) &lt;&lt; right &lt;&lt; taxableAmount &lt;&lt; endl; // Screen output
cout &lt;&lt; left &lt;&lt; "Tax Rate for each $100.00: " &lt;&lt; setw(14) &lt;&lt; right &lt;&lt; taxRate &lt;&lt; endl; // Screen output
cout &lt;&lt; left &lt;&lt; "Property Tax: " &lt;&lt; setw(27) &lt;&lt; right &lt;&lt; propertyTax &lt;&lt; endl; // Screen output
cout &lt;&lt; endl;

fout &lt;&lt; setfill(' '); // set fill to blank spaces for formatting of output to file
fout &lt;&lt; fixed &lt;&lt; showpoint &lt;&lt; setprecision(2); // display numbers in file in two digit decimal notation.

fout &lt;&lt; left &lt;&lt; "Assessed Value: " &lt;&lt; setw(25) &lt;&lt; right &lt;&lt; assesedValue &lt;&lt; endl; // Write to file
fout &lt;&lt; left &lt;&lt; "Taxable Amount: " &lt;&lt; setw(25) &lt;&lt; right &lt;&lt; taxableAmount &lt;&lt; endl; // Write to file
fout &lt;&lt; left &lt;&lt; "Tax Rate for each $100.00: " &lt;&lt; setw(14) &lt;&lt; right &lt;&lt; taxRate &lt;&lt; endl; // Write to file
fout &lt;&lt; left &lt;&lt; "Property Tax: " &lt;&lt; setw(27) &lt;&lt; right &lt;&lt; propertyTax &lt;&lt; endl; // Write to file

fout.close(); // close file




} // This is the end of the main function, and my program
</pre><hr />

General Woundwort April 20th, 2005 12:39 PM

Re: OT: Look what I can do...
 
Interested in doing my Python homework? http://forum.shrapnelgames.com/images/smilies/wink.gif

DarkHorse April 20th, 2005 01:09 PM

Re: OT: Look what I can do...
 
That can't be right. I don't see "hello world" anywhere in that code.

Fyron April 20th, 2005 01:16 PM

Re: OT: Look what I can do...
 
Yeah, that program is all wrong.

Combat Wombat April 20th, 2005 02:15 PM

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

Aiken April 20th, 2005 02:45 PM

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

AngleWyrm April 20th, 2005 03:38 PM

Re: OT: Look what I can do...
 
Yea? Look what I can do: C++ hat random container template library addition

boran_blok April 20th, 2005 03:41 PM

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.

Fyron April 20th, 2005 03:42 PM

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

geoschmo April 20th, 2005 04:03 PM

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


All times are GMT -4. The time now is 10:00 PM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2024, Shrapnel Games, Inc. - All Rights Reserved.