473,405 Members | 2,445 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,405 software developers and data experts.

Class Basics

1
Hi, I am a first semester student, learning the OOPs basics. I need help for a program:

Expand|Select|Wrap|Line Numbers
  1. class Message{
  2. public:
  3.     void input();
  4.     int output();
  5. private:
  6.     long token_number;// next token to be given to client
  7.  
  8. };
  9.  
  10. void Message::input()
  11. {
  12.     token_number = 1;
  13. }
  14.  
  15. int Message::output()
  16. {
  17.     return token_number;
  18. }
  19.  
I dont know the right way to call these elements in the main()
Expand|Select|Wrap|Line Numbers
  1. int main(){
  2. Message obj;
  3.  
  4. std::cout<< out_buffer<<obj.output()<<std::endl;//write the token number in the buffer
  5. std::cout<<"Response received"<<++obj.input();//To update the input value and display
  6. }
  7.  
Apr 5 '22 #1
1 9643
dev7060
636 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. int main(){
  2. Message obj;
  3.  
  4. std::cout<< out_buffer<<obj.output()<<std::endl;//write the token number in the buffer
  5. std::cout<<"Response received"<<++obj.input();//To update the input value and display
  6. }
What are you trying to do?

You might be looking for
Expand|Select|Wrap|Line Numbers
  1. int main() {
  2.   Message obj;
  3.   obj.input();
  4.   std::cout << obj.output();
  5.   return 0;
  6. }
  • A member function can be used to update the private data members.
  • A constructor is used to initialize the object.
Apr 9 '22 #2

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

Similar topics

1
by: Steven Lien | last post by:
I wrote a simple vector class that can store Cards, and my question is if i had Card class, should i "new" it to store into vector , or simply use copy structure?. if i need the vector class to be...
2
by: Kurien Baker Fenn | last post by:
I would like to show the progress of an application using the progress bar in visual basics using the timer.Please help me. Thanks in advance.
2
by: D | last post by:
Hello I'm learning C++ and having done some Asm and C. I would like input on the following. If I understand what I'm reading then Objects of a type of class gets a copy of it's class' (including...
6
by: windandwaves | last post by:
Hi Folk I was wondering to hear from you why you use classes in some instances rather than functions. I have never used a class, but I use a lot of functions. I don't have a comp sci...
5
by: Stephen Russell | last post by:
In the past public void has worked. But I need to return an XMLDocument, and this class needs a string param for the SP to call. public void makeXML (string lcStatement) wont allow me to return...
5
by: Simon Harris | last post by:
Hi All, Being a classic ASP programmer, I'm trying to get to grips with OOP, specifically using classes. I have setup my class with various properties, so far so good. What I dont quite get...
10
by: Chet Cromer | last post by:
I am creating a set of base classes and sub classes to use throughout a program I'm developing. The base class represents a generic "lookup table" from my database that contains lists of things...
4
by: Brian | last post by:
Hello.. After many books and self study, I think I am finally starting to grasp the basics of classes. However, I can't quite grasp how to use them after I design them. For example, I want to...
3
by: Peskov Dmitry | last post by:
Hi, What is the memory layout of an object, and the derived object. For example : class A { private: int prv_data; protected: int pro_data;
0
by: babu8880 | last post by:
www.convensysglobal.com/elearn You can login and attend courses and similar resources ask your doubts from experienced engineers in iphone and Objective C Domain You can attend live classes...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.