Tuesday, July 14, 2009

May I get C++ program for Genetic algorithm with binary coded single point cross over,?

May I get C++ program for Genetic algorithm with binary coded single point cross over, roulette-wheel selection operator , or any site can help me on this

May I get C++ program for Genetic algorithm with binary coded single point cross over,?
no
Reply:Yes

clematis

I need help with C++ Programming. We are using Dev C++?

I am so lost...


I am attempting to create a program that first asks to enter an


integer between 0 and 35. If the number is less than or equal to 9, the


program should output the number; otherwise it should output A for 10, B for


11, C for 12,...so on... and Z for 35. Then it tells me to use the cast operator, static_cast%26lt;char%26gt;(), for numbers %26gt;=10.





I am just lost period on how the static_cast function works...I have spent hours trying to find information...and figure it out!

I need help with C++ Programming. We are using Dev C++?
static_cast%26lt;int%26gt;("A") = 65





gives you the ASCII value of the character





Whole program:================================...





char array[25]={'A','B',.....'Z'}





cout %26lt;%26lt; "Enter number: ";


cin %26gt;%26gt; number





if(number %26lt;= 10){


cout %26lt;%26lt; number;


}


else


cout %26lt;%26lt; array[number- 10];





That is the basic program you need to write it will work just dress it up to look pretty
Reply:Okay.. So here's the thing.. Characters and integers are closely related. If you store the value "65" in a char you get the letter "A" if you store the value "65" in an integer you get the number 65. With that said, it should make a little more sense that you can cast an integer into a character and vise versa. Casting will work like this:





int myint = 65;





char ch = (char) myint; //casts myint to a character





cout %26lt;%26lt; "myint " %26lt;%26lt; myint %26lt;%26lt;"\n";


cout %26lt;%26lt; "myint casted to char" %26lt;%26lt; ch;








try that code in your program and see what happens.





The general form of casting is (%26lt;datatype%26gt;) %26lt;object%26gt;.








I'm a bit rusty with the C++ but hopefully this help.


C++ for beginners desperate for answers please help?

I really need your help please answers the questions 5 points for the best answer!





Explain the following bitwise operations in C++


a) and b) or





what is meant by the term zero indexed





what does the address operator do





list the permission values assigned to the number 0,1,2, and 4

C++ for beginners desperate for answers please help?
Q) Explain the following bitwise operations in C++





a)and





For each bit in the source and destination, "and"


results in a "1" only if *both* inputs are "1"





0 %26amp; 0 = 0


0 %26amp; 1 = 0


1 %26amp; 1 = 1


1 %26amp; 0 = 0








b) or





"or" results in a "1" if *either* inputs are "1"





0 | 0 = 0


0 | 1 = 1


1 | 1 = 1


1 | 0 = 1








Q. what is meant by the term zero indexed





It means that the first element of an array


is index "0". Some languages base their arrays


from element 1 (ie. Fortran). Others


allow the first element index to be user


specified (ie. Pascal).





Q. what does the address operator do





It returns the value of the "location" of a variable


in memory. It allows a "pointer" to refer to


a variable (by holding the variable's address).





Q. list the permission values assigned to the


number 0,1,2, and 4





I assume that this is about Unix permissions


which uses bits to specify read "r", write "w"


and execute (x).





0 = 000 ==%26gt; no read, write, or execute permission


1 = 001 ==%26gt; execute only (no read or write)


2 = 010 ==%26gt; write only, no read or exec


4 = 100 ==%26gt; read only, no write or exec
Reply:Ahhh... I'm always a bridesmaid but never a bride.. hehehe.. In any event...





1) BITWISE OPERATIONS:





The bitwise-AND operator ("%26amp;") compares each bit from the first operand to the corresponding bit in the second operand. If both bits are 1, the corresponding resulting bit is 1. Otherwise, the resulting bit is 0.


EXAMPLE:


1011


%26amp; 1101


