473,322 Members | 1,718 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,322 software developers and data experts.

Program to add two numbers by using classes

Expand|Select|Wrap|Line Numbers
  1. class class1
  2. {
  3. public : void sum1(int,int);
  4. };
  5.  
  6. void class1::sum1(c,d)
  7. {
  8. int c,d;
  9. int sum;
  10. sum=c+d;
  11. cout<<"sum="<sum;
  12. }
  13. void main()
  14. {
  15. int a=1,b=2;
  16. class1 p;
  17. p.sum1(a,b);
  18. getch();
  19. }
Check errors in it and reply
Nov 16 '07 #1
3 17183
sicarie
4,677 Expert Mod 4TB
There are a few errors in it that I can see, but I'm not here to do your work for you. I'm here to help you understand it, so you can do it yourself.

With that in mind, what did you get? What do you think are the errors in there? (Hint: running this through a compiler will probably help show errors...)
Nov 16 '07 #2
u can do this by declaring datamembers in class only and then used these data members in the member funtion to get the desired result.
there few other errors in code,see by your ownself.
Nov 17 '07 #3
Dear,
You must type blew code instead of your code:
Expand|Select|Wrap|Line Numbers
  1.       class class1
  2.       {
  3.       public : void sum1(int,int);
  4.       };
  5.  
  6.       void class1::sum1(int C,int D)  //Note here
  7.       {
  8.       int sum;
  9.       sum=C+D;
  10.       cout<<"sum="<sum;
  11.       }
  12.       void main()
  13.       {
  14.       int a=1,b=2;
  15.       class1 p;
  16.       p.sum1(a,b);
  17.       getch();
  18.       }
Nov 17 '07 #4

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

Similar topics

6
by: Nirjhar Oberoi | last post by:
Hi, Can you add two numbers using a Single Variable? :-) If yes then show me the code!!! Regards Nirjhar
4
by: GeekBoy | last post by:
I am reading a file of numbers using for loops. The numbers are in a grid as follows: 8 36 14 11 31 17 22 23 17 8 9 33 23 32 18 39 23 25 9 38 14 38 4 22 18 11 31 19 16 17 9 32 25 8 1 23
3
by: apedosmil8 | last post by:
I am having problems with using classes. I'm not sure why this program will not run. I have pointed out the problem. Thanks #include <iostream> #include <iomanip> #include <cmath> using...
6
by: penny | last post by:
In this assignment we shall look at a possible representation of rational numbers in java using objects. The java language represents rational numbers using the same representation used for other...
3
by: jishara | last post by:
How to write a program in a one page to find the sum of two numbers using php $_POST method.
2
by: =?Utf-8?B?d2lubGlu?= | last post by:
Hello 1) I agree that useing classes is the best way to use VB.net. The question is how do you write a VB program without using classes? 2) For my own edification where can I see an actual...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.