Jump to content


Check out our Community Blogs

mnirahd

Member Since 29 Oct 2010
Offline Last Active Jun 08 2012 03:17 AM
-----

#586311 Array of pointers to int arrays

Posted by mnirahd on 05 January 2011 - 02:54 AM

Hi,


int array[100];
int **pointerToArray = & array;

I hope this helps!

Munir
  • -1


#585972 The good ol' "unresolved external symbol" ... (Windows)

Posted by mnirahd on 03 January 2011 - 06:15 AM

Hi,

you're getting linking errors: which suggest that compiler is not being able to find references to certain symbols(functions).

After you looking on the linking errors: I see that you need to link your code with ws2_32.lib.

Trying linking it with ws2_32.lib library, and let us know if that resolves the issues.

Munir
  • 1


#583401 SMTP Session Access

Posted by mnirahd on 09 December 2010 - 03:05 AM

Hi,

You can open connection with your SMTP server, and can send different commands. The purpose of these commands is to set values for

Mail From, Reciepents and Mail contents.

For example, if you want to set a recipient email address, then

1. Open connection with Server
2. Send following string to server, if you want to set xyz@codecall.net as recipient email

RCPT:<xyz@codecall.net>\r\n


I hope this helps!

Munir
  • -1


#582311 URL Decoder

Posted by mnirahd on 30 November 2010 - 04:31 PM

Hi,

I've tried your code with VS 2008, and it worked perfect with the string you mentioned.

what compiler you are using - let me know so that I could try it.

Munir
  • -1


#581915 C program to detect prime numbers

Posted by mnirahd on 27 November 2010 - 11:03 AM

Hi,

The program is running in a loop where it determines whether given number is a prime or not.
The logic is that it loop goes on until one of the following happens. i++ provides a next number each turn the loop runs

1. number is dividable by i
2. i reaches equal to number.

if you remove i++: the loop would go on forever:

Munir
  • -1


#580653 need help in understanding the given code in library management system

Posted by mnirahd on 16 November 2010 - 07:27 AM

Hi,

the purpose of the kbhit() function is to check if keyboard buffer is empty or have some character to read.

it returns

a) 0 if there are no number of bytes to read from keyboard buffer.
B) non-zero value if there is some data in keyboard buffer.

Now coming back to the code

 while (!kbhit());

This shows that this loops would keep on executing until user presses a key. Probably, programmer wanted to halt the program until user are enable to give some input.

I hope this helps
  • -1


#580582 Overload operator= for array class

Posted by mnirahd on 15 November 2010 - 12:11 PM

Hi,

I think you need to change your [] operator a bit.

In order to make assignment operator work correctly for an individual element of your array class, You need to change the prototype.

Currently, you are doing like as follow

[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
        }

A correct version should be as follow

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
        }


The reason for the is error when you try something array[i] = 5; requires a reference to the element in the array.

since in your [] operator you're returning a value - not a reference: you get the compilation error.

you can try the following code - I've tested it. and I believe that it must work



// 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;
}



Lets try that, and let me know how does it goes.

I hope this helps!

Munir
  • 1


#578596 Possible logic error?

Posted by mnirahd on 30 October 2010 - 07:39 AM

Hi,

to make the precision work correctly, you must first choose the fixed-point format. Like this:


#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. 

So your program should look like as following


//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;
}

I hope this should fix the problem. If you see some problem: send me the inputs you send to the program, and expected output.

Thanks
Munir
  • -1


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download