----------


1001





The bitwise-inclusive-OR operator ("|") compares each bit from the first operand to the corresponding bit in the second operand. If either bit is 1, the corresponding resulting bit is 1. Otherwise, the corresponding resulting bit is 0.


EXAMPLE:


1011


%26amp; 1101


----------


1111





The bitwise-exclusive-OR operator("^") compares each bit of its first operand to the corresponding bit of its second operand. The result in each position is 1 if the two bits are different, and 0 if they are the same.





EXAMPLE:


1011


%26amp; 1101


----------


0110








2. ZERO INDEXED.


When you have an array, the first element is referenced in that array is the "zero" element. This is due to our ecumenically historic approach to numbers... Thanks to an Indian named Pingala and later by the Greeks, "0" (zero) is recognized in our numbering system. So if we count by ten's, the actual numbers are ZERO through 9:





C | X | I (excuse the roman numerals)


----------------


1 2 0





So in the "one's" column, we have "0" or our first non-number, number...


With ALL MY HOT AIR extinguished... here's a C++ reference using the "0" element:





int nMyIntArray[20];





nMyIntArray[0] = 12; // The first array element equals 12.


nMyIntArray[1] = 24; // The second array element equals 24.





I need a drink....





3. ADDRESS-OF OPERATOR.


The address-of operator ("%26amp;") provides the address of a operand. The address-of operator can only be applied to variables with fundamental, structure, class, or union types that are declared at the file-scope level, or to sub-scripted array references.








4. PERMISSION VALUES:


This one, you've got me stumped... Typical permissions implement a scheme with relative numeric definitions applying to the scheme design. So without knowing what system of security you're thinking of, these numbers have no apparent or inherent security rights...


C++ for beginners desperate for answers?

i really need your help badly





describe the differences between a compiler error and a link error





explain the following bitwise operations in c++


a) and b) or





what is meant by the term zero indexed





what does the address operator do





what is a UML





list the permission values assigned to the number 0,1,2, and 4

C++ for beginners desperate for answers?
You really ought to do this part yourself. With so many questions, you could have least presented us with your answers—right or wrong.





This is the easy part. If you don't truly take the time and energy to research and understand these fundamentals, and you continue with such laziness and indifference, you will most certainly get a poor grade.





What will you do when it comes time to design, write, and debug increasingly complex programs?





______________
Reply:A compiler error means an error was discovered while compilation which could be a syntax error (e.g. you forgot a semicolon) or a semantic error (e.g. you make an equality between a string and an integer).


A link error means an error was discovered while linking, consider the following code:


void Factorial(int num);


void main()


{


printf("%d", Factorial(4));


}


Here, you told the compiler that you have a function called "Factorial" and you tried to use it while you didn't specify how it works.





--------------------------------------...





Try to realize "AND" and "OR" logically, for example:


AND means that both conditions are true while "OR" means at least one of the conditions is true. By using such definition as bitwise operators:


5 AND 4 = 4


If you considered that "1" means "true" and 0 means "false" then by converting 5 and 4 to binary values:


1 0 1 (5)


1 0 0 (4)


--------


1 0 0 (4)


The most left bit in the result is the only bit which is "1" because the most left bit in both "5" and "4" is "1".


By ORing them:


1 0 1 (5)


1 0 0 (4)


-------


1 0 1 (5)


Because OR requires only one of the bits to be "0" so the first and last bit were "1".





----------------------





Zero indexed means that "0" represents the first item in a collection. For example when you want to get the value of the first element in an array you use the following way:


int x[4];


int y;


y = x[0];


Because arrays are zero indexed, so you refered to the first item by "0" not "1".





----------------------





The address operator shows where the variable is stored in the memory not the value. For example:


#include %26lt;stdio.h%26gt;


void main()


{


int x = 5;


printf("%p %d", %26amp;x, x);


}


This program will output where "x" resides in the memory and the value stored in that location.





