954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to incorporate Database into C++ ?

Does Anybody know how to use C++ to get information from a database? I have this assignment due but , I do no know to incorporate a database into my program. My program is to allow a user to choose from NFL football teams,when the user picks the team , they will see that teams 2004 draft picks.Here is how I have started without using a database.

function file:

#include //for file I/O *
#include
#include //for cin and cout *
#include "2004draft.h"
#include
#include //for exit() *

using namespace std;

const double pi = 3.14159;

//**********************************************************************************************
//**********************************************************************************************
void Draft::intro()
{
cout<<"\n\n\t ********* 2004 NFL DRAFT PROGRAM *********\n\n"
<<"\t(NFL teams only - one of each team)\n"
<<"\tYou will be given six choices.\n"
<<"\tPick the team that you are interested in,\n"
<<"\tbut first, ";
}

void Draft::getUsername()
{
cout<<"\n\n Please enter your name: ";
getline(cin,userName);
}

void Draft::getClassname()
{
cout<<" Enter class name: ";
cin>>className;
}

void Draft::getDate()
{
cout<<" Enter day: ";
cin>>day;
cout<<" Enter month: ";
cin>>month;
cout<<" Enter year: ";
cin>>year;
}
//************************************************************************************************
//************************************************************************************************

void Draft::getDBinfo()
{
cout<<"\n Round 1 (17): LB D.J. Williams,Miami:"<
#include "2004draft.h"
#include
using namespace std;

void main()
{
Draft findTeam;

findTeam.intro();
findTeam.getUsername();
findTeam.getClassname();
findTeam.getDate();
findTeam.outputName();
findTeam.outputCourseNum();
findTeam.outputDate();
cin.clear(); //This keeps variables from
cin.ignore(100,'\n'); // getting into 'choice',
// allows switch to work.
int choice;
do{


cout<<"\n\n Enter choice number:\t1 - Denver Broncos\n"<<
"\t\t\t2 - Minnisota Vikings \n"<<
"\t\t\t3 - Dallas Cowboys\n"<<
"\t\t\t4 - Arizona Cardinals \n"<<
"\t\t\t5 - Detroit Lions \n"<<
"\t\t\t6 - San Diego Chargers \n"<<
"\t\t\t7 - Green Bay Packers \n"<<
"\t\tor any other entry to quit: ";
cin>>choice;

switch (choice)
{
case 1:
findTeam.getDBinfo();
//findTeam.calcRC();
break;
case 2:
findTeam.getMVinfo();
//findTeam.calcRL();
break;
case 3:
findTeam.getDCinfo();
//findTeam.calcRLC();
break;
case 4:
findTeam.getACinfo();
//findTeam.calcParaRC();
break;
case 5:
findTeam.getDLinfo();
//findTeam.calcParaRL();
break;
case 6:
findTeam.getSCinfo();
//findTeam.calcParaRLC();
break;
case 7:
findTeam.getGBinfo();
}
}while(choice == 1 || choice == 2 || choice == 3 || choice == 4 || choice == 5 || choice == 6 || choice ==7);
}
IF anybody has some useful info I would appreciate it.

RPA
Newbie Poster
2 posts since May 2004
Reputation Points: 10
Solved Threads: 0
 

Hello,

A database is nothing more than a file with a certain pattern for data storage. In order to pull data from a database, you need to know HOW the data is internally stored within that file. A database could be a flat file, with one record per line, or it could be a binary file with internal search keys and other encoded data.

In order to help you with your code, you will need to tell us how the database is formatted, and you should also take a stab with the code to read it out and into variables. Chances are, you will need to put the data into a memory array or linked list, and you are going to need storage buckets to hold the data and the linked information together.

Good luck with it.

Christian

kc0arf
Posting Virtuoso
Team Colleague
1,937 posts since Mar 2004
Reputation Points: 121
Solved Threads: 57
 

Guys and gals just dont seem to understand file handling
Check this link http://www.daniweb.com/techtalkforums/thread5720.html

I give a basic intro on how to use a database.It's just the steps you can follow to retrive or write data.I use structs but you can also uses classes(Hey calsses are just structures with funtions attached,so you can write them to a file).

Many seem to have a problem with file handling and databse.[Does anybody want a full blown tutorial on fstream file handling and databses in C++,i will do one if ya want]

FireNet
Posting Whiz in Training
258 posts since May 2004
Reputation Points: 108
Solved Threads: 7
 

Thanks firenet. Yeah i would like a tutorial on the subject mentioned. Thanks .:mrgreen:

RPA
Newbie Poster
2 posts since May 2004
Reputation Points: 10
Solved Threads: 0
 

http://xlock.ssr.be/

is my site,so when it's up you will get the tut or an admin will have to put up a sticky of the file i/o tut

FireNet
Posting Whiz in Training
258 posts since May 2004
Reputation Points: 108
Solved Threads: 7
 

Hello there,

I was wondering if a database management library would be something nice, 'cos it won't be necessary to install a database management system before using a program that uses a database.
So, I've developed a database management library, DBL, and I would like to share it with C++ programmers. As soon as I can I intend to share the source-code as well.
There is also a DBL Command-Line Interface for download.

http://sites.google.com/site/rcorcs/download/system-softwares
sites.google.com/site/rcorcs/download/system-softwares

I reckon it might be useful for loads of C++ programmers

Cheers

rcorcs
Newbie Poster
7 posts since Jun 2010
Reputation Points: 9
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You