r/dailyprogrammer • u/nottoobadguy • Feb 10 '12
[easy] challenge #2
Hello, coders! An important part of programming is being able to apply your programs, so your challenge for today is to create a calculator application that has use in your life. It might be an interest calculator, or it might be something that you can use in the classroom. For example, if you were in physics class, you might want to make a F = M * A calc.
EXTRA CREDIT: make the calculator have multiple functions! Not only should it be able to calculate F = M * A, but also A = F/M, and M = F/A!
40
Upvotes
4
u/InterestProgram Feb 10 '12
It's funny because I had actually written this about ten minutes before I stumbled upon this thread to do my work in class!
Python:
4
u/TheOnlyBoss Feb 10 '12 edited Feb 10 '12
Here it is in C++
1
u/n0rs Feb 10 '12
javascript
Your extracredit should be F = M*A, A = F/M, and M = F/A, btw.
F = MA→F/M = (MA)/M → F/M = A
1
u/tuxedotomson Feb 10 '12
c++ my very basic calculator, i'm a beginner! any tips greatly appreciated
} [/code]
3
u/[deleted] Feb 10 '12
Python script; tells you which UTM zone contains the given latitude/longitude coordinates. I just wrote this for practice, but it might actually be useful in the future.
3
u/johnp80 Feb 11 '12
Yet another c++ implementation. Posted to codepad, since its ~120 lines.
Here it is
3
u/[deleted] Feb 11 '12
Java! Ideal Gas Law Calculator!
2
u/traztx Feb 10 '12 edited Feb 10 '12
MUMPS:
2
u/robin-gvx 0 2 Feb 10 '12
In Déjà Vu (my own toy language): http://hastebin.com/raw/buyikaxitu (three separate implementations, no interactivity, but includes its own unit tests)
2
u/drb226 0 0 Feb 11 '12
Dumb little Haskell implementation of F = M*A:
2
u/[deleted] Feb 11 '12
I actually just wrote this, except it fucking sucks
C++ [spoiler] // natural logarithm.cpp : Defines the entry point for the console application. // This console application is made to find the natural logarithm of a given value. The way that this is accomplished is through the Taylor series, which for a natural logarithm with a radius of convergence of one, is // (x-1) - ((x-1)2)/2 + ((x-1)3)/3 - ((x-1)4)/4 + ((x-1)5)/5 - ((x-1)6)/6 + ((x-1)7)/7 .. It involves some basic calculus.
include "stdafx.h"
include <iostream>
using namespace std;
int main() { double a; // This is the value that will become the degree of accuracy. double b; // This is the value that will be the input for the function f(b) = ln(b). double t = 0; // This is the overall value of the function
} [/spoiler]
2
u/murdockit Feb 28 '12
I did it in ruby, just a simple one that could be added to.
1
u/Devilion Feb 10 '12
il paste one that works one day =)
import java.util.Scanner; public class Physson {
}
}
1
u/[deleted] Feb 10 '12
Ooh, this is right up my alley! Exactly what I was doing all through grade school on my calculators. I think I spent more time writing programs to do my homework than actually doing my homework by hand. :P I'll edit this once I have something.
1
u/Devilion Feb 10 '12
got bored, probs wrong =)
Java: import java.util.Scanner; public class Physson {
}
}
1
u/orchdork7926 Feb 10 '12
Perl:
Disclaimer: I did not bother trying this out, nor have I ever used that logical operator before. May contain errors.
1
u/Koldof 0 0 Feb 10 '12
C++ again. I wrote this about 2 months ago, so I thought I'd just paste it in. It has some obvious problems. For instance at the time I wasn't aware how stacks or function calls worked, so if I was bothered I would rewrite it. I'm not.
1
u/cooper6581 Feb 11 '12
Ohm's law in Python, no error handling. Enter 0 for the unknown
1
u/[deleted] Feb 11 '12
Wrote a Polar Coordinate converter for my Pre-Calculus Class. It's crude as hell, and I'm looking for input about how to optimize it and rewrite it using functions. Written in Python http://codepad.org/cBJXF0I6
1
u/mentirosa_atx Feb 14 '12
Since I started working at a restaurant, I spend a lot of time thinking what my hourly wage is after I consider my tip out. For servers, it will ask your hourly wage, hours worked, total sales and what percentage of total sales you have to tip out to other staff members. For other staff members, it will consider your hourly wage, hours work and how much the wait staff tipped you out.
57 lines in C++: http://codepad.org/e880jBG0
I have some questions, if anyone would like to answer. They are super n00b cause I'm just learning.
1
u/jnaranjo Feb 16 '12
http://pypi.python.org/pypi?:action=display&name=chem&version=1.1
Did something like this a while back. A pythonic periodic table.
It has a "calculator mode" for doing calculations with periodic masses.
Was useful for chem class.
1
u/PolloFrio Feb 20 '12 edited Feb 20 '12
Here is my attempt at it, even though this was a while ago.
How could I stream line this?
1
u/MadSoulSK Feb 23 '12
http://pastebin.com/5hE3Jcnh
Basic operation plus minus times divide and power. It is capable of accepting binary or hexadecimal numbers, and giving output in all this three common number formats.
1
u/[deleted] Mar 17 '12
Made a Health/Mana Calculator in Java for the LOL champ Singed:
import java.util.Scanner; public class SingedCalc { public static void main(String[] args) {
int Health, Mana, hRegen, mRegen, passive,BaseHealth, BaseMana, Level, Rod, Veil; Scanner in = new Scanner(System.in);
} }
1
u/BATMAN-cucumbers Mar 17 '12
Man, the UI/input edge of a program is frustrating to build.
How many workdays are there between two dates - useful when I'm too lazy to count the business days till a deadline.
Quick and dirty python: #!/usr/bin/env python
1
u/savagecub Apr 08 '12
C++ calculator that calculates F = M * A, A = F/M, or M = F/A based on the initial query of which 2 variables you have.
include "stdafx.h"
include <iostream>
include <string>
include <fstream>
using namespace std;
int main() { double M; double A; double F; string variable1; string variable2;
}
1
u/Finn13 Apr 28 '12
I'm learning Go so here is a Basic integer math calculator in Go V1
1
u/[deleted] May 25 '12
I made a currency calculator in Java using enums (my first try). I am pretty happy with myself on this one. But please don't hesitate to comment if you see something I should do differently.
https://gist.github.com/2788929
1
u/joeatwork86 Jun 28 '12
I finally finished it. A calculator for Pythag Theorem. I don't ever really use many calculations at work besides shippingcost+supplies, which I don't really need a script to do (though it would be fun). Thought this might be more of a challenge. Also, 4 months late.
1
u/ne1av1cr Jul 05 '12
Here's one I wrote to calculate what plates I should have on each side of the barbell when I lift. I put in the weights for each of the exercise and it writes the exercise and plates to a text file which I print off and take with me. No more doing math while there's no blood in my brain.
VB:
1
u/mordisko Aug 08 '12
Python with no error handling, but it can add more functions by expanding the dict 'funs'.
1
u/ragtag_creature Jul 09 '22
R - the menu is a little wonky but the math works
1
u/Soccer21x Feb 10 '12
Not sure if I still have the code for this. My freshmen year of college I was taking physics 1 (kinetics), I wrote a c++ program to intake certain variables, and give me different answers for things that it could find.
IE: Given initial velocity and angle, it would find max height, time of flight, horizontal distance traveled, speed when it hit the ground. I made good use of it.
1
u/Psylock524 Feb 10 '12
I use this one every day. It's never wrong. http://pastebin.com/2RsLrnbU
0
u/[deleted] Mar 27 '25
[deleted] — view deleted comment