------------------------------





UML is a modeling language which is used for designing programs, it stands for "Unified Modeling Language". It is mainly composed of some figures which represents the components of that program and the relation between them.





---------------------------------





Unfortunately I don't understand the last question, sorry.
Reply:A compile error occurs because the source code has a logic error in it. A link error occurs when you try to link you code to already compiled libraries





I never did get bitwise operators try this:


http://www.cprogramming.com/tutorial/bit...


personally i never use them.





Zero indexed (i think) means that an array (or array like data) is indexed starting at 0. So the first item would be name[0], the second item name[1] and so on. Note: There is a philosophicall diffrene from how we normally think. Exe first cow is cow 1 second 2 ect.





If its this "%26amp;" it returns the address of the variable that it is in front of instead of the value of the variable.





UML is a type of way to map out what your program is going to do. I don't use it so I would look here:


http://en.wikipedia.org/wiki/Unified_Mod...





Honestly I have no clue Good luck.
Reply:If you're talking about UNIX permissions, this site (http://www.perlfect.com/articles/chmod.s... should help.


C++ input question?

so here is the thing I have a program broken up into classes with there appropriate implementation files.





This problem im getting is that the in the main menu I created when the user inputs there choice from the menu ive done it like this:





basically its





cin %26gt;%26gt; choice;





switch(choice)


{


case 1:





break;





}





and so on.





But once they choice is made there is a conflict because the choice is taken in by the cin %26gt;%26gt; operator and the first thing taken in after the choice is made is using the getline because it needs to be able to take spaces. So the question is this....





Is there another way I can do my menu so that it doesnt use cin? I tried doing getline but it doesnt work with switch or if statements for some reason.





Since getline is from C not c++ is there an equevalent that will work for my situation???





thanks for reading!

C++ input question?
Q


But once they choice is made there is a conflict because the choice is taken in by the cin %26gt;%26gt; operator and the first thing taken in after the choice is made is using the getline


End Q


See http://www.daniweb.com/tutorials/tutoria... .





Q


Is there another way I can do my menu so that it doesnt use cin? I tried doing getline but it doesnt work with switch or if statements for some reason.


End Q


