473,395 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

hello everyone...addition of bytes which s declared as array in private of class

i wrote a program to add bytes in array in such a way that when i add zeroth byte of two array sum should retained and carry must be added to next addition of bytes(ie array index 1 bytes)
this is program which i wrote using class
#include<iostream.h>
#define N 2

typedef unsigned char byte;

class Megaint
{
private:

byte a[N];
unsigned int R[N];
public:
Megaint();
Megaint(byte m[]);
Megaint operator+(Megaint M);
void ShowMegaint();
};

int add(byte n1,byte n2,byte *c)
{
unsigned int r,r1;
r=n1+n2+(*c);
r1=r;
r=r&0x0ff;
*c=r1>>8;
return r;
}

int add1(byte n1,byte n2,byte *c)
{
unsigned int r;
r=n1+n2+(*c);
return r;
}



Megaint::Megaint()
{
int i;
for(i=0;i<N;i++)
{
a[i]=0;
R[i]=0;
}
}

Megaint::Megaint(byte m[])
{
int i;
for(i=0;i<N;i++)
{
a[i]=m[i];

}
}



void Megaint::ShowMegaint()
{
int i;
cout<<"the sum is"<<endl;
for(i=0;i<N;i++)
{

cout<<R[i]<<endl;
}
}

Megaint Megaint::operator +(Megaint M)
{
Megaint res;
byte carry=0;
int i;
for(i=0;i<(N-1);i++)
{
res.R[i]=add(a[i],M.a[i],&carry);

}
res.R[N-1]=add1(a[N-1],M.a[N-1],&carry);
return res;
}


int main()
{
int i;
byte A[N]/*={183,128}*/,B[N]/*={183,128}*/;

cout<<"enter 1st array elements"<<endl;
for(i=0;i<N;i++)
{
cin>>A[i];........here its not taking values,it is taking only one value;
}

cout<<"enter 2nd elements"<<endl;
for(i=0;i<N;i++)
{
cin>>B[i];
}

Megaint first(A),second(B),third;

third=first+second;
third.ShowMegaint();

return 0;
}

here the problem is in main if i initialize elements into array and execute the program is working..But if try to put value in array using cin statement i could only enter one elements...You just execute this you will know what is problem...
Please help me

thanking you
sushi
Sep 8 '09 #1
2 2141
manjuks
72
Hi,

I tried the program which you write, cin is working fine.
Just check it once again.

Thanks,
Manjunath
Sep 8 '09 #2
thank u manjunath ...i got d answer
Sep 9 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Govind | last post by:
Hi All, I want to Convert 32 bit integers to byte in right alighed format . For 32 = the usual way is BitConverter.GetBytes(int32)==> xx xx 00 00 , but i want right aligned like 00 00 xx xx.Is...
1
by: Titan | last post by:
Hi all, In Delphi the following code will work: (xxas TLibr).XEarth=xx.xm*(-1.0); where xx is defined as a array of class TBody, and it has n members; Tlibr is the derived class of Tbody, and...
3
by: Ajai kumar menon | last post by:
Hi, How is this possible? i am surprised at how the private array value changed!! class BaseControl { private int elements; public int GetArrayElements(){ return elements;
5
by: philip | last post by:
Here is some lines of code than I wrote. You can copy/paste theis code as code of form1 in a new project. My problem is this one : I try to write in a file a serie of bytes. BUT some bytes...
4
by: newbie120 | last post by:
Hi all maybe its just been a long day, but i have a question about call access modifiers in C#. Consider the following code. namespace Application { private class Class1 { int i;
10
by: fei.liu | last post by:
Consider the following sample code char * ptr = "hello"; char carray = "hello"; int main(void){ } What does the standard have to say about the storage requirement about ptr and carray? Is...
2
by: jr.freester | last post by:
I have a written a simple class called Matrix. It allows me to operate on a 2D array if it were a matrix. I have not really written a class in c++ since the single course I took in college. In...
2
by: yeshello54 | last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error...
3
by: susheela s | last post by:
Hi. Hers im subtracting two 16bit numbers by using two 8bit num array.In case if first byte of array is less than first byte of second array den i hav to take borrow form second byte of first...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.