Author Topic: C++ Programs  (Read 4724 times)

Offline Penguin

  • Jesus Christ Is Real
  • Gold Member
  • *
  • Posts: 786
  • Awards [OCRP Award] Millionaire [OCRP Award] Secret Phrase [OCRP Award] Social Player [OCRP Award] You Own The Mall
    • View Profile
    • Awards
C++ Programs
« 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!
« Last Edit: September 12, 2011, 04:43:30 PM by Somone77 »

Offline Calstifer

  • Gold Member
  • *
  • Posts: 75
    • View Profile
    • Awards
Re: C++ Programs
« Reply #1 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 : ")

Offline Penguin

  • Jesus Christ Is Real
  • Gold Member
  • *
  • Posts: 786
  • Awards [OCRP Award] Millionaire [OCRP Award] Secret Phrase [OCRP Award] Social Player [OCRP Award] You Own The Mall
    • View Profile
    • Awards
Re: C++ Programs
« Reply #2 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

Offline wakeboarderCWB

  • Gold Member
  • *
  • Posts: 2,486
  • Awards [OCRP Award] Social Player [OCRP Award] You Own The Mall [OCRP Award] Dedicated Player [OCRP Award] Millionaire
    • View Profile
    • Awards
Re: C++ Programs
« Reply #3 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++?
« Last Edit: September 26, 2011, 09:41:57 PM by wakeboarderCWB »

Offline Penguin

  • Jesus Christ Is Real
  • Gold Member
  • *
  • Posts: 786
  • Awards [OCRP Award] Millionaire [OCRP Award] Secret Phrase [OCRP Award] Social Player [OCRP Award] You Own The Mall
    • View Profile
    • Awards
Re: C++ Programs
« Reply #4 on: September 27, 2011, 03:57:44 PM »
About a month will be uploading about 5 more programs soon.

Offline Calstifer

  • Gold Member
  • *
  • Posts: 75
    • View Profile
    • Awards
Re: C++ Programs
« Reply #5 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.

Offline Penguin

  • Jesus Christ Is Real
  • Gold Member
  • *
  • Posts: 786
  • Awards [OCRP Award] Millionaire [OCRP Award] Secret Phrase [OCRP Award] Social Player [OCRP Award] You Own The Mall
    • View Profile
    • Awards
Re: C++ Programs
« Reply #6 on: September 27, 2011, 06:35:12 PM »
Ok

Offline Meatwad

  • Gold Member
  • *
  • Posts: 195
  • Awards [OCRP Award] Secret Phrase [OCRP Award] Evo City Half Marathon
    • View Profile
    • Awards
Re: C++ Programs
« Reply #7 on: September 28, 2011, 10:45:28 PM »
Code: [Select]
#include <iostream>

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

lolpwned

Offline AcornMan

  • Gold Member
  • *
  • Posts: 311
  • Awards [OCRP Award] Secret Phrase [OCRP Award] You Own The Mall [OCRP Award] Comrades
    • View Profile
    • Awards
Re: C++ Programs
« Reply #8 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.
"Groovy", "This, is my Boom stick".
"RoflWaffle: Servers are going to be down for at least 12 hours as I locked myself out of the box again"."RoflWaffle: :c I need to stop doing that".Justin Newton AKA Jay killed RTLK using "weapon_copgun_ocrp "I've now killed all the admins and dev's at least once."- Justin Newton AKA Jay".
For funny billboards: http://majormike.us/?p=128

Offline Meatwad

  • Gold Member
  • *
  • Posts: 195
  • Awards [OCRP Award] Secret Phrase [OCRP Award] Evo City Half Marathon
    • View Profile
    • Awards
Re: C++ Programs
« Reply #9 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?

Offline wakeboarderCWB

  • Gold Member
  • *
  • Posts: 2,486
  • Awards [OCRP Award] Social Player [OCRP Award] You Own The Mall [OCRP Award] Dedicated Player [OCRP Award] Millionaire
    • View Profile
    • Awards
Re: C++ Programs
« Reply #10 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.

Offline Penguin

  • Jesus Christ Is Real
  • Gold Member
  • *
  • Posts: 786
  • Awards [OCRP Award] Millionaire [OCRP Award] Secret Phrase [OCRP Award] Social Player [OCRP Award] You Own The Mall
    • View Profile
    • Awards
Re: C++ Programs
« Reply #11 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

Offline Meatwad

  • Gold Member
  • *
  • Posts: 195
  • Awards [OCRP Award] Secret Phrase [OCRP Award] Evo City Half Marathon
    • View Profile
    • Awards
Re: C++ Programs
« Reply #12 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-2024, SimplePortal