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

A n00b.

Hello.
I'm a noob. As such, I will now ask the obligatory stupid questions.
Can anyone tell me how to do this???

I need to write a program that acts as a database for a CD collection,
It has to use a class to store the CD info, has to have a file saving
implemented, and must use dynamic data.

Thank you for any help.

Oct 30 '06 #1
14 1424
Tu********@gmail.com wrote:
Hello.
I'm a noob. As such, I will now ask the obligatory stupid questions.
Can anyone tell me how to do this???
We can always help you ask obligatory stupid questions. You can even
get a sample of those off 'groups.google.com'.
I need to write a program that acts as a database for a CD collection,
It has to use a class to store the CD info, has to have a file saving
implemented, and must use dynamic data.
No, sorry, C++ has no means to do this. Database connectivity is OS-
and database-specific, and has to be asked about in the newsgroup that
deals with the OS or/and with the database of choice.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 30 '06 #2
Okay... Not a database then. The program has to let you enter three
bits of data (artist name, Cdname, year of release for as many CD's as
the user wants, and allow for the saving and retreval of that data to
and from a file.

Oct 30 '06 #3
Artist wrote:
Okay... Not a database then. The program has to let you enter three
bits of data (artist name, Cdname, year of release for as many CD's as
the user wants, and allow for the saving and retreval of that data to
and from a file.
Ah, that... I think it's covered by the FAQ 5.2. Check it out.
Oct 30 '06 #4
I'm not asking for anyone to do this for me, just a pointer towards
generally the right direction.

Oct 30 '06 #5
Artist wrote:
I'm not asking for anyone to do this for me, just a pointer towards
generally the right direction.
You go first. Write a little code, and we will review it.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Oct 30 '06 #6

Artist wrote:
I'm not asking for anyone to do this for me, just a pointer towards
generally the right direction.
The FAQ is a great place to start.

Oct 30 '06 #7
"Artist" <Tu********@gmail.comwrote:
Okay... Not a database then. The program has to let you enter three
bits of data (artist name, Cdname, year of release for as many CD's as
the user wants, and allow for the saving and retreval of that data to
and from a file.
Well first, I think you need to read up on how to accept user data. Have
you ever done that? Like taking the user's name and printing it back out?

--
To send me email, put "sheltie" in the subject.
Oct 30 '06 #8
"Artist" <Tu********@gmail.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
I'm not asking for anyone to do this for me, just a pointer towards
generally the right direction.
std::cin for input.
store the data in a vector or a map
std::cout for output
If you need to store the data, look at fstreams

Put some code together the best you can and post what you got if you still
have problems.
Oct 30 '06 #9
OKay, this is my baseline code, what I have so far

// classes test
#include <iostream>
using namespace std;

class riaaconner {
char conname[30],cartist[30];
int doc;
Public:
void set_values (conname,cartist,doc);
};

void riaaconner::set_values (char cnget[30], char caget[30], int dget)
{

conname = cnget;
cartist = caget;
doc = dget;
}

int main () {
char cngsend[30]
char cagsend[30]
int dgsend
riaaconner getdat;
cout << "CD Storage Prog BETA" <<endl;
endl;
cout << "This Prog enters data for you CD colection. The syntax is"
<<endl;
cout << "as follows: CD Name, Artist, Year Realeased." <<endl;
endl;
cout << "Please enter the data." <<endl;
endl;
cout << "Enter the CD Name." <<endl;
cin >cngsend;
cout << "Enter the Artist Name." <<endl;
cin >cagsend;
cout << "Enter the Release Year." <<endl;
cin >dgsend;
getdat.set_values (cngsend,cagsend,dgsend)
cout << "Results:"<<endl;
cout << "CD Name is: " << getdat.cnget();
endl;
cout << "Artist Name is: " << getdat.caget();
endl;
cout << "Release Year is: " << getdat.dget();
return 0;
}

Oct 30 '06 #10
Artist wrote:
<snip>

See my comments below.
class riaaconner {
Nice naming. ;)
Public:
Should be lowercase.

public:
conname = cnget;
cartist = caget;
This doesn't work. You can't assign an array. I will suggest a better
solution below.
char cngsend[30]
char cagsend[30]
int dgsend
You forgot your semi-colons here.
endl;
This statement doesn't do anything. If you want to print a newline you
have to pass it to cout:

cout << endl;

Or just use << endl << endl at the end of each output line.

<snip>

There are several other problems with your code. First of all, you
shouldn't use character arrays to store strings. There are many good
reasons. Among them:

a) You have no control over the user input. If someone enters more than
30 characters your program will probably crash.
b) You have to manually keep track of and copy the characters.
c) It doesn't do what you expect when you compare or assign.

Instead, you should use the 'string' class. It works exactly as
expected, like all the other built-in types and accepts an arbitrary
number of input characters. Here's an example:

