Just some interesting applications of the bitwise and (&), or (|) operators. You might find some other uses.

Member Avatar
Member Avatar
+0 forum 1

**Problems 1: Spiral matrix - Advanced** Source of the problem: [Here (not in English)](http://www.spoj.com/PTIT/problems/BCACM11B/) Spiral matrix is formed by filling number 1 in 1st row 1st column, after that, filling with increasing number by clockwise, example: 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9 Write a program that inform the value of cell (x, y) of a square spiral matrix sized n x n. *Input:* First row record the number of tests, not greater than 100. Each test record in one row, include …

Member Avatar
Member Avatar
+0 forum 1

Can someone check if I am doing these right please, thanks ? int a=3, b=5, x; x= a/b + b/a +a%b + b%a; cout << x; // x=0+1+0+1= 2 y=float(b/a)+ float(b)/a; cout << y; // y=1.6+1=2.6 z=a*b/2; cout << z; // z= 4 w=pow(b, a)+sqrt(a+b); cout << w; // w=125+2sqrt(2) int a=4, b=7, x; a++; --b; x=a+b; cout<<"x"<< x; //x=11 a=4; b=8 x=a++*--b; cout<<"x="<< x; //x=35 a=3; b=5; a+=3+b; b*=2; x=a+b; cout<< "x="<< x; //x=13

Member Avatar
Member Avatar
+0 forum 3

# Tutorial On Operators# *Operators are the signs to the tell the compiler to perform specific task*. The Operators fall into following categories :- Arithmatic Operator Relational Operator Logical Operator Bitwise Operator Miscellaneous Operator(i added Assignment Operators in this categeory) **Arithmatic operators:-** There are following arithmetic operators:- + Add [6+2=8] - Subtract [6-2=4] * Multiply [6*2=12] / Divide [6/2=3] % Modulus(Reminder) [7%2=1] **Relational Operator :-** Relational Operators are used to compare 2 values and result in true [1] or false [0]. < less than > greater than <= less than equal to >= greater than equal to == equal to …

Member Avatar
Member Avatar
+5 forum 10

This assignment asks to add some code from to a previous assignment I had. I have been confused about this overload operators alot and im confused on how to do it in my code any help with this will be good A) overload the >> operator to allow for reading a new name and new balance from the keyboard and use the data to update the object's data members B) Overload the << operator to dsiplay the Name, Balance, and Interest Rate of an object on the screen with proper labels. C) Overload the += operator to allow an increase …

Member Avatar
Member Avatar
+0 forum 7

