Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 7th, 2005, 3:26 PM   #1
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
Ohm's Law

In electronics you can use Ohm's Law to find the Voltage, Resistance and Current of an electrical circuit.
Here is a small simple C++ program that uses Ohm's Law, it could prove useful to someone, probably not but i decided to post it here, because i never really post any of my code
/*
File: ohm.cpp
Title: Ohm's law
Author: ColdDeath
Date: 07/09/05 19:47
Description: This program demonstrates Ohm's law. (I=V/R)
V = voltage in Volts, R = resistance in Ohms, I = current in ampheres
*/
#include <iostream> //needed for user input and output
using namespace std;
int VoltFind(float current, float resistance)
{
	//V=I*R
	float voltage = current * resistance;
	cout<<"\nVoltage: "<<voltage<<endl;
	return 0;
}
int ResistFind(float voltage, float current)
{
	//R=V/I
	float resistance = voltage / current;
	cout<<"\nResistance: "<<resistance<<endl;
	return 0;
}
int CurrentFind(float voltage, float resistance)
{
	//I=V/R
	float current = voltage / resistance;
	cout<<"\nCurrent: "<<current<<endl;
	return 0;
}
int main(int argc, char *argv[])
{
	float I;
	float R;
	float V;
	int menuOption;
	cout<<"Main Menu\n1. Find Voltage\n2. Find Resistance\n3. Find Current\n4. Exit"<<endl;
	cin>>menuOption;
	switch (menuOption)
		{
		case 1:
			cout<<"Current: ";
			cin>>I;
			cout<<"\nResistance: ";
			cin>>R;
			VoltFind(I, R);
			break;
		case 2:
			cout<<"\nVoltage: ";
			cin>>V;
			cout<<"Current: ";
			cin>>I;
			ResistFind(V, I);
			break;
		case 3:
			cout<<"Voltage: ";
			cin>>V;
			cout<<"\nResistance: ";
			cin>>R;
			CurrentFind(V, R);
			break;
		case 4:
			return 0;
		default:
			cout<<"Please use a correct menu option.";
			return 0;
		}
	return 0; //Exit the main function
}

If anyone has any suggestions or comments about this program, feel free to speak.
-CD

EDIT: This code is straightforward and simple so i decided not to comment it too much
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Oct 25th, 2005, 11:29 PM   #2
frankish
Hobbyist Programmer
 
frankish's Avatar
 
Join Date: Oct 2005
Location: Ohio
Posts: 177
Rep Power: 0 frankish is an unknown quantity at this point
It would be nice if the code dealt with circuits. I mean, can you make it so that it can find currents and voltage across circuits?
frankish is offline   Reply With Quote
Old Oct 26th, 2005, 1:36 AM   #3
MrSmiley
Programmer
 
MrSmiley's Avatar
 
Join Date: May 2005
Posts: 41
Rep Power: 0 MrSmiley is on a distinguished road
Hey, if you can write a programme to figure out Integrals (multi variable) and Derivitives that would make calc 3 a lot easier (oh yes, vectors too)
MrSmiley is offline   Reply With Quote
Old Oct 26th, 2005, 4:27 AM   #4
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6 bl00dninja is on a distinguished road
like maple or mathcad or whatever?
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Oct 26th, 2005, 8:22 AM   #5
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
or mathlab and mathematica
OpenLoop is offline   Reply With Quote
Old Oct 26th, 2005, 8:52 AM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Thevenin's equivalent, perhaps, or Norton's? I already have a 50-cent calculator.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Oct 26th, 2005, 8:28 PM   #7
frankish
Hobbyist Programmer
 
frankish's Avatar
 
Join Date: Oct 2005
Location: Ohio
Posts: 177
Rep Power: 0 frankish is an unknown quantity at this point
Quote:
Originally Posted by MrSmiley
Hey, if you can write a programme to figure out Integrals (multi variable) and Derivitives that would make calc 3 a lot easier (oh yes, vectors too)
They have program like that for the TI 85. You can download them from ticalc.org.
frankish is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:22 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC