2,712 Posted Topics

Member Avatar for miskeen

Whats the general form? From that example, you can do something like this : [code] unsigned int var1 = 11; long var2 = 5; long var3 = 3; unsigned int final_var = var1 &0x3; final_var <<= 2; final_var |= (var2 & 0x01); final_var <<= 1; final_var |= (var3&0x1); [/code]

Member Avatar for miskeen
0
109
Member Avatar for ashkash
Member Avatar for Dougie

I think I am one of few without a Facebook. Even my uncle has one.

Member Avatar for oldgamesware
0
169
Member Avatar for bandit711

Can you gives us a picture or something that shows how the output should be?

Member Avatar for bandit711
0
172
Member Avatar for thileep

Virutal inheritance comes into play when you inherit from two classes and both of those class inherit from the same base class. Its called the diamond shape inheritance. Here is an example : [code] struct Base{ }; struct A : Base{ }; struct B : Base{ } struct C : …

Member Avatar for mrnutty
-2
80
Member Avatar for #define

I don't think thats possible. Obviously, you will have to iterate over all the elements to reverse the order. I think the best you can do is : O(log(n))

Member Avatar for Narue
0
83
Member Avatar for Fenlevi

Do something like this : [code] int nearSqrt(int num){ int n = sqrt(num); return n*n; } [/code] That returns the nearest square number. For it to be greater than num,you need to return (n+1)*(n+1);

Member Avatar for Robert1995
0
101
Member Avatar for heynow12

put the "cout << endl; " at the end of the first for loop. So do this : [code] for(i=1;i<5;i++) { for( j=1;j<6; j++) { infile>>random[i][j]; cout<<random[i][j]<<endl; } cout<<endl; } [/code]

Member Avatar for jonsca
0
158
Member Avatar for NitaB

[URL="http://www.cplusplus.com/reference/clibrary/cmath/pow/"]This [/URL]link shows the function prototype that pow function takes. Make sure you match one of the function prototype. So for example this code : [code] pow(2,2); [/code] will not work since pow does not overload pow(int,int) . But this any of these will work : [code] pow(2.0,2.0); pow(2.0,2); pow(2.0f,2.0f); …

Member Avatar for jonsca
0
138
Member Avatar for ChPravin

First correct me in this if I'm wrong. For sum = 0 , return 0; For sum = 1 , return 1; For sum = 2 , return 2; For sum = 3 , return 3; For sum = 4 , return 5; For sum = 5 , return 8; …

Member Avatar for ChPravin
0
90
Member Avatar for PDB1982

use vectors. Here is an example : [code] #include <iostream> #include <fstream> using namespace std; int main(){ vector<float> inputValues; ifstream file("num.txt"); while(!file.eof() || !file.fail()){ float num = 0.0f; file >> num; inputValues.push_back(num); } } [/code]

Member Avatar for mrnutty
0
88
Member Avatar for myz068u

[QUOTE=myz068u;1184716]Please forgive me, but I don't seem to follow... Could you care to explain more?[/QUOTE] 1) start a loop 2) ask for input 3) use the switch 4) continue with loop until exit command entered >>start a loop [code] while( true ){...} [/code] >>ask for input ask for input inside …

Member Avatar for mrnutty
0
104
Member Avatar for Ace1.0.1.