#include <string>
using namespace std;
// ...
string mystring;
mystring = "hello!";
cout << mystring;

Second of all, your class is fairly useless. It just serves as a big
bag to put stuff in instead of representing a true logical object.
There are a few things you can do to make it better. First, let your
class read itself instead of doing it outside:

public:
void Read()
{
cin >name;
cin >artist;
}

You would use this class like so:

MyClass obj;
obj.Read();

For writing you do the same thing. Have a member function that does it:

public:
void Write()
{
cout << name;
cout << artist;
}

Once you get it to work with 'cin' and 'cout' you can make it work with
any stream. You just have to pass your streams as parameters, like so:

void Read(istream& input);
void Write(ostream& output);

Now, to call the Read and Write functions you have to pass it an open
stream (possibly a file), like so:

obj.Read(inputfile);
obj.Write(outputfile);

Try all the things I mention and then post your code again.

Regards,
Bart.

Oct 30 '06 #11
Bart wrote:
void Write(ostream& output);
Of course, this should be:

void Write(ostream& output) const;

Regards,
Bart.

Oct 30 '06 #12
"Artist" wrote:
Okay... Not a database then. The program has to let you enter three
bits of data (artist name, Cdname, year of release for as many CD's as
the user wants, and allow for the saving and retreval of that data to
and from a file.
See if this gives you something to think about. Not tested.

class CD
{
public:
CD(string artist_arg, string name_arg; int year);
private:
string artist;
string name;
int year;
}
----
class Data_base
{
public:
Data_base(char* file_name, bool new); // restore the data from the
file if new is false
~ Data_base() // save the data base to a file
private:
vector<CDdb;
};
----
int main()
{
// see if this is an initial creation of the data base
Data_base db( stuff);
// stuff
return 0;
}
---
Add stuff as necessary.

Try to find out why the instructor wants you to use dynamic storage. He may
want you to use a "roll your own" linked list instead of a vector.

Oct 30 '06 #13
osmium wrote:
Data_base(char* file_name, bool new); // restore the data from the
You can't name a formal parameter 'new'.

Regards,
Bart.

Oct 30 '06 #14
Tu********@gmail.com wrote:
Hello.
I'm a noob. As such, I will now ask the obligatory stupid questions.
Can anyone tell me how to do this???

I need to write a program that acts as a database for a CD collection,
It has to use a class to store the CD info, has to have a file saving
implemented, and must use dynamic data.

Thank you for any help.

Assuming that this is some sort of homework, and that you aren't really
interested in using a relational database, with all its associated
baggage, then likely what you'd want is text-based flatfile database.
Those are easy to work with and work well enough for a small project.

The exact form of the flatfile will be up to you. Tab-separated fields
with a new-line record separator are pretty easy to use, especially if
you restrict the data so that those characters can't appear (you'll
need to check). Something like:
CD Title\tArtist\tRelease Date\nDetails\n
Here the \t and \n represent actual tab and new-line character that
would appear in the file, you use the escape sequences to create them.


Brian

Oct 30 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matt | last post by:
I'd like to overwrite just one line of a binary file, based on a position set by seek(). Is there no way to do this? As far as I can tell I need to read the whole file, change the line, and write...
3
by: Anupam Kapoor | last post by:
hi all, a python n00b, so please bear with me. i have a simple question: i generally name python sources as a-simple-python-example.py. when i try to import a module named as above, i...
1
by: newgenre | last post by:
I am using a pre-built package of code for my site, which is called EasyDisc. All it does is it creates an interactive forum on your site, like any forum you see anywhere. I am having a problem...
2
by: ducky | last post by:
Hi all, The only programming experience i have under my belt so far is VB. I'm just starting out on C++ and wonder if anybody suggests and good (free) starting points for me to get going. I'm...
4
by: onefry | last post by:
Hey I have this prog that i'm working on, starting my first c++ class and kind of a n00b to programming here it is #include <iostream> #include <cstdlib> using namespace std;
6
by: Charles | last post by:
I am learning from the Accelerated C++ book. The following example doesn't work and I don't know why: #include <iostream> #include <string> int main () { const std::string exclam = "!"; const...
8
by: HardHackz | last post by:
Hey, I'm trying to learn C++, the problem is, when I do cout << "Hello World!"; it always opens dos and closes it to quickly to see...i know im a total n00b, but any help?
0
by: hockeyjk | last post by:
All, I'm writing a program that creates a histogram of data. IDLE is freezing up after the window opens (doesn't prompt user or graph anything). The window that opens is named "tk" rather than...
2
by: benwah1983 | last post by:
Greetings, Here is my problem: The following code shows a div with two small nested divs (images with a title), then the div is closed. Another one opens and a "random text" is displayed. <div...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...

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.