|
I am new to program (c++)and I am having a hard time writing the code for this example. I am useing microsoft visual c++. This is a example of my problem and how do I start this project.
Write a program that calculates and displays the electrical current flowing through the circuit, the voltage across each resistor, and power dissipated by each of two resistors in a simple series circuit. The series circuit consists of a single voltage source with two resistors in series across the voltage source outputs.
The program should execute in a loop. Inside the loop ask the user to enter the source voltage. Read the value entered and assign it to an appropriately named member of a structure. Next prompt the user to enter a value for the first resistor. Assign this value to an appropriately named member of a structure. Next prompt the user to enter a value for the second resistor and assign this value to an appropriately named member of a structure. After the values are entered, display the current flowing through the series circuit (voltage/(resistorA+resistorB)), the voltage drop across each resistor, and the power dissipated by each resistor. The voltage drop across resistorA is (resistorA * voltage)/(resistorA + resistorB). The voltage drop across resistorB is (resistorB * voltage)/(resistorA + resistorB). Power can be calculated by multiplying the voltage drop across a resistor value times the current through it.
After the above information is displayed prompt the program user to enter either a Y or N. If the user enters a Y, the program should continue to loop and go through the entire cycle asking for voltage source and resistor values, performing the calculations and outputting the current, voltage drops, and power dissipated by the resistors.
Put the definition for the structure in a header file (File-New File-Header File(.h). Be sure to save the file in the project folder and add the header file to project. Use the #include “filename.h” at the top of you C++ program to attach the header file to project.
|
|
|
|
|
I'll do your homework for you. My rate is $200 an hour.
Or you could give it a go, post your code here, and I'll be glad to help you.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Christian Graus wrote:
I'll do your homework for you. My rate is $200 an hour.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
Use the App Wizard to create a Console Application.
Create variables - double Vs, Is, V1, V2, P1, P2, R1, R2; initialize Vs=0, Is=0, R1 and R2 something > 0 (to prevent ugly errors).
Create a variable - char Q.
Create a loop control; int Go = 1, perhaps.
Open a While(Go) loop.
Inside the loop, request values for Vs, R1, and R2 from the console.
Is= Vs/(R1 + R2);
V1= R1 * Is;
V2= R2 * Is;
P1= V1 * V1 / R1;
P2= V2 * V2 / R2;
Display the values and wait for a response of Y or N into the variable Q.
If (Q == 'Y')
Go = 1;
else
Go = 0;
Implementation details are left as an exercise for the student.
Will Build Nuclear Missile For Food - No Target Too Small
|
|
|
|
|
Roger Wright wrote:
Implementation details are left as an exercise for the student.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
I've always wanted to say that, I heard it so often in college. Now that I'm a college teacher, I can.
Will Build Nuclear Missile For Food - No Target Too Small
|
|
|
|
|
Roger Wright wrote:
I've always wanted to say that
Yeah i know what you mean , never miss a change when you want to do it.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
Hello everyone:
How to get system time to micro second?
Thank you.
-Freehawk
|
|
|
|
|
Using QueryPerformanceCounter, see article in recent MSDN magazine:
http://msdn.microsoft.com/msdnmag/issues/04/03/HighResolutionTimer/default.aspx
Edward
|
|
|
|
|
Thank you very much for the fast reply.
-Freehawk
|
|
|
|
|
Hello everyone, i was wondering how to copy from one string to another.
for example.
I am reading a line from a file, lets say
1234 Jack
I want to parse the 1234 to temp and Jack to temp2
between 1234 and Jack is a space.
I have tried using the find and the replace function of string, but have not succeded, if anyone could help me out, it
none
|
|
|
|
|
Perhaps you could explain what the problem is and show us your code ? You want to find the index of the space, and then create two new strings, from memory CString has Left(), Mid() and Right() functions to do that.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Well here is what i am trying to do..
As you can see, i am reading from a file and putting it into buff. At first run of the look buff has
1234 Jack
what i want to do is put 1234 into temp and Jack into temp2.
CString temp,temp2
temp = "";
temp2 = "";
while( !m_sfile.eof() ) {
m_sfile.getline( buff, 256 );
}
none
|
|
|
|
|
Try this instead:
std::string name;
int number;
while( !m_sfile.eof() )
{
m_sFile >> number;
m_sFile >> name;
}
This will do it. Plus it does not taint the standard library with CString. It's much neater than string mashing.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I does not work, i get an error.
C:\TIME TRACKER\TimeTracker\TimeTrackerDlg.cpp(283) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >' (or there is no a
none
|
|
|
|
|
The std::string cannot be read from stream via >> , because the stream doesn't know, where should be the end of the string. std::istream haven't any parse capabilities (except of simple getline , that isn't useful in your case).
Try Tokenizer class at Codeproject.
Robert-Antonio
"Science is a differerntial equation.
Religion is a boundary condition."
|
|
|
|
|
Hello,
I am not to experienced with VC++. I would like to write a program that is pretty large. (at least for me) I am having trouble with getting all my ideas on paper or in a plan of something. Any suggestions on a possible (free?) program that I can use to plan a project?
Slaru
|
|
|
|
|
Start with implementing a scientific calculator.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
If you're into Object Oriented programming, you might want to try UML. It's helpful for breaking large ideas into smaller chunks.
There are a number of UML tools available. ArgoUML is pretty nice, and free, too. http://argouml.tigris.org/
|
|
|
|
|
|
i just started learning c++ so it may just be a noob question but i am haveing a problem. I am trying to make a prog that writes names and number to notepad. When i run it it write the names and number but on top of it it has a set of numbers (1245068) and that will happen everytime.
Example:
1245068
John
Doe
5678906
Jaine
Doe
23456789
That is what is on notepad. My question is what i am doing wrong to get that set of number and how to just write the first name then last name then number. If anyone could help it would be appreciated. my code is bellow.
#include<stdlib.h>
#include<iostream.h>
#include<fstream.h>
int main(int argc, char* argv[])
{
int x=0, y=0;
string L_Name[100];
string F_Name[100];
int number[100];
char resp;
//Reads if there is already info in there and puts it into array
ifstream read("File.txt");
while(!read.eof())
{
read >>F_Name[x] >>L_Name[x] >>number[x];
x++;
}
read.close();
//Where the user can enter more name
do
{
cout <<"First Name: ";
cin >>F_Name[x];
cout <<"Last Name: ";
cin >>L_Name[x];
cout <<"Number: ";
cin >>number[x];
x++;
cout <<"Would you like to enter another name?(y/n)";
cin >>resp;
}
while((resp=='y')||(resp=='Y'));
y=x;
//writes the origianl names then the new name but here is where i get the
//set of numbers
ofstream write("File.txt");
for(x=0; x<y; x++)
{
write <<F_Name[x] <<endl;
write <<L_Name[x] <<endl;
write <<number[x] <<endl;
}
return 0;
}
|
|
|
|
|
Try it without the endl, if not copy declare a CString and append the name, last name and the phone number into a string and just write the string.
CString temp_string;
temp_string = "";
while.....
temp_string = F_Name[x] + " " + L_Name[x] + " " + number[x];
write<
|
|
|
|
|
OK, let's have a look.
You included iostream.h and fstream.h, you should just include iostream and fstream ( drop the h ). The .h versions are the ones created prior to the standard. I think you'll find that you'll then need to put using std::cin;, etc. for all the parts of iostreams you use. Namespaces are just one benefit of using standard headers.
You should also investigate using std::vector to hold your data, and probably put it in a struct. The first so you don't have a limit to how many items can be entered, the second to connect the three pieces of data you collect.
I dunno what your main problem is though, I'd try flushing the stream perhaps (cin.flush() from memory), or perhaps using the standard C++ headers will even solve the problem.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
ya i tryed putting it in a stuct but it would do the same thing so i just tryed it with it out
|
|
|
|
|
The struct won't solve your problem, it merely makes your design better. Add an iostream inserter/extracter and things would be really nice.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|