473,779 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

10 New Member
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<iostre am.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+(Megai nt 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::Megain t()
{
int i;
for(i=0;i<N;i++ )
{
a[i]=0;
R[i]=0;
}
}

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

}
}



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

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

Megaint Megaint::operat or +(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+sec ond;
third.ShowMegai nt();

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 2165
manjuks
72 New Member
Hi,

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

Thanks,
Manjunath
Sep 8 '09 #2
susheela s
10 New Member
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
2683
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 there any way. Regards, Govind.
1
1742
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 Xearth is its private data. How to write the corresponding code in c++ ? Thanks,
3
1200
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
3661
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 written in file are not the sent bytes. Copy and paste the following lines to observe my problem. What can I do to resolve problem ? Only System.Text.Encoding.ASCII write the same number of bytes, but not the good bytes. Someone can help me. Thanks by...
4
6306
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
5357
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 it a fair statement that char *ptr will take 4 more bytes (on 32bit platform) in DATA segment? I have found
2
1990
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 the class Matrix I have a function toMatrix that allows me to copy a standard array to a Matrix object. I have written a driver program to test out the class. When compiling with gcc 4.1.2 I get the following error ' error: ‘toMatrix’ was not...
2
3767
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 when i do the following. if you add a contact with up to 13 fields it will be stored in a data structure. i have a tabbed pane that will show six of the 13 fields for that contact. when you double click the contact i want it to pop up and show all 13...
3
3021
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 array.This i could do ..wat my doubt s suppose if i take 4 elements in array and first byte of first array is less than first byte of second array den im gonna take borrow from second byte of first array,if that second byte of first array is 0 den how can...
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10306
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10074
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9930
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.