int array[100]; int **pointerToArray = & array;
I hope this helps!
Munir
Posted by mnirahd on 05 January 2011 - 02:54 AM
int array[100]; int **pointerToArray = & array;
Posted by mnirahd on 03 January 2011 - 06:15 AM
Posted by mnirahd on 09 December 2010 - 03:05 AM
RCPT:<xyz@codecall.net>\r\n
Posted by mnirahd on 30 November 2010 - 04:31 PM
Posted by mnirahd on 27 November 2010 - 11:03 AM
Posted by mnirahd on 16 November 2010 - 07:27 AM
while (!kbhit());
Posted by mnirahd on 15 November 2010 - 12:11 PM
[COLOR="Red"]//This is wrong: I believe this should be as Type &[/COLOR] Type operator[] (int index) const { if (abs(index) > m_size) throw "Index Out Of Range"; if (index > 0) return array[index]; else return array[m_size - index]; } Type operator= (const Type& value) { // code }
Type [COLOR="Red"]&[/COLOR]operator[] (int index) const { if (abs(index) > m_size) throw "Index Out Of Range"; if (index > 0) return array[index]; else return array[m_size - index]; } [COLOR="Red"]//You may not need this operator if you define [] as I defined. [/COLOR] Type operator= (const Type& value) { // code }
// codeCall.cpp : Defines the entry point for the console application. // #include <iostream> using namespace std; typedef unsigned int uint; template <class Type> class Array { public: Array(uint size = 0) : m_size(size) { if (m_size > 0) { array = new Type[m_size]; for (uint i = 0; i < m_size; ++i) array[i] = 0; } } virtual ~Array() { delete [] array; } const uint size() const { return m_size; } Type &operator[] (int index) const { if (abs(index) > m_size) throw "Index Out Of Range"; if (index > 0) return array[index]; else return array[m_size - index]; } Type operator= (const Type& value) { // code } private: Type* array; uint m_size; uint abs(uint param) const { return (param > 0) ? param : -param; } }; int main(int argc, _TCHAR* argv[]) { Array<int> o(5); o[2] = 5; cout<<o[2]<<endl; return 0; }
Posted by mnirahd on 30 October 2010 - 07:39 AM
#include <iostream> #include <iomanip> using namespace std; int main() { double x = 2.0/3.0; cout << setiosflags(ios::fixed) << setprecision(4) << x; return 0; } The result (.6667) is an appropriate four-digit representation of the repeating decimal fraction 2/3.
//program calculates the price of one stock #include <iostream> #include <iomanip> using namespace std; //function call double price_per(int whole, int numer, int denom, int total_shares); //main program int main() { char loop; do { //gathers input int number_of_shares, whole_value, numerator, denominator; double price_per_share; cout << "Enter the number of shares you own: "; cin >> number_of_shares; cout << "Enter the value of your shares, first the whole value: "; cin >> whole_value; cout << "Now enter the numerator: "; cin >> numerator; cout << "Now the denominator: "; cin >> denominator; //call price_per_share = price_per(whole_value, numerator, denominator, number_of_shares); //sets precision //displays output cout << "The value of one share is: "; [B] [COLOR="Red"] cout << setiosflags(ios::fixed) << setprecision(2) << price_per_share << endl; //this is the changed part[/COLOR] [/B] cout << "Enter Y to continue or N to exit: "; cin >> loop; }while (loop == 'Y' || loop == 'y'); cout << "~~~~~~~~~~~~~~~~~~~Goodbye~~~~~~~~~~~~~~~~~~~" << endl; } //function definition double price_per(int whole, int numer, int denom, int total_shares) { double whole_denom_numer, last; whole_denom_numer = (((whole*denom)+numer)/denom); last = whole_denom_numer/total_shares; return last; }