|
-
July 13th, 2009, 10:40 AM
#1
Recalling Memory Functions
I have been working on a program that uses 2 memory blocks, one of which is recalled from the previous program in the same file. The "tReg" program is suppose to use the "FallingEdgeDet". the code i have so far is posted bellow. It does not work mainly because of the incorrect way I am trying to call the previous program. A little back round to make this easier to understand, The input of the program is "T" the output of the FallingEdgeDet in the "tReg" program is "U" the memory block of the FallingEdgeDet in the "tReg" is "F" the input to the 2nd memory of the "tReg" is the output of the entire program "Q". This memory block is labeled "M" the output of "M" is "R", "R" and "U" go into an XOR gate which has the proper programing.
// function: Falling Edge Detector
class FallingEdgeDet {
bool M;
public:
FallingEdgeDet() {
M = 0;
}
void operator () (bool A, bool & Z) {
bool C;
C = M;
Z = !A&&C;
M = A;
}
};
//test function FallingEdgeDet
void testFallingEdgeDet () {
FallingEdgeDet M;
bool A, Z;
char ans;
while (
cout<<"would you like to test?",
cin>>ans,
ans=='y'
)
{
cin>>A;
M(A,Z);
cout<<Z<<endl;
}
}
//Toggle Register
class tReg {
bool FallingEdgeDet(), M;
public:
tReg(){
M = 0;
}
void operator () (bool T, bool & Q){
bool U, R;
FallingEdgeDet(F(T,U));
R = M;
Q = U!=R;
M = Q;
}
};
-
July 13th, 2009, 11:15 AM
#2
Re: Recalling Memory Functions
Please use code tags for posting code so it is readable.
Code:
while (cout<<"would you like to test?", cin>>ans, ans=='y')
This doesn't work. While doesn't know what to do with a comma. You will get a warning about it... don't ignore this warning. Use && or || to combine checks.
one of which is recalled from the previous program in the same file
Which previous program are you talking about ?
extra tip : STOP using one letter variables like A, B ,C ,T ,Q. It's messy and unprofessional and it's asking for trouble because you can't see what you are doing. Give variables meaningful names.
-
July 13th, 2009, 11:38 AM
#3
Re: Recalling Memory Functions
HTML Code:
// function: Falling Edge Detector
class FallingEdgeDet {
bool M;
public:
FallingEdgeDet() {
M = 0;
}
void operator () (bool A, bool & Z) {
bool C;
C = M;
Z = !A&&C;
M = A;
}
};
//test function FallingEdgeDet
void testFallingEdgeDet () {
FallingEdgeDet M;
bool A, Z;
char ans;
while (
cout<<"would you like to test?",
cin>>ans,
ans=='y'
)
{
cin>>A;
M(A,Z);
cout<<Z<<endl;
}
}
//Toggle Register
class tReg {
bool FallingEdgeDet(), M;
public:
tReg(){
M = 0;
}
void operator () (bool T, bool & Q){
bool U, R;
FallingEdgeDet(F(T,U));
R = M;
Q = U!=R;
M = Q;
}
};
Reply With Quote
you can see there are 2 programs written, 1 is called FallingEdgeDet the other tReg the names are commented out at the top.
-
July 13th, 2009, 12:03 PM
#4
Re: Recalling Memory Functions
They are called classes... not programs. Programs are executables.
Your class...
Code:
class tReg
{
Are these 2 members public, protected of private ?
bool FallingEdgeDet();
bool M;
public:
tReg()
{
M = 0;
}
void operator () (bool T, bool & Q)
{
bool U, R;
FallingEdgeDet(F(T,U));
R = M;
Q = U!=R;
M = Q;
}
}
Code:
bool FallingEdgeDet();
Where is this function ? It's not a part of your class, or you didn't post the code.
Code:
FallingEdgeDet(F(T,U));
You are declaring a class but you are not using it. I can only assume that you declare this class to use the () operator. In this case you can make a separate function of it instead of mis-using a class as a function container.
Also, you are talking about memory blocks ... I don't see any memory blocks.
Last edited by Skizmo; July 13th, 2009 at 12:06 PM.
-
July 13th, 2009, 12:35 PM
#5
Re: Recalling Memory Functions
Code:
function: Falling Edge Detector
class FallingEdgeDet {
bool M;
public:
FallingEdgeDet() {
M = 0;
}
void operator () (bool A, bool & Z) {
bool C;
C = M;
Z = !A&&C;
M = A;
}
};
in case you havent been able to tell I am very new to this, this is only the second week of using c++
this is the FallingEdgeDet this section of code with the header and the produce a command prompt window which allows me to put in the input either 1 or 0. so again. now again I am new to this so I will try to make this as simple as possible so i dont confuse anyone anymore. I am trying to get the program above, minus the test part of the function, to be used in this function :
Code:
class tReg
{
bool M;
public:
tReg()
{
M = 0;
}
void operator () (bool T, bool & Q)
{
bool U, R;
R = M;
Q = U!=R;
M = Q;
}
}
I have removed my horrid attempts at doing this so its just an unfinished code, below ill provide an example of exactly what im trying to do.
Code:
#include <iostream>
using namespace std;
//halfAdd
void halfAdd(bool a, bool b, bool & sum, bool & carry)
{
sum = a!=b;
carry = a&&b;
}
//fullAdd
void fullAdd (bool a, bool b, bool c, bool & carry, bool & sum)
{
bool c1, c0, s0;
halfAdd (a,b,c0,s0);
halfAdd (s0,c,c1,sum);
carry = c0||c1;
}
in this code i wrote a function labeled halfAdd, in the next function which is labeled fullAdd, i used the halfAdd function to evaluate.
also the 2 members are public
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|