Catalyst Gaming

General => Creations => Topic started by: Penguin on September 12, 2011, 04:37:37 PM

Title: C++ Programs
Post by: Penguin on September 12, 2011, 04:37:37 PM
I wrote some programs for C++ thought I would post them here so people can use them on whatever they wish.

Kinetic energy calculator, finds the amount of Kinetic energy after the input of speed and mass.

Code: [Select]
// Kinetic energy
#include <iostream.h>
#include <conio.h>
#include <fstream.h>
void main ()
{
double long Mass, Speed, KE  ;
   cout << "What is the mass?\n" ;
   cin >> Mass ;
cout << "What is the speed?\n" ;
   cin >> Speed ;
   KE = Speed * Speed * Mass / 2 ;
   ofstream printObject ;
   printObject .open ("h:\\C++\\KE.txt" , ios::out ) ;
 
 
   cout << "The kinetic energy is..." << KE << endl ;
   printObject << "Speed..." << Speed << endl ;
   printObject << "Mass..." << Mass << endl ;
   printObject << "Total kinetic energy..." << KE << endl  ;
   printObject .close ();
   cout << " Press any key to end run..." ;
   getch () ;
   }


Farenheit to celsius converter:

// CP1, Farenheit to celsius program
#include <conio.h>
#include <iostream.h>
#include <fstream.h>
void main ()
{
double long  C, F ;
   cout << "Please enter fahrenheit temperature. \n" ;
   cin >> F  ;
   C = (F - 32)* 5/9 ;
   ofstream printObject ;
   printObject .open ("h:\\C++\\Farenheitconverter.txt" , ios::out ) ;
 
   cout << "Your degrees in celsius is " << C <<endl  ;
   printObject << "Your degrees in celsius is " << C <<endl  ;
cout << "Press any key to end run..." ;
   getch () ;
   }


Finds your gross pay and net pay after a tax deduction of 20%, also input your number of hours worked and rate of payment.

// Payment
#include <iostream.h>
#include <conio.h>
#include <fstream.h>
void main ()
{
double long Rate, Hours, Gross, Withheld, Netpay  ;
   cout << "Please enter Hours worked.\n" ;
   cin >> Hours ;
   cout << "Please enter Rate of payment.\n" ;
   cin >> Rate ;
   Gross = Rate * Hours ;
   Withheld = Gross * .20 ;
   Netpay = Gross - Withheld ;
   ofstream printObject ;
   printObject .open ("h:\\C++\\Payment.txt" , ios::out ) ;
 
   cout << "You worked...Hours = "<< Hours << endl ;
   cout << "You make ... an hour " << Rate << endl ;
   cout << "Gross pay = " << Gross << endl ;
   cout << "Withheld = " <<Withheld << endl ;
   cout << "Netpay = " << Netpay << endl ;
   printObject << "Gross pay = " << Gross << endl ;
   printObject << "Amount of money taken by taxes = " << Withheld << endl ;
   printObject << "Money made after taxes =  " << Netpay << endl  ;
   printObject .close ();
   cout << " Press any key to end run..." ;
   getch () ;
   }

*Edited by Somone77 - Please use code tags, thanks!
Title: Re: C++ Programs
Post by: Calstifer on September 26, 2011, 01:34:14 AM
I call your C++ and raise you a python.

Code: [Select]
mass = input("What is the mass ? ") ; mas = float(mass)
speed = input("What is the speed ? ") ; sped = float(speed)
energy = sped * sped * mas / 2
print ("Kinetic energy =", int(energy))
b = input ("Press enter to exit : ")
Title: Re: C++ Programs
Post by: Penguin on September 26, 2011, 07:17:29 AM
I call your C++ and raise you a python.

Code: [Select]
mass = input("What is the mass ? ") ; mas = float(mass)
speed = input("What is the speed ? ") ; sped = float(speed)
energy = sped * sped * mas / 2
print ("Kinetic energy =", int(energy))
b = input ("Press enter to exit : ")
Idk about python but in c++ you still have to spell the variables in your formula correct
energy = speed * speed * mass / 2
Corrected
Title: Re: C++ Programs
Post by: wakeboarderCWB on September 26, 2011, 09:39:49 PM
Tried learning C++ but I never took an interest in it. I'm more into Java.

Think.java
Code: [Select]
public class Think{
public static void main(String[] args){

Actions myActionObj = new Actions();

myActionObj.displayMessage("Hello World!");
}
}

Actions.java
Code: [Select]
public class Actions{

public void displayMessage(String msg){
System.out.println(msg);
}
}

In regards to your program, it's a nice simple calculator. May I ask how long you have been programming with C++?
Title: Re: C++ Programs
Post by: Penguin on September 27, 2011, 03:57:44 PM
About a month will be uploading about 5 more programs soon.
Title: Re: C++ Programs
Post by: Calstifer on September 27, 2011, 05:40:00 PM
Idk about python but in c++ you still have to spell the variables in your formula correct
energy = speed * speed * mass / 2
Corrected

I re-named them.
Code: [Select]
mass = input("What is the mass ? ") ; [b]mas = float(mass)[/b]
speed = input("What is the speed ? ") ; [b]sped = float(speed)[/b]

I've been doing python for a little over 6 months, and am starting to do a bit of networking, but its more learning than anything functional.
Title: Re: C++ Programs
Post by: Penguin on September 27, 2011, 06:35:12 PM
Ok
Title: Re: C++ Programs
Post by: Meatwad on September 28, 2011, 10:45:28 PM
Code: [Select]
#include <iostream>

using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}

lolpwned
Title: Re: C++ Programs
Post by: AcornMan on September 28, 2011, 10:59:50 PM
If I get a chance, I'll upload some of my code for Visual Basic (VB.NET) for a few programs I've done. Note: I'll edit this post to remove this note and have a list of the codes for each within a spoiler as some are long and fall under a few names given for them, on that will definitely be in will be my Lunar Lander code. Again this note will be removed when I get the code out (possibly getting it tomorrow during school and type it down real quick or something) and have the names above each spoiler so you can tell the difference between the codes.
Title: Re: C++ Programs
Post by: Meatwad on September 29, 2011, 07:33:31 PM
I can't seem to get my C++ code to work, I have no idea how to compile it. Can anyone help?
Title: Re: C++ Programs
Post by: wakeboarderCWB on September 30, 2011, 06:27:09 AM
I can't seem to get my C++ code to work, I have no idea how to compile it. Can anyone help?
Download an IDE like Code::Blocks.
http://www.codeblocks.org/downloads

Start a new project, put it in the typing area, and compile it.
Title: Re: C++ Programs
Post by: Penguin on September 30, 2011, 07:21:23 AM
I can't seem to get my C++ code to work, I have no idea how to compile it. Can anyone help?
I use Borland C++. There are many compilers just do a search
Title: Re: C++ Programs
Post by: Meatwad on September 30, 2011, 11:37:58 AM
I can't seem to get my C++ code to work, I have no idea how to compile it. Can anyone help?
Download an IDE like Code::Blocks.
http://www.codeblocks.org/downloads

Start a new project, put it in the typing area, and compile it.
I have that but I have no idea how to compile something...
SimplePortal 2.3.7 © 2008-2025, SimplePortal