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

Creating class, print function, unique ID for each class object.

1
hi there,

here I have a qustion, which says;
(((Write a course class which contains number of credits and a string id. In addition to the constructor, it should contain a print function)))

so,
I need a function that convert integer to string
coze I did answer but not copleted yet

for example:
((. For each course, the id and number of credits is stored. The id of the course is a single string composed of two parts: a two character code specifying the major (e.g. CS for Computer Science, MA for Mathematics, EC for economics.. etc) and a serial number, which, unlike the code, is generated by the system.))


my answer is:
Expand|Select|Wrap|Line Numbers
  1. claas course
  2. {     
  3.       static int serialID;
  4.       int no_credits;
  5.       string ID;
  6.  
  7.       public:
  8.       course(string s, int no)
  9.       {
  10.            no_credits = no;
  11.            ID = s + serialID (( Here's the problem))
  12.            serialID++;
  13.       }
  14.  
and the print fun which print the course name and number togethere..



please I need it in a hurry

thanx
Nov 14 '07 #1
1 2600
sicarie
4,677 Expert Mod 4TB
Okay, first off, you have a typo - it's 'class' and not 'claas'. That will keep it from compiling for a while (the little ones like that are the most annoying to try to troubleshoot, because your eye will see that you meant class and skip over it).

So the second issue is your serial ID. This can be handled in two ways. One, you can do it in the main, and pass it to the constructor, or initialize it later; or you can create a singleton list of serials (add one to the list each time a constructor is called). As you're just starting out, storing it in main is probably the easiest.

Third is your print function. I don't know where you're stuck on this, it doesn't look like you've tried it yet. So give it a shot, I have faith in you ;)
Nov 14 '07 #2

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

Similar topics

2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
1
by: Dixie | last post by:
I wish to add some fields to an existing table in code. I am using the following code from rkc. CurrentDb.Execute ("ALTER TABLE MyTable ADD MyNewField Text 25") This works , but I need to also set...
7
by: Robin | last post by:
In a current .Net solution (using VB.Net) has a 3 tier architecture of Web interface, Data Access Layer and Database. How do I implement business logic and class layers into this solution?
10
by: connyledin | last post by:
Im trying to create a version of the game Wumpus. Mine is called Belzebub. But im STUCK! And its due tuesday 2 maj. Im panicing! Can some one help me?? here is the file:...
17
by: Lee Harr | last post by:
I understand how to create a property like this: class RC(object): def _set_pwm(self, v): self._pwm01 = v % 256 def _get_pwm(self): return self._pwm01 pwm01 = property(_get_pwm, _set_pwm)
1
by: kaens | last post by:
So, I have a class that has to retrieve some data from either xml or an sql database. This isn't a problem, but I was thinking "hey, it would be cool if I could just not define the functions for...
0
by: DarrenWeber | last post by:
# Copyright (C) 2007 Darren Lee Weber # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free...
1
by: joe_doufu | last post by:
I'm creating a page with multiple "widgets", each with its own XMLHttpRequest object, so the user can play with the widgets in parallel. The widgets are enclosed in divs with class "widget" and a...
5
by: alan | last post by:
Hello world, I'm wondering if it's possible to implement some sort of class/object that can perform mapping from class types to strings? I will know the class type at compile time, like so:...
1
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: 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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.