Jump to content

!please read my post!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
16 replies to this topic

#1
programming Child

programming Child

    Newbie

  • Members
  • Pip
  • 5 posts
Hi there guys,

i know all of you are busy and have better questions to answer but i really need help i am a 15 year old beginner to c++ programming i can do the basic stuff like adding numbers and writing stringsplus pointers.

But i want to create a data base using my own hard drive that i can access and add or write memory to like writing a file with numbers and people info in it

The reason being is that my dad is a great guy but i want to show him i can create something that i did by my self plus along this lesson i would like to gain knoledge so please guys walk me through this please

Thanks

AJ

#2
Phoenixz

Phoenixz

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 256 posts
I guess, mySQL will be a thing you need to research, as far as I know I/O for C++ only handles .txt and batch files
Posted Image

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Are you talking about a simple application that saves data to a file, or creating a generic SQL database? They are two radically different things, and require very different levels of understanding.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#4
Lance

Lance

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
Yeah, there are a lot of decisions you need to make, even at the beginning stage. Such as:
1. Are you going to implement the data storage and retrieval functionality by your self?
1.1. If yes, I suggest you just store records with no metadata, eg. let's say you have a Person table, with each record stores

struct Person{

         int id;

         char fname[20];

         char lname[20];

         char telephone[12];

         char dob[8];

         char addr1[50];

         char addr2[50];

         char addr3[50];

         char postcode[7];

         //...

};

Then you have a corresponding Person.dat file storing n Person record, while the information of each field definition will not be stored in the file. This is just to minimize your coding job. You'll need to lean how to how to read and write file in binary mode, etc.

1.2 if no, you can rely on third party libary. SQLite, Microsoft Access mdb file would be some sensible options. You'll need know a liitle bit SQL to use them though. However, this skill, understanding SQL, will be a great asset in your future. If you really intend to learn for this project, instead of get something done quick and dirty, I'd suggest you go this direction. You can move on to some more powerful RDBMSs like MySQL, PostgreSQL, Oracle, SQL Server, etc in the future, the SQL is essentially the same.

#5
programming Child

programming Child

    Newbie

  • Members
  • Pip
  • 5 posts
Hi there again,

Basically all i want to do is, lets say i have 10 employees and i need there work position there department there address there phone number and postal code.

All i want to do is get that information and store it somewhere but then i can recall it buy typing in there name. And there you have it all the info you need about that person.

Thanks Again Guys!

AJ

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I would create a class to store the information. Instantiate an array/linked list of the class, and read the data in from a binary file. When you finish the program, write the data back out to file.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
programming Child

programming Child

    Newbie

  • Members
  • Pip
  • 5 posts
K i understand that kinda but i need a little more guidance like i have done projects with classes and arrays but i need help on how i link them how i get them to work together! I am an absolute beginner to this and i need a lot of help.

This is what i am trying now but i can't seem to get it to work and stay on the command prompt. For example it should state the line but it just pops up and goes away. Then i need to know how to recall it and read it again:
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}

Thanks Again get back to me please

AJ

Edited by WingedPanther, 28 January 2009 - 10:36 AM.
add code tags (the # button)


#8
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Try running it in a command prompt. Also, have you opened example.txt to see what's in it?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#9
programming Child

programming Child

    Newbie

  • Members
  • Pip
  • 5 posts
yeah i have....:( i don't know what to do.

All i want to do is get somebodys name and number and store it so then i can pick it back up again by entering the file through c++ and opening it through command prompt. thats it really.

What is the difference between binary and txt. like i know the text but what does binary do? or how does it work?

thanks guys you have all been very helpful!

AJ

#10
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
binary stores the data as it exists in memory.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#11
Lance

Lance

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
Go with my 1.1.

There are many ways to achieve that, we are just recommending the easiest. You can definitely do it use a text file, eg, XML would certainly do, but that would be a lot to learn or to write before you can even start working on your business.

Simply put, we want to write Records of same size to the file so that data can be quickly located and retrieved. Old dBase do it pretty much the same way. In text mode, if a EOF charater is read, the file is deemed to have ended there, you don't want it this way. In text mode, on MS platform, a "\n" will be translated to "\r\n" before writing to the file, this is something you definitely want to avoid because it changes you Record size.

No before everything else, you're requested to, with the PersonRecord defined as,

struct PersonRecord

{

        char fname[30];

        char lname[50];


        int    height;

};


Construct 10 PersonRecord, write them to a file, say person.dat, and read back again, print out and check if every PersonRecord is stored and retrieved correctly.

You can use this as a start point to implement your project.

The beauty of fixed sized Record is, you can locate a record really fast, eg, if you want the 10th record, you just position the get pointer to 10*sizeof(Record) and read a record. The bad part is, you'll have to predetermine the width of each field.

#12
programming Child

programming Child

    Newbie

  • Members
  • Pip
  • 5 posts
So could anybody help me create codes using c++ that lets me store data and then open it again.

For example:

Name: John
Department: Deli
Gender: M

i want to put that into a .txt file then store it and open it back up again!

Please help

AJ