Hi folks, I am aware this is a problem that many people have, but I am yet to find an answer... I have a 10x10 grid generated using a html `<table>`, each cell has an id reffering to its location (ie. #15 - row 1, colmn 5). All I need is a snippet that will take the cell id, and add one -> #15 becomes #16, rather than #151... I can use normal Javascipt or jQuery, whichever is easiest :) Thanks in advance!

Member Avatar
Member Avatar
+0 forum 4

I came across the foll code: #include<stdio.h> main() { int i=4,j=7; j=j||(printf("you can")&&(i=5)); printf("%d %d",i,j); } output: 4 1 Athough I am specifying the braces for the && operator so that it gets executed first..Then also the value of i remains 4 only..Why doesnot it gets changed to 5??Also the printf doesnot execute??

Member Avatar
Member Avatar
-1 forum 9

The comparison operators: * === * <=> * eql? * equal? * == Both are performing equality check I know. Some of them overrides `==` also. But now my query is how to think,what to use in what situations? Explanation with a code would be better idea to understand. Thanks in advance!!

Member Avatar
Member Avatar
+0 forum 4

As someone who is new to Javascript, I find it kind of odd that Javascript doesn't seem to have a != operator. Is there a rationale why the language was designed this way?

Member Avatar
Member Avatar
+0 forum 2

Hi I'm been trying to enter numbers into the <input> so I can calculate **Add** - **Subtract** - **Divide** - **Multiply**. This is the equations: <?php $number = 20; $number += 10; print "\$number += 10;<br /> The answer is <b>$number</b>. <br /><br />"; $number -= 12; print "\$number -= 12;<br /> The answer is <b>$number</b>. <br /><br />"; $number *= 14; print "\$number *= 14;<br /> The answer is <b>$number</b>. <br /><br />"; $number%= 16; print "\$number %= 16;<br /> The answer is <b>$number</b>. <br /><br />"; ?> This is my **form**: <html> <body> <form action="number.php" method="get"> Enter number: …

Member Avatar
Member Avatar
+0 forum 8

Hi guys. I am having issues with the output of this program. Can somebody tell me what I have to do to make this work correctly? Here is the code I have so far: import java.util.Scanner; //text scanner to parse primitive types and strings using regular expressions. public class Operations { private static Object total; @SuppressWarnings("resource") public static void main(String[] args) { Scanner input=new Scanner (System.in); int num1=0, num2=0; System.out.printf("Enter First Number:\t "); num1=input.nextInt(); System.out.printf("Enter Second Number:\t "); num2=input.nextInt(); System.out.println(""); System.out.format("%1s%25s","Operation","Result\n"); String fmt = "%-28s %-7d \n"; String solution1= Integer.toString(num1) + "+" + Integer.toString(num2); System.out.printf(fmt, solution1, total); String format1 = …

Member Avatar
Member Avatar
-2 forum 6

Why does first two eg give true when a check done on them using if(x==y) but 3rd and 4th case give false? eg1: `String x = "Hello", y="Hello" ` eg2: `String x = "Hello";` `String y= "Hello";` eg3: `String x="Hello";` `String y = new String("Hello");` eg4: `String x = new String("Hello");` `String y = new String("Hello");`

Member Avatar
Member Avatar
+0 forum 3

The o/p is 10. But shouldn't it be 9? Is it got anything to do with Postfix or variable scoping has a role to play?

Member Avatar
Member Avatar
+0 forum 2

I need a code which can solve the equations like this :- 56*78+(78/8) In this we know that brackets must be solved first and then divide/multiply and then add/subtract. So, i need a code for solving this kind of equations which contains multiple operators in single line. Thnks :)

Member Avatar
Member Avatar
+0 forum 4

Hi all, I have a rather basic C/C++ question about the priority of the ++ operator in regard to pointers. Note the following code (joining two strings): #define LENGTH 255 void mystrcat (char *base, char *add) { while(*base) ++base; while( *(base++) = *(add++) ); } int main() { char name[LENGTH]="Feline"; char lastname[LENGTH]=" Hazard"; mystrcat(name,lastname); printf("My name is: %s", name); return(0); } Now the function mystrcat joins lastname to name but I don't understand exactly why. At the end of the 1st while loop (line 3) base should be pointing to the terminal zero (\0) of the base string, right? Now, …

Member Avatar
Member Avatar
+0 forum 7

[code]main() { int a=5; a=++a + ++a; printf("%d",a); }[/code] the output is 14..how come?

Member Avatar
Member Avatar
+0 forum 8

Hi guys i need a little help fast i have a calculator and its giving me some problems This calculator reads from a text file the result shows in the terminal but its giving me some troubles For one only the + operator works I cant use the overflow function correctly it just gives me the overflow message in an infinite loop those are my two main problems and i dont know what to do can anyone help pls [code] MAX_BUFFER equ 2048 ; Constante que sera' usada como tamanho maximo de cada bloco lido do ficheiro (2kb) FICH_ABERTURA equ …

Member Avatar
+0 forum 0

My assignment is to write a program that outputs the following columns of numbers using mathematical operators and the loop index. This is what I want the program to output: [CODE]1 10 0 1 1 0 2 20 1 4 2 0 3 30 2 9 3 0 4 40 3 16 4 0 5 50 4 25 0 1 6 60 5 36 1 1 7 70 6 49 2 1 8 80 7 64 3 1 9 90 8 81 4 1 10 100 9 100 0 2[/CODE] *I couldn't get the top row aligned right. The top …

