|
how to conver any base like binary to any base like hexadecimal and octal or others bases give me code
|
|
|
|
|
|
code to convert any base like binary to any base
|
|
|
|
|
Is this a question or a statement?
|
|
|
|
|
Hi Iam trying to convert my Digit To Words class from c# to VC++... And the following line I am facing trouble
String^ strNum;
String^ strNumDec;
String^ StrWord;
strNum = Convert::ToString(Num);
blah..blah...blah...
StrWord = ((double.Parse(strNum) == 1) ? " Rupee " : " Rupees ") + NumToWord((decimal)(double.Parse(strNum))) + ((double.Parse(strNumDec) > 0) ? (" and Paise" + cWord3((decimal)(double.Parse(strNumDec)))) : "");
Thanks for the helps
|
|
|
|
|
Paramu1973 wrote: trouble
And that trouble would be what exactly?
Paramu1973 wrote: blah..blah...blah...
is not valid C++ or C# code.
|
|
|
|
|
What type is Num and why are you converting it to a string just so that you can parse it into a double? Please provide more details of exactly what problem you are trying to solve.
|
|
|
|
|
Thanks Richard...Still I remember your powerful helps.....Num is Decimal and I found the solution...
Thanks Again
|
|
|
|
|
Is it really C# code? 
|
|
|
|
|
Create an STL vector of 10 integers and store initial values (0 to 9 is fine).
Use the std::random_shuffle algorithm to shuffle the list.
Print the list. (try to do this one with an std iterator)
Use the std::sort algorithm to sort the list.
Print the list again. (you can use for each instead of an iterator)
See if you can locate the documentation for random_shuffle and sort either in VS help or with Google. Once you leave this class, you will need to be able to find information like this on your own.
Checklist
1. Did NOT create a folder for the solution
2. Project/solution named correctly
3. Correct comments at top
4. Consistent indentation
5. Good variable names
6. Overall neat organization
7. Comments in code explain what's being done
8. Correct division of code into .h and .cpp files
9. Use of #pragma once in .h files (or, #ifndef)
10. #include "stdafx.h" in cpp files (or, suppress pch)
|
|
|
|
|
|
What does this mean? If you expect me to do your work for you then you are going to be disappointed.
|
|
|
|
|
hi this code is a part of keecak function.
i do not undrastand what is "C[index(x-xOff)];" plz help me;
template<class Lane>
void KeccakF::inverseTheta(vector<Lane>& A) const
{
vector<Lane> C(5);
for(unsigned int x=0; x<5; x++) {
C[x] = A[index(x,0)];
for(unsigned int y=1; y<5; y++){
C[x] ^= A[index(x,y)];
}
}
const LaneValue inversePositions64[5] = {
0xDE26BC4D789AF134ULL,
0x09AF135E26BC4D78ULL,
0xEBC4D789AF135E26ULL,
0x7135E26BC4D789AFULL,
0xCD789AF135E26BC4ULL };
vector<LaneValue> inversePositions(5, 0);
for(unsigned int z=0; z<64; z+=laneSize)
for(unsigned int x=0; x<5; x++)
inversePositions[x] ^= inversePositions64[x] >> z;
for(unsigned int z=0; z<laneSize; z++) {
for(unsigned int xOff=0; xOff<5; xOff++)
for(int x=0; x<5; x++)
for(unsigned int y=0; y<5; y++)
if ((inversePositions[xOff] & 1) != 0)
A[index(x, y)] ^= C[index(x-xOff)];
for(unsigned int xOff=0; xOff<5; xOff++) {
ROL(C[xOff], 1);
inversePositions[xOff] >>= 1;
}
}
}
|
|
|
|
|
index() is a function that takes two values and returns another value. You need to find the documentation for it to know what all the values represent.
|
|
|
|
|
mostafaghanei wrote: this code is a part of keecak function
Ahh, Keecak eh? Yes, that's very well known. I am sure someone can tell you what it does.
"The whole idea that carbon dioxide is the main cause of the recent global warming is based on a guess that was proved false by empirical evidence during the 1990s." climate-models-go-cold
|
|
|
|
|
THE QUESTION IS AS FOLLOWS:
Create a template class called Array that implements an array and works with any type (int, double, etc.). The constructor should take a size for the array and use new to allocate memory (don't forget to delete in the destructor). Overload operator[] to access the elements of the array. If an attempt is made to access an element outside the array bounds (either above OR below), throw an exception. In the main program, first create an Array<int> object, add a few values, and demonstrate that operator[] throws an exception if an attempt is made to access an out-of-bounds elements. Catch the exception and print an appropriate message. Then do the same thing with an Array<std::string>.
Hint: you will need both of these overloads:
T& operator[](int i)
const T& operator[](int i) const
I DID THE PROGRAM IN MAIN AS FOLLOWS AND IT DOES WELL IN THE MAIN BUT ITS GIVING ME HARD TIME DIVIDING IT INTO DIFFERENT FILES.
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <exception>
#include "Array.h"
template <typename T>
class Array
{
int size; T*array;
public:
Array(int s)
{
size=s;
array=new T [size];
}
~Array()
{
delete [] array;
}
const T &operator[](int i) const
{
if(i < 0)
throw exception("Index out of bounds LOWER");
else if(i>=size)
throw exception("Index out of Bounds OVER");
else
return array[i];
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Array <int> num(12);
try
{
int i=num[-1];
}
catch (std :: exception & ex)
{
cout<<ex.what()<< endl;
}
Array <string> num1(12);
try
{
string j=num1[14];
}
catch (std :: exception & ex)
{
cout<<ex.what()<< endl;
}
cin.get();
cin.get();
return 0;
}
THEN I DIVIDED THE PROGRAM INTO DIFFERENT FILES AS FOLLOWS:
IN ARRAY.H
#pragma once
template <typename T>
class Array
{
public:
Array(int s);
~Array();
const T &operator[](int i)const;
private:
int size; T*array;
};
IN ARRAY.CPP
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <exception>
#include "Array.h"
template <typename T>
Array<T>::Array(int s)
{
size=s;
array=new T [size];
}
template <typename T>
Array<T>::~Array()
{
delete [] array;
}
template <typename T>
const T & Array<T>::operator[](int i) const
{
if(i < 0)
throw exception("Index out of bounds LOWER");
else if(i>=size)
throw exception("Index out of Bounds OVER");
else
return array[i];
}
IN MAIN
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <exception>
#include "Array.h"
int _tmain(int argc, _TCHAR* argv[])
{
Array <int> num(12);
try
{
int i=num[-1];
}
catch (std :: exception & ex)
{
cout<<ex.what()<< endl;
}
Array <string> num1(12);
try
{
string j=num1[14];
}
catch (std :: exception & ex)
{
cout<<ex.what()<< endl;
}
cin.get();
cin.get();
return 0;
}
PLEASE REPLY SOON.
|
|
|
|
|
|
You do not need ARRAY.CPP, all that code should be in the header file, following the class definition.
|
|
|
|
|
@Richardd MacCutchann
But the checklist is as follows:
hecklist
1. Did NOT create a folder for the solution
2. Project/solution named correctly
3. Correct comments at top
4. Consistent indentation
5. Good variable names
6. Overall neat organization
7. Comments in code explain what's being done
8. Correct division of code into .h and .cpp files
9. Use of #pragma once in .h files (or, #ifndef)
10. #include "stdafx.h" in cpp files (or, suppress pch)
11. Test for below as well as above out-of-range
|
|
|
|
|
Then you need to follow the instructions and do your own work.
|
|
|
|
|
@Richard-MacCutchann
I actually did and have posted the main program and my attempt to divide it into .cpp and .h files i am almost there and i just need help to figure out the minor mistakes i have made . if you look at my main post you will see all the program please have a look and let me know if you can help me or not thanks.
|
|
|
|
|
I already gave you a suggestion. If you want more help then you need to provide a more detailed explanation of your problem.
|
|
|
|
|
if you look at the main question i have my main program that runs and gives me desired output but when i try to make a seperate .cpp and .h files for the program (that i also have attached in the main question) gives me some error so i want to request you to have a look at that and let me know what i should do to make the program work with a seperate .cpp and .h file for the main program that i have attached in the question
|
|
|
|
|
I have looked, and I have given you a suggestion; it is up to you to implement it. You then need to build and test until it runs successfully.
You also need to provide specific details of the errors you receive if you want further help.
|
|
|
|
|
THE QUESTION IS AS FOLLOWS:
Create a template class called Array that implements an array and works with any type (int, double, etc.). The constructor should take a size for the array and use new to allocate memory (don't forget to delete in the destructor). Overload operator[] to access the elements of the array. If an attempt is made to access an element outside the array bounds (either above OR below), throw an exception. In the main program, first create an Array<int> object, add a few values, and demonstrate that operator[] throws an exception if an attempt is made to access an out-of-bounds elements. Catch the exception and print an appropriate message. Then do the same thing with an Array<std::string>.
Hint: you will need both of these overloads:
T& operator[](int i)
const T& operator[](int i) const
I DID THE PROGRAM IN MAIN AS FOLLOWS AND IT DOES WELL IN THE MAIN BUT ITS GIVING ME HARD TIME DIVIDING IT INTO DIFFERENT FILES.
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <exception>
#include "Array.h"
template <typename T>
class Array
{
int size; T*array;
public:
Array(int s)
{
size=s;
array=new T [size];
}
~Array()
{
delete [] array;
}
const T &operator[](int i) const
{
if(i < 0)
throw exception("Index out of bounds LOWER");
else if(i>=size)
throw exception("Index out of Bounds OVER");
else
return array[i];
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Array <int> num(12);
try
{
int i=num[-1];
}
catch (std :: exception & ex)
{
cout<<ex.what()<< endl;
}
Array <string> num1(12);
try
{
string j=num1[14];
}
catch (std :: exception & ex)
{
cout<<ex.what()<< endl;
}
cin.get();
cin.get();
return 0;
}
THEN I DIVIDED THE PROGRAM INTO DIFFERENT FILES AS FOLLOWS:
IN ARRAY.H
#pragma once
template <typename T>
class Array
{
public:
Array(int s);
~Array();
const T &operator[](int i)const;
private:
int size; T*array;
};
IN ARRAY.CPP
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <exception>
#include "Array.h"
template <typename T>
Array<T>::Array(int s)
{
size=s;
array=new T [size];
}
template <typename T>
Array<T>::~Array()
{
delete [] array;
}
template <typename T>
const T & Array<T>::operator[](int i) const
{
if(i < 0)
throw exception("Index out of bounds LOWER");
else if(i>=size)
throw exception("Index out of Bounds OVER");
else
return array[i];
}
IN MAIN:::
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <exception>
#include "Array.h"
int _tmain(int argc, _TCHAR* argv[])
{
Array <int> num(12);
try
{
int i=num[-1];
}
catch (std :: exception & ex)
{
cout<<ex.what()<< endl;
}
Array <string> num1(12);
try
{
string j=num1[14];
}
catch (std :: exception & ex)
{
cout<<ex.what()<< endl;
}
cin.get();
cin.get();
return 0;
}
|
|
|
|