473,216 Members | 1,938 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,216 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. };
  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 17179
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
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.       };
  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

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
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
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...
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...
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.
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...
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.