Member Avatar
Member Avatar
+0 forum 5

So I'm trying to write a program that is due tomorrow. I am trying to overload operators and dealing with template classes. I have everything written already but keep getting this error whenever i try to compile the driver file: NOTE: proj4.cpp has #include "box.h" and box.h compiles fine, but it says box.h has errors whenever i try to compile proj4.cpp student@student-desktop:~$ g++ -c proj4.cpp box.h: In member function ‘void listT<elemType>::insert(elemType) [with elemType = Box]’: proj4.cpp:51: instantiated from here box.h:18: error: ‘bool Box::operator<(Box&)’ is private listT.cpp:63: error: within this context Here is some of the code that I think is …

Member Avatar
Member Avatar
+0 forum 4

I attempted to overload the == operator for one of my classes, I even copied a previous implementation of it, but now that I am using pointers it refuses to function properly here is the relevant code (there is a lot so I will provide more if need be) [CODE]#ifndef __MESSAGE_H #define __MESSAGE_H #include <iostream> using namespace std; class Message { public: Message(int idnum, char* inmsg); ~Message(); Message(const Message* &m); Message & operator= ( const Message & assignFrom ); bool operator== ( const Message* & m ) const; bool operator!= ( const Message* & m ) const; friend istream & …

Member Avatar
Member Avatar
+0 forum 4

Hey, I have a set of types which are all arithmetic (have operators for addition, subtraction, multiplication, etc.). I want to aggregate any number of them into a single object, so I'm using the std::tuple class template and the <tuple> library (and Boost.Tuple for backward compatibility). My question is a bit of a shot in the dark: Has anyone heard or seen a tuple-like class template that implements all the arithmetic operators? For example, the std::tuple and boost::tuple classes both implement all the comparison operators which will only compile correctly if all the types contained in the tuple also have …

Member Avatar
Member Avatar
+0 forum 4

For some people it may be difficult to understand what Boolean is.Well, it's a type of algebra. We will be learning about three Boolean operators today-AND,OR,NOT The order for evaluating Boolean operators are as follows:- AND-If you have a code that should be executed if two conditions are true, you use the and operator.And is shown as [U]&&[/U] in C++.1 && 0 will evaluate to 0 because one of them is false. OR-Same as and, but either or both of the conditions must be true.Or is shown as [U]||[/U] in C++.1 || 0 will evaluate to 1 since one of …

Member Avatar
Member Avatar
+0 forum 2

Is it possible to create operator overloads for non-objects (like typedef-ed arrays)?

Member Avatar
Member Avatar
+0 forum 3

Hi, i have some issues with class inheritance and i do not know how to solve it, maybe someone could help me with that ? [CODE] //pentathlete.h #include <iostream> using namespace std; template < class T > class pentathlete { protected : T comp_res [ 5 ] ; /*private: int sum_res ;*/ public : class error_1 { } ; class error_2 { } ; T sum_res ; pentathlete ( ) { for ( int i = 0 ; i < 5 ; i ++ ) { comp_res [ i ] ; } sum_res = -1 ; } pentathlete ( int …

Member Avatar
Member Avatar
+0 forum 2

Is it possible to overload an operator for a built-in type? And if so what is it's syntax? EG: [CODE]//Use of overloaded operator^ for types double and double (assuming it is overloaded for exponent): double a=10.0; double b=2.5; double pow=a^b;//pow is approximately 316.22....[/CODE]

Member Avatar
Member Avatar
+0 forum 1

I am working on making a 'safetype' abstract class, which will have a complete set of pure virtual operator overloads to help make sure that a class inherited from it is safe to pass to virtual any function. The problem is that I don't know the syntax of a pure virtual operator overload or if any of the operators are unable to be virtualized. Can somebody give me an example of how to write a pure virtual operator, as well as list any operators that cannot be made purely virtual?

Member Avatar
Member Avatar
+0 forum 2

The End.