Let me guess, choice Is an integer? Because if you take a look at getline (http://www.cplusplus.com/reference/strin... ), you’ll see that it requires a string. There’s a C string version and then there’s a C++ string version. Either one you can convert to an integer for using in a switch statement. But you need to go the conversion route with getline.





Q


Since getline is from C not c++ is there an equevalent that will work for my situation???


End Q


Getline is from C++ not C. What references are you using? Get better ones.
Reply:Before the line


cin%26gt;%26gt;choice,


add the line


fflush(stdin);


There are chances that this may work out.

columbine

PLEASE HELP ME WITH THIS: using multiple if-else and ternary operator...?

make a c program that will ask the user to enter a number. the program should display "POSITIVE ODD","NEGATIVE ODD","POSITIVE EVEN","NEGATIVE EVEN"... depends on the number....


please use multiple if-else condition...





please!!!!! i just need it for our midterm....





also using ternary operator...











example output:


enter a number: 56


POSITIVE EVEN!





please help me with this peeps...





hope u understand...


thanks!!

PLEASE HELP ME WITH THIS: using multiple if-else and ternary operator...?
Using CONDITIONAL (TERNARY) operator:





#include %26lt;iostream.h%26gt;





void main(){


signed int num;





cout %26lt;%26lt; "Enter Number" %26lt;%26lt; endl;


cin %26gt;%26gt; num;


cout %26lt;%26lt; ((num %26gt; 0) ? "POSITIVE " : "NEGATIVE ");


cout %26lt;%26lt; ((num %26amp; 1) ? "ODD" : "EVEN");


}





--------------------------------------...





Using IF - ELSE statements:





#include %26lt;iostream.h%26gt;





void main(){


signed int num;





cout %26lt;%26lt; "Enter Number" %26lt;%26lt; endl;


cin %26gt;%26gt; num;


if(num %26gt; 0)


{


cout %26lt;%26lt; "POSITIVE ";


}


else


{


cout %26lt;%26lt; "NEGATIVE ";


}


if(num %26amp; 1)


{


cout %26lt;%26lt; "ODD";


}


else


{


cout %26lt;%26lt; "EVEN";


}


}








OUPUT:





Enter Number


32


POSITIVE EVEN





Enter Number


-33


NEGATIVE ODD
Reply:not know c, but if you can translate from basic...


cls


do


input "enter a number";num


a=int(num/2)


b=num-a


if a=b then a$="even" else a$="odd"


If num%26lt;0 then c$="negative"


if num%26gt;0 then c$="positive"


Print"number "num is "c$;" and";a$


loop until inkey$%26lt;%26gt;""
Reply:#include %26lt;iostream.h%26gt;





main() {


int num;


cout%26lt;%26lt;"Enter a number: "


cin%26gt;%26gt;num;


if(num %26gt;= 0) {


if(num%2 != 0) {


cout%26lt;%26lt;"POSITIVE ODD";


}


else {


cout%26lt;%26lt;"POSITIVE EVEN";


}


}


else {


if(num%2 != 0) {


cout%26lt;%26lt;"NEGETIVE ODD";


}


else {


cout%26lt;%26lt;"NEGETIVE EVEN";


}


}


}





Thats the basic structure, although you probably won't be able to copy/paste it and have it work. The guy above me doesn't use the mod operator (the % sign), so his code is slightly more complicated than mine. I think mine is what your teacher is looking for. You should really read a book or ask the teacher if you have further problems. One thing I've learned from going to Yahoo Answers for support on programming bugs is that they aren't as helpful as the teacher/professor.





Happy Programming.


Beginner C++ question?

Hi, I'm just learning how to use C++ and I'm having some problems with Objects and plugging variables from one class into another. Right now I'm designing a simple calculator program with various classes, each one associated with seperate operators, example Addition class, subtraction, etc. The driver class(Calculator in this case) will accept 2 values from the user and let him/her decide which operator to perform. If the user chooses to add them together then int Value1 and int Value2 should be forwarded to the Addition class which simply returns the two values after adding them together. My only problem is I'm not entirely sure how to do this, in Java I'm assuming I would say something along these lines. Addition new = Addition(Value1, Value2);. then just, return Addition;





Any ideas?

Beginner C++ question?
You could put the operands into the constructor and instantiate a new Addition each time (as in your example), or reuse a single Addition instance via method setOperands( int left, int right ), or methods setOperandLeft( int value ) setOperandRight( int value ).





In either case, to get the result you could have a method


int getResult()


which would generate the reult and return it.





example usage:


Addition newAddition = new Addition(Value1, Value2);


int result = additionInstance.getResult();


free(newAddition);


return result;


*or, under the reuse scenario:*


additionInstance.setOperands( value1, value2 );


display(additionInstance. getResult())





To really get into the spirit of things, Addition should be a subclass of Operation, or even of BinaryOperation which would be a subclass of Operation. The superClass would fully define the setOperands() methods and would include an abstract of the getResult() method. This would allow you to manipulate Operations in a general manner without knowing which operation was involved in every step.





Java would follow the same layout. Since free() is unnecessary, the first example usage shorthens to:


Addition newAddition = new Addition(Value1, Value2);


return additionInstance.getResult();





Hope this helps
Reply:C and C++ work with "pointers" and references (just C++)...so for your case you MUST make sure you pass your "int" values as "%26amp;Value1" and "%26amp;Value2" and set your param for the function with *Value1 and *Value2 .... or just make your function param as "%26amp;Value1" and "%26amp;Value2" and when the variables get passed in they will be passed by reference.





See this example: http://publib.boulder.ibm.com/infocenter...