| | |
How to incorporate Database into C++ ?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2004
Posts: 2
Reputation:
Solved Threads: 0
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 <fstream> //for file I/O *
#include <string>
#include <iostream> //for cin and cout *
#include "2004draft.h"
#include <math.h>
#include <stdlib.h> //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:"<<endl;
cout<<"\n Round 2 (41): RB Tatum Bell ,Oklahoma State:"<<endl;
cout<<"\n Round 2 (54): WR Darius Watts,Marshall :"<<endl;
cout<<"\n Round 3 (85): CB Jeremy LeSueur,Michigan :"<<endl;
cout<<"\n Round 5 (152): CB Jeff Shoate,San Diego State :"<<endl;
cout<<"\n Round 6 (171): WR Triandos Luke,Alabama :"<<endl;
cout<<"\n Round 6 (190): C Josh Sewell,Nebraska :"<<endl;
cout<<"\n Round 7 (225): QB Matt Mauck,Louisiana State:"<<endl;
cout<<"\n Round 7 (247): RB Brandon Miree ,Pittsburgh :"<<endl;
cout<<"\n Round 7 (250): QB Bradlee Van Pelt,Colorado State:"<<endl;
}
//************************************************************************************************
//************************************************************************************************
void Draft::getMVinfo()
{
cout<<"\n Round 1 (20) : Kenechi Udeze DE USC (from Miami) "<<endl;
cout<<"\n Round 2 (48): Dontarrious Thomas OLB Auburn (from New Orleans)" <<endl;
cout<<"\n Round 3 (88): Darrion Scott DE Ohio St. (from Baltimore) "<<endl;
cout<<"\n Round 4 (115) Nat Dorsey OT Georgia Tech "<<endl;
cout<<"\n Round 4 (119) Mewelde Moore RB Tulane (from Miami) "<<endl;
cout<<"\n Round 5 (155) Rod Davis MLB Southern Miss (from Baltimore) "<<endl;
cout<<"\n Round 6 (184) Deandre' Eiland S South Carolina "<<endl;
cout<<"\n Round 7 (220) Jeff Dugan TE Maryland"<<endl;
}
//************************************************************************************************
//************************************************************************************************
void Draft::getDCinfo()
{
cout<<"\n Round 2 (43) Julius Jones RB Notre Dame (from Buffalo) "<<endl;
cout<<"\n Round 2 (52) Jacob Rogers OT USC "<<endl;
cout<<"\n Round 3 (83) Stephen Peterman OG LSU " <<endl;
cout<<"\n Round 4 (121) Bruce Thornton CB Georgia"<<endl;
cout<<"\n Round 5 (144) Sean Ryan TE Boston College (from Buffalo)" <<endl;
cout<<"\n Round 7 (205) Nate Jones CB Rutgers (from Oakland)" <<endl;
cout<<"\n Round 7 (216) Patrick Crayton WR NW Oklahoma St. (from Tampa Bay)"<<endl;
cout<<"\n Round 7 (223) Jacques Reeves CB Purdue (from Dallas via Oakland)"<<endl;
}
//************************************************************************************************
//************************************************************************************************
void Draft::getACinfo()
{
cout<<"\n Round 1 (3) Larry Fitzgerald WR Pittsburgh"<<endl;
cout<<"\n Round 2 (33) Karlos Dansby OLB Auburn" <<endl;
cout<<"\n Round 3 (64) Darnell Dockett DT Florida St."<<endl;
cout<<"\n Round 4 (100) Alex Stepanovich C Ohio St. "<<endl;
cout<<"\n Round 5 (135) Antonio Smith DE Oklahoma St. "<<endl;
cout<<"\n Round 6 (167) Nick Leckey C Kansas St. "<<endl;
cout<<"\n Round 7 (202) John Navarre QB Michigan "<<endl;
}
//************************************************************************************************
//***********************************************************************************************
void Draft::getDLinfo()
{
cout<<"\n Round 1 (7) Roy Williams WR Texas (from Cleveland)"<<endl;
cout<<"\n Round 1 (30) Kevin Jones RB Virginia Tech (from Kansas City)"<<endl;
cout<<"\n Round 2 (37) Teddy Lehman OLB Oklahoma (from Cleveland)"<<endl;
cout<<"\n Round 3 (73) Keith Smith CB McNeese St." <<endl;
cout<<"\n Round 5 (140) Alex Lewis OLB Wisconsin "<<endl;
cout<<"\n Round 6 (172) Kelly Butler OT Purdue "<<endl;
}
//*************************************************************************************************
//*************************************************************************************************
void Draft::getSCinfo()
{
cout<<"\n Round 1 (1) Eli Manning QB Mississippi traded to NY Giants "<<endl;
cout<<"\n Round 2 (35) Igor Olshansky DT Oregon "<<endl;
cout<<"\n Round 3 (65) Nate Kaeding K Iowa (from NY Giants)"<<endl;
cout<<"\n Round 3 (66) Nick Hardwick C Purdue "<<endl;
cout<<"\n Round 4 (98) Shaun Phillips DE Purdue "<<endl;
cout<<"\n Round 5 (133) Dave Ball DE UCLA "<<endl;
cout<<"\n Round 5 (154) Michael Turner RB Northern Illinois (from Miami)"<<endl;
cout<<"\n Round 6 (169) Ryan Krause WR Nebraska (Omaha) "<<endl;
cout<<"\n Round 7 (204) Ryon Bingham DT Nebraska"<<endl;
cout<<"\n Round 7 (209) Shane Olivea OT Ohio St. (from Atlanta)"<<endl;
cout<<"\n Round 7 (254) Carlos Joseph OT Miami (Fl) (Compensatory) "<<endl;
}
//************************************************************************************************
//************************************************************************************************
void Draft::getGBinfo()
{
cout<<"\n Round 1 (25) Ahmad Carroll CB Arkansas "<<endl;
cout<<"\n Round 3 (70) Joey Thomas CB Montana St. (from Jacksonville) "<<endl;
cout<<"\n Round 3 (72) Donnell WashingtonDT Clemson(from Washington via Jacksonville)"<<endl;
cout<<"\n Round 3 (87) B.J. Sander P Ohio St (from Miami)"<<endl;
cout<<"\n Round 6 (179) Corey Williams DT Arkansas St.(from San Francisco)"<<endl;
cout<<"\n Round 7 50 (251) Scott Wells C Tennessee (Compensatory)"<<endl;
}
//*************************************************************************************************
//************************************************************************************************
//void Draft::getAFinfo()
//{
//}
//*************************************************************************************************
//************************************************************************************************
void Draft::outputName()
{
cout<<"\n\n 2004 nfl team draft locator "<<userName<<"."<<endl;}
void Draft::outputCourseNum()
{
cout<<" I hope you enjoyed the "<<className<<" class."<<endl;}
void Draft::outputDate()
{
cout<<" You logged in on "<<day<<" "<<month<<" "<<year<<"."<<endl<<endl;}
file to display
#include<iostream>
#include "2004draft.h"
#include<math.h>
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.
function file:
#include <fstream> //for file I/O *
#include <string>
#include <iostream> //for cin and cout *
#include "2004draft.h"
#include <math.h>
#include <stdlib.h> //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:"<<endl;
cout<<"\n Round 2 (41): RB Tatum Bell ,Oklahoma State:"<<endl;
cout<<"\n Round 2 (54): WR Darius Watts,Marshall :"<<endl;
cout<<"\n Round 3 (85): CB Jeremy LeSueur,Michigan :"<<endl;
cout<<"\n Round 5 (152): CB Jeff Shoate,San Diego State :"<<endl;
cout<<"\n Round 6 (171): WR Triandos Luke,Alabama :"<<endl;
cout<<"\n Round 6 (190): C Josh Sewell,Nebraska :"<<endl;
cout<<"\n Round 7 (225): QB Matt Mauck,Louisiana State:"<<endl;
cout<<"\n Round 7 (247): RB Brandon Miree ,Pittsburgh :"<<endl;
cout<<"\n Round 7 (250): QB Bradlee Van Pelt,Colorado State:"<<endl;
}
//************************************************************************************************
//************************************************************************************************
void Draft::getMVinfo()
{
cout<<"\n Round 1 (20) : Kenechi Udeze DE USC (from Miami) "<<endl;
cout<<"\n Round 2 (48): Dontarrious Thomas OLB Auburn (from New Orleans)" <<endl;
cout<<"\n Round 3 (88): Darrion Scott DE Ohio St. (from Baltimore) "<<endl;
cout<<"\n Round 4 (115) Nat Dorsey OT Georgia Tech "<<endl;
cout<<"\n Round 4 (119) Mewelde Moore RB Tulane (from Miami) "<<endl;
cout<<"\n Round 5 (155) Rod Davis MLB Southern Miss (from Baltimore) "<<endl;
cout<<"\n Round 6 (184) Deandre' Eiland S South Carolina "<<endl;
cout<<"\n Round 7 (220) Jeff Dugan TE Maryland"<<endl;
}
//************************************************************************************************
//************************************************************************************************
void Draft::getDCinfo()
{
cout<<"\n Round 2 (43) Julius Jones RB Notre Dame (from Buffalo) "<<endl;
cout<<"\n Round 2 (52) Jacob Rogers OT USC "<<endl;
cout<<"\n Round 3 (83) Stephen Peterman OG LSU " <<endl;
cout<<"\n Round 4 (121) Bruce Thornton CB Georgia"<<endl;
cout<<"\n Round 5 (144) Sean Ryan TE Boston College (from Buffalo)" <<endl;
cout<<"\n Round 7 (205) Nate Jones CB Rutgers (from Oakland)" <<endl;
cout<<"\n Round 7 (216) Patrick Crayton WR NW Oklahoma St. (from Tampa Bay)"<<endl;
cout<<"\n Round 7 (223) Jacques Reeves CB Purdue (from Dallas via Oakland)"<<endl;
}
//************************************************************************************************
//************************************************************************************************
void Draft::getACinfo()
{
cout<<"\n Round 1 (3) Larry Fitzgerald WR Pittsburgh"<<endl;
cout<<"\n Round 2 (33) Karlos Dansby OLB Auburn" <<endl;
cout<<"\n Round 3 (64) Darnell Dockett DT Florida St."<<endl;
cout<<"\n Round 4 (100) Alex Stepanovich C Ohio St. "<<endl;
cout<<"\n Round 5 (135) Antonio Smith DE Oklahoma St. "<<endl;
cout<<"\n Round 6 (167) Nick Leckey C Kansas St. "<<endl;
cout<<"\n Round 7 (202) John Navarre QB Michigan "<<endl;
}
//************************************************************************************************
//***********************************************************************************************
void Draft::getDLinfo()
{
cout<<"\n Round 1 (7) Roy Williams WR Texas (from Cleveland)"<<endl;
cout<<"\n Round 1 (30) Kevin Jones RB Virginia Tech (from Kansas City)"<<endl;
cout<<"\n Round 2 (37) Teddy Lehman OLB Oklahoma (from Cleveland)"<<endl;
cout<<"\n Round 3 (73) Keith Smith CB McNeese St." <<endl;
cout<<"\n Round 5 (140) Alex Lewis OLB Wisconsin "<<endl;
cout<<"\n Round 6 (172) Kelly Butler OT Purdue "<<endl;
}
//*************************************************************************************************
//*************************************************************************************************
void Draft::getSCinfo()
{
cout<<"\n Round 1 (1) Eli Manning QB Mississippi traded to NY Giants "<<endl;
cout<<"\n Round 2 (35) Igor Olshansky DT Oregon "<<endl;
cout<<"\n Round 3 (65) Nate Kaeding K Iowa (from NY Giants)"<<endl;
cout<<"\n Round 3 (66) Nick Hardwick C Purdue "<<endl;
cout<<"\n Round 4 (98) Shaun Phillips DE Purdue "<<endl;
cout<<"\n Round 5 (133) Dave Ball DE UCLA "<<endl;
cout<<"\n Round 5 (154) Michael Turner RB Northern Illinois (from Miami)"<<endl;
cout<<"\n Round 6 (169) Ryan Krause WR Nebraska (Omaha) "<<endl;
cout<<"\n Round 7 (204) Ryon Bingham DT Nebraska"<<endl;
cout<<"\n Round 7 (209) Shane Olivea OT Ohio St. (from Atlanta)"<<endl;
cout<<"\n Round 7 (254) Carlos Joseph OT Miami (Fl) (Compensatory) "<<endl;
}
//************************************************************************************************
//************************************************************************************************
void Draft::getGBinfo()
{
cout<<"\n Round 1 (25) Ahmad Carroll CB Arkansas "<<endl;
cout<<"\n Round 3 (70) Joey Thomas CB Montana St. (from Jacksonville) "<<endl;
cout<<"\n Round 3 (72) Donnell WashingtonDT Clemson(from Washington via Jacksonville)"<<endl;
cout<<"\n Round 3 (87) B.J. Sander P Ohio St (from Miami)"<<endl;
cout<<"\n Round 6 (179) Corey Williams DT Arkansas St.(from San Francisco)"<<endl;
cout<<"\n Round 7 50 (251) Scott Wells C Tennessee (Compensatory)"<<endl;
}
//*************************************************************************************************
//************************************************************************************************
//void Draft::getAFinfo()
//{
//}
//*************************************************************************************************
//************************************************************************************************
void Draft::outputName()
{
cout<<"\n\n 2004 nfl team draft locator "<<userName<<"."<<endl;}
void Draft::outputCourseNum()
{
cout<<" I hope you enjoyed the "<<className<<" class."<<endl;}
void Draft::outputDate()
{
cout<<" You logged in on "<<day<<" "<<month<<" "<<year<<"."<<endl<<endl;}
file to display
#include<iostream>
#include "2004draft.h"
#include<math.h>
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.
•
•
Join Date: Mar 2004
Posts: 1,620
Reputation:
Solved Threads: 51
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
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
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]
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]
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
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
![]() |
Similar Threads
- Database - CPanel (Database Design)
- Urgent Help!! Database Tables (Oracle)
- Calling a PHP function with Ajax (JavaScript / DHTML / AJAX)
- Website and Database Programmer Wanted in Scottsdale, AZ (Web Development Job Offers)
- I want to know how to make a Reviewing Database. (Database Design)
Other Threads in the C++ Forum
- Previous Thread: Please Check The Errors'..Dont know what else to do
- Next Thread: Better code for TCheckListBox
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