This code : [code] cout << "Enter 1 to create an account : "; int nEntered; cin >> nEntered; for(;;) { if( nEntered == 1) { BankAccount s; cout << " Bank account created\n If you would like to make a deposit press 1"; break; } else { cout << …

Member Avatar for mrnutty
0
1K
Member Avatar for lordvoldemort

You access each individual numbers and multiply them : [code] int Array[2] = {1,1}; int Array2[2] = {5,5}; int result[2] = {}; result[0] = Array[0]*Array2[0]; result[1] = Array[1]*Array2[1]; [/code] Of course there is a lot more to this, but you get the basic idea.

Member Avatar for mrnutty
0
468
Member Avatar for gregarion

This : [code] char array2[arraySize2] ={'A','B','E','F','G','H','J','K','N','O','P','Q','R','S','T','U','W','Y','Z'}; for (int i = 0 ; i < str.length() ; i ++) int b = str.find(array2[i]); [/code] can be replaced with this : [code] if( str.find_first_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ") == string::npos){ letter not found. } [/code] but it seems that you are trying to find the number …

Member Avatar for mrnutty
0
155
Member Avatar for tennis

There are more difference. For instance, when an object gets destroyed, its destructor is called. Whereas when an object gets destroyed, its member function might not be called. Also a destructor has no return type where as an member function could. Looks like what your confused about is polymorphism. Take …

Member Avatar for mrnutty
0
111
Member Avatar for gregarion

Also don't use magic numbers. Use constants. For example : [code] enum FuncReturn{ ALL_DIGITS , INVALID_INPUT }; int myCheck(const string& str){ if(str.find_first_of("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz") != string::npos) return INVALID_INPUT; else if(str.find_first_of("!@#$%^&*()-_+=';[]{}:<>?/.,`~") != string::npos) return INVALID_INPUT; else return ALL_DIGITS; } int main(){ FuncReturn f; f = myCheck("123123143431a"); //.... } [/code]

Member Avatar for mrnutty
0
94
Member Avatar for HoldmysunnyD

Look at it in our eyes. You talk a little and dump a whole *lot of code on us. Make it simpler for us to help you by shows only the relevant code and stating the problem correctly. I have a hunch, that you are not getting the theory behind …

Member Avatar for em-kay
1
283
Member Avatar for gregarion

Its pretty close. You had the right idea to use a for loop and use isdigit function. You just didn't do it correctly. Here are basic steps you can try : 1) Get input into a string 2) Create a for loop from i = 0 to string.length 3) use …

Member Avatar for Robert1995
0
182
Member Avatar for rizzi143

what do you think ? Don't you have a compiler ? Whats confusing you ? So many questions( including yours ) but no answers?

Member Avatar for Salem
0
295
Member Avatar for apo

[QUOTE=some;1177975]In my c++ book it shows how to do it differently. I'll just post that up to so the person who asked can have more options in choosing what he wants to do. I'll use an example to explain it. Suppose you want to display num which stands for 4.91877 …

Member Avatar for jonsca
0
130
Member Avatar for Martje

Nope. What you did makes no sense. A char can only contain 1 char. Use std::string instead.

Member Avatar for WaltP
0
105
Member Avatar for PDB1982

You didn't define a operator+, that takes an int. You only defined a operator+ that takes another Polynomial.

Member Avatar for PDB1982
0
184
Member Avatar for vbx_wx

If your function is write, and it writes to the screen, then just templatized it.

Member Avatar for mrnutty
0
107
Member Avatar for merse

Just for emphasis, an automatic variable is deleted with it reaches the end of its block. So for example : [code] int main(){ { int x = 0; } //x is deleted when it reaches this bracket int x = 3, y = 3 } //x and y is deleted …

Member Avatar for mrnutty
0
137
Member Avatar for Someguynamedpie

>>[B]I don't believe you can call class functions without an object.[/B] It can be done. [CODE] #include <iostream> #include <string> using namespace std; struct Print { static void print(string str) { cout << str << endl; } }; int main(){ Print::print("string"); } [/CODE] But from the looks of it, using …

Member Avatar for mrnutty
0
848
Member Avatar for NitaB

>>[B]info[cols_*row + col];[/B] I don't think this conversion is right. Assuming you are using a 1D array. Then our 1D array indices is like so : 0 1 2 3 4 5 6 7 8 9 10 11 Your conversion equation is " row*col+col ". Say we call matrix(1,1); That …

Member Avatar for NitaB
0
186
Member Avatar for babalonas

You need exactly what you said here "std::cout << "Haha, this is a loop";" You need a loop. Here is an example of for loop. [code] #include <iostream> using namespace std; int main(){ const int MAXLOOP = 100; for(int i = 0; i < MAXLOOP; ++i){ //loop 100 times cout …

Member Avatar for mrnutty
0
48
Member Avatar for AltF4me

Nope. That's the limitation of the linked list. You need to transverse the list to get to a node. Whereas with arrays, you can access the data by indexing. But using linked list, you can delete and insert element very fast, O(1) to be exact.

Member Avatar for AltF4me
0
149
Member Avatar for dusktreader

Close but you still did not need to program for this problem. We have this wonderful formula : [I][U] Fib(n) = round( Phi^n/√5)[/U][/I] We can manipulate the above equation to get the number of digit we are looking for by using logarithm. Fib(n) = log( phi^n / phi(√5) ) Lets …

Member Avatar for dusktreader
0
151
Member Avatar for timbomo

>>[B]can someone show me an example of how you would initiate a variable. [/B] [code] int variable = 0; //declare and initialize the variables [/code] >>[B]how you would fix a undeclaired identifiers.[/B] an undeclaried identifier means that you used a variables that has not been declared. For example : [code] …

Member Avatar for Jiwe
0
135
Member Avatar for caffeine

Yep, I think you need to include sstream as well. stringstream is defined in the sstream header file.

Member Avatar for dusktreader
0
179
Member Avatar for ashwini_rt
Member Avatar for timbomo

[code] void turn_it_is(int play1, int play2) { cout << (((turn_it_is%2)==1)?(play1:play2)); cout << " it's your turn "; cin >> turn_it_is; } [/code] What are you doing? "turn_it_is" is a function. Not a variable!. Why are you trying to use cin >> turn_it_is ? and also why are you trying to …

Member Avatar for Fbody
0
164
Member Avatar for hag++

Most likely, you did not initialize your variables. Also you probably might be writing into memory that you are not supposed to. Because, in debug, the compiler pads the memory more than in release.

Member Avatar for mrnutty
0
264
Member Avatar for buzzykerbox

Do something like this : [code] #include <iostream> #include <ctime> //needed for time int main(){ srand( time(0) ); //seed random number generator string name[3] = { "luke" , "tony", "robert" }; string randomName = rand() % 3; //return a number from [0,3) } [/code]

Member Avatar for mrnutty
0
92
Member Avatar for pinsickle

I like the second one, if it would compile :) And why are u incrementing m two times per a loop.

Member Avatar for Ancient Dragon
0
103
Member Avatar for PDB1982

The function prototype : [code]int operator +(Polynomial &Poly1, Polynomial &ConstValue);[/code] The function definition header: [code]int operator +(Polynomial Polynomial1, Polynomial ConstValue)[/code]

Member Avatar for david.k
0
178
Member Avatar for Galf

If i'm not mistaken, you should be able to return the vector iterator. Maybe an example will help. [code] #include <iostream> #include <vector> #include <string> #include "print.h" using namespace std; class Items{ public: typedef std::vector<string> ItemType; typedef std::vector<string>::iterator Iterator; typedef std::vector<string>::const_iterator constIterator; private: ItemType _weapons; ItemType _potions; public: Items(){ _weapons.push_back("sword"); …

Member Avatar for Galf
0
106
Member Avatar for daniwebrandom

There are a couple of ways you can do this. First you need to create a BigInteger class. It basically adds and subtracts arbitrary long digits. One way to do this is to use a string to hold the number, internally. Then create an add function, that adds one BigInteger …

Member Avatar for daniwebrandom
0
261
Member Avatar for TheWolverine

If you need optimization that badly, then make a look up table with cosine and sinus table.

Member Avatar for nezachem
0
135
Member Avatar for robski

Not quite sure what you mean, but maybe this will help you : [code] switch(option){ case 1 : doCase1(); break; case 2 : doCase2(); break; case 3 : case 4 : doCase3And4(); break; default : break; } [/code] The idea is that if the user picks 3 or 4 it …

Member Avatar for Iamthedude
0
105
Member Avatar for lighten123

string concatenation. If you're saying "...default***/test.txt" is the path, where the user picks what goes in ***, then you can achieve this with string concatenation. For example : [code] string startPath = "...//default"; string endPath = "//test.txt"; string pathNumber = ""; string finalPath = ""; cin >> pathNumber; if(pathNumber != …

Member Avatar for Salem
0
96
Member Avatar for NathanOliver

>>[B] error C2662: 'Number::operator -' : cannot convert 'this' pointer from 'const Number' to 'Number &'[/B] That means you are passing a const object into a non-const function. Const-correct your functions, that is do something like this if you can : [code] Numbers operator+(const Number& num)const;[/code]

Member Avatar for NathanOliver
0
151
Member Avatar for am5a03

your idea is fine. Just don't use stl containers. use regular arrays if you wan't speed since this is all about speed.

Member Avatar for am5a03
0
105
Member Avatar for mertserimer

1) use code tags. `/* code goes here */` 2) Whats your problem. We aren't compilers. We don't just compiler the code in our head and find errors, although we might be able to. 3) `for( int n = 0; n!= 100; n++) re_read_Steps1And2();` 4) Fix those things and post …

Member Avatar for mrnutty
0
178
Member Avatar for shaiksalim

This would be just like adding regular numbers, but instead of carrying when the addition of 2 digits gets 10 or bigger, you will carry when the addition of 2 numbers get 2 or bigger. First now how to add binary numbers in paper. When you try to add binary …

Member Avatar for mrnutty
0
103
Member Avatar for Samuelandjw

sure : [code] class A{ public: const static string ClassName; //declare }; const string A::ClassName = "A";//initialize [/code]

Member Avatar for Samuelandjw
0
55
Member Avatar for winecoding
Member Avatar for mrnutty
0
96
Member Avatar for 88omar

[URL="http://www.play-hookey.com/digital/converting_ff_inputs.html"]Here, [/URL] less work for me to explain.

Member Avatar for mrnutty
0
62

The End.