Database Applications for Managers Spring 2008  BU4040

Home  |  Syllabus  |  Journal  | Project Exam Research  |  Gallery

Journal Wednesday February 20, 2008

 

Next class we will have our first quiz. all questions by us. please Email to ebrahimidr@gmail.com  

Please have questions from all areas covered, Test will be on Monday 25th 2008 100 T/F Questions.

Most questions in this example are from chap. 9 That are important for a strong foundation of database

1- First copy and paste the questions from the website to a blank page.

2- Answer all questions and Email them to ebrahimidr@gmail.com  

3- Copy this to your wcm Exam Webpage.

Today we will discuss backing up your database.

Page 291-292 functions:

WHAT IS A DATABASE (dbase)

Manipulating data (information) plays an important role in any organization today. In order to manipulate the data, information has to be stored, retrieved, modified or deleted. At any moment new data can be added to a file, or existing information can be retrieved, modified or even deleted. Instead of one file there might be several files needed to store information as well as to interact with other files (file processing). The notion of data manipulation where data may be stored, retrieved, modified or even deleted is called a database.  In addition, there are times when it is necessary to generate reports based on a certain request or computations from the database.

 

 

A JOURNEY FROM BIT TO DATABASE

 

Computer information is represented in binary form using a bit.  Each bit contains a value which is either zero or one. Eight bits represent a byte. Depending on the system one or two bytes represent a character. Several characters form a field or a string. One or more fields make up a record. Multiple records build a stream or a file. Finally several files create a database. However this naming convention may vary slightly, a string may represent the whole file or a database may contain only a single file.

 

 

BUILDING A SIMPLE DATABASE: Create, Display and Search

 

The following program illustrates how easily you can build a simple database by putting a few functions together. For the sake of simplicity, the database program will add, display and search the data immediately, with data modification and deletion performed later. In writing this program, the concern is simplicity rather than efficiency (speed of program or saving space). The three functions for this database are myappend() to add a record to the end of data file, mydisplay() to display entire records, and mysearch() to search  for a particular record.

 

 

MODE OF OPENING A FILE

 

A file can be opened according to the following ways (modes):

A file can be opened as an input file so that data can be retrieved.

ifstream fin (“data.in”,ios::in);

 

      

 The default file mode for ifstream is ios::in

ifstream fin (“data.in”); //input stream

 

      

A file can be opened so that data can be written or output to it.

ofstream fout (“data.out”,ios::out);

 

     

  The default file mode for ofstream is ios::ou

ofstream fout (“data.out”);

 

       

 

In addition a file can be for output by adding (appending) data to the end of the existing file.

ofstream fout (“data.out”,ios::app);

          

A file can be for both input and output ios::in | ios::out

 

fstream fout (“data.dat”, ios::in|ios::out);

 

Ruan  contribution for today program from page 292.

 

#include<fstream>

#include<string.h>

#include<iostream>

#include<iomanip>

#include<stdlib.h>

using namespace std;

int myappend(char personname[],char phone[]){

ofstream fout("directory.txt",ios::app);

cout<<"ENTER PERSON NAME";

cin>>personname;

cout<<"Enter THE PHONE";

cin>>phone;

fout<<personname<<setw(20)<<phone<<endl;

return 0; }// MyAppend

int mysearch(char personname[],char phone[]){

char searchname[20];

ifstream fin("directory.txt",ios::in);

cout<<"ENTER THe Search Name";

cin>>searchname;

while(fin>>personname>>phone){

if(strcmp(searchname,personname)==0){

cout<<"THE PHONE IS" <<phone<<endl<<endl;

return 1; } //if

}// while

cout<<"NAME NOT FOUND" <<endl;

return 0; } //MYSearch

int mydisplay(char personname[],char phone[]){

ifstream fin("directory.txt");

while(fin>>personname>>phone){

cout<<"PERSON NAME IS" << personname<<endl;

cout<<"PHONE IS " <<phone<<endl; }//while

return 0; } // My Display

main(){

char option;

char personname[20],phone[20];

cout<<"Select One Of The Following" << endl;

while(1) { cout<<"TYPE 1 TO INSERT" <<endl;

cout<<"TYPE 2 TO Display" <<endl;

cout<<"TYPE 3 TO Search" <<endl;

cout<<"TYPE # TO Quit" <<endl;

cin>>option;

if(option =='1')myappend(personname,phone);

else if (option=='2') mydisplay(personname,phone);

else if (option=='3') mysearch(personname,phone);

else if (option=='#') {cout<<"BYE"<<endl;exit(1);} } //while

return 0;

}//Main

 

 

 YEAR 2007 NOTES Class notes