Please help programming (in SQLite C or SQLite C++) Project description. Music-S
ID: 3762814 • Letter: P
Question
Please help programming (in SQLite C or SQLite C++)
Project description.
Music-Shop has many CDs and its CD listing in a database (named "song.db") with sqlite3. The database maintains three tables of artist, cd and track of each cd. Each cd has many tracks. Each track has a song (song title) of an artist. The schema and sample listings of these tables are shown below.
create table cd (
id INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(70) NOT NULL,
artist_id INTEGER NOT NULL,
catalogue VARCHAR(30) NOT NULL
);
create table artist (
id INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY,
name VARCHAR(100) NOT NULL
);
create table track (
cd_id INTEGER NOT NULL,
track_id INTEGER NOT NULL,
title VARCHAR(70),
PRIMARY KEY(cd_id, track_id)
);
One day the database was damaged and unrecoverable. Fortunately, someone saved a file of all the records a few days before the crash (as shown below where each field is separated by "|").
sqlite> select * from artist;
1|Pink Floyd
2|Genesis
3|Einaudi
4|Melanie C
sqlite> select * from cd;
1|Dark Side of the Moon|1|B000024D4P
2|Wish You Were Here|1|B000024D4S
3|A Trick of the Tail|2|B000024EXM
4|Selling England By the Pound|2|B000024E9M
5|I Giorni|3|B000071WEV
6|Northern Star|4|B00004YMST
sqlite> select * from track;
1|1|Speak to me
1|2|Breathe
1|3|On the run
1|4|Time
1|5|Great gig in the sky
1|6|Mooney
1|7|Us and them
1|8|Any colour you like
1|9|Brain damage
1|10|Eclipse
2|1|Shine on you crazy diamond
2|2|Welcome to the machine
2|3|Have a cigar
2|4|Wish you were here
2|5|Shine on you crazy diamond pt.2
3|1|Dance on a volcano
3|2|Entangled
3|3|Squonk
3|4|Madman moon
3|5|Robbery assault and battery
3|6|Ripples
3|7|Trick of the tail
3|8|Los Endos
4|1|Melodia Africana (part 1)
4|2|I due fiumi
4|3|In unaltra vita
4|4|Melodia Africana (part 2)
4|5|Stella del mattino
4|6|I giorni
4|7|Samba
4|8|Melodia Africana (part 3)
4|9|La nascita delle cose segrete
4|10|Quel che resta
4|11|Inizio
4|12|Limbo
4|13|Bella notte
4|14|Canzone Africana (part 4)
6|1|Go!
6|2|Northern Star
6|3|Goin Down
6|4|I Turn To You
6|5|If That Were Me
6|6|Never Be The Same Again
6|7|Why
6|8|Suddenly Monday
6|9|Ga Ga
6|10|Be The One
6|11|Closer
6|12|Feel The Sun
The shop-manager wants you (IT consultant) to do a project, to create a software system (using C++ with sqlite3 database) to restore the lost database. Your job is to write a C++ program to do the following tasks.
Your C++ program will do (interacting with sqlite3 database, named "song.db" which is initially empty). This is done by "touch song.db" to create an empty file.
Part 1.
(A1) You need to create the files of artist, cd, and track (as shown above).
To read the file and tokenize each line to get each field data.
(A2) Use it (from (1)) to create sql statement(s) to be used to call the database, to create the tables and then to insert each record (one by one, or all at once for each table). For each record, for example, the first record for track
1|1|Speak to me
should be a sql insert statement to be used for the program to interact with the database, to insert a record
insert into track(cd_id, track_id, title) values(1, 1, 'Speak to me');
(A3) To get the records from the database tables, and to output (print) each record to a file, after (p2) is done. The output should include a proper heading for each table and formatting for each record to be printed into an output file. You may use select statement to get all the records of a table (for example, "select * from artist;" to get all the records from artist table).
(A4) After all done, someone discovered one typo in the record.
You will write a small quick-fix C++ program, to correct this typo in the record in the database as shown below. With update sql call, the song title should be updated to "Money" (not "Mooney"). After it is corrected, get the record from the database and print it. You may use select statement to get all the records of the track table (for example, "select * from track;" to get all the records from track table) to show the record has been corrected.
1|6|Mooney which should be 1|6|Money
You may need to call sqlite3 to do this update: update track set title = 'money' where cd_id=1 and track_id=6;
(A5) To delete all the records in the tables of the database, to clean up.
Part2.
(B1) to design and implement three classes (artist, cd, track) corresponding to each table (artist, cd, track).
(B2) to get the data from the database to create (instantiate) each object corresponding to each record (from each table: artist, cd, and track). For example, for each artist record, its object (of each artist) will be created and initialized accordingly. After each class and its objects created, the program will generate a report for this class and all the objects of each class.
(B3) to use a C++ STL map (associative container), the created objects (of each class) should be kept in record so that you may enumerate (iterate) each object of artist class, or to search an artist object with artist id, etc.
See some examples of how to create a map and use of map iterator. You may use "static" keyword to keep the instance of a map to be static.
(B4) After creating all the objects (of artist, cd, and track), the program will check the integrity of the data (the objects). For example, each cd object has a field (variable) for an artist id. That is, the corresponding artist object (of this artist id defined in a cd object) should be created and exist. The program will check the integrity and produce a report of any exception (missing data) or to state, for example, that the artist id in one cd object is checked. Each integrity check will be implemented via a method of each class.
For example, you will have a method (getArtist) in the cd class to get the corresponding artist object (a reference to the object) with the artist id specified in that particular cd object (to verify the data or object integrity with the artist object with the artist id in question). For example, getArtist(int artistID) call where artistID = 1, will return the reference to the artist object of which artist id = 1. If the artist object is not existed then return a null pointer (to indicate an exception).
Current data is in integrity.
Next update your program to insert a track record (below) to create an exception.
7|Northern Star|5|B00004YMST
This will create an integrity problem for there is no artist id which is 5.
Run your program to generate the exception report for this case.
--- Hint for SQL statements for your program to generate from the data.
--- First the artist (or group) tables
insert into artist(id, name) values(1, 'Pink Floyd');
insert into artist(id, name) values(2, 'Genesis');
insert into artist(id, name) values(3, 'Einaudi');
insert into artist(id, name) values(4, 'Melanie C');
--- Then the cd table
insert into cd(id, title, artist_id, catalogue) values(1, 'Dark Side of the Moon', 1, 'B000024D4P');
insert into cd(id, title, artist_id, catalogue) values(2, 'Wish You Were Here', 1, 'B000024D4S');
insert into cd(id, title, artist_id, catalogue) values(3, 'A Trick of the Tail', 2, 'B000024EXM');
insert into cd(id, title, artist_id, catalogue) values(4, 'Selling England By the Pound', 2, 'B000024E9M');
insert into cd(id, title, artist_id, catalogue) values(5, 'I Giorni', 3, 'B000071WEV');
insert into cd(id, title, artist_id, catalogue) values(6, 'Northern Star', 4, 'B00004YMST');
--- Finally we populate the track
insert into track(cd_id, track_id, title) values(1, 1, 'Speak to me');
insert into track(cd_id, track_id, title) values(1, 2, 'Breathe');
insert into track(cd_id, track_id, title) values(1, 3, 'On the run');
insert into track(cd_id, track_id, title) values(1, 4, 'Time');
insert into track(cd_id, track_id, title) values(1, 5, 'Great gig in the sky');
insert into track(cd_id, track_id, title) values(1, 6, 'Mooney');
insert into track(cd_id, track_id, title) values(1, 7, 'Us and them');
insert into track(cd_id, track_id, title) values(1, 8, 'Any colour you like');
insert into track(cd_id, track_id, title) values(1, 9, 'Brain damage');
insert into track(cd_id, track_id, title) values(1, 10, 'Eclipse ');
insert into track(cd_id, track_id, title) values(2, 1, 'Shine on you crazy diamond');
insert into track(cd_id, track_id, title) values(2, 2, 'Welcome to the machine');
insert into track(cd_id, track_id, title) values(2, 3, 'Have a cigar');
insert into track(cd_id, track_id, title) values(2, 4, 'Wish you were here');
insert into track(cd_id, track_id, title) values(2, 5, 'Shine on you crazy diamond pt.2');
insert into track(cd_id, track_id, title) values(3, 1, 'Dance on a volcano');
insert into track(cd_id, track_id, title) values(3, 2, 'Entangled');
insert into track(cd_id, track_id, title) values(3, 3, 'Squonk');
insert into track(cd_id, track_id, title) values(3, 4, 'Madman moon');
insert into track(cd_id, track_id, title) values(3, 5, 'Robbery assault and battery');
insert into track(cd_id, track_id, title) values(3, 6, 'Ripples');
insert into track(cd_id, track_id, title) values(3, 7, 'Trick of the tail');
insert into track(cd_id, track_id, title) values(3, 8, 'Los Endos');
insert into track(cd_id, track_id, title) values(4, 1, 'Melodia Africana (part 1)');
insert into track(cd_id, track_id, title) values(4, 2, 'I due fiumi');
insert into track(cd_id, track_id, title) values(4, 3, 'In unaltra vita');
insert into track(cd_id, track_id, title) values(4, 4, 'Melodia Africana (part 2)');
insert into track(cd_id, track_id, title) values(4, 5, 'Stella del mattino');
insert into track(cd_id, track_id, title) values(4, 6, 'I giorni');
insert into track(cd_id, track_id, title) values(4, 7, 'Samba');
insert into track(cd_id, track_id, title) values(4, 8, 'Melodia Africana (part 3)');
insert into track(cd_id, track_id, title) values(4, 9, 'La nascita delle cose segrete');
insert into track(cd_id, track_id, title) values(4, 10, 'Quel che resta');
insert into track(cd_id, track_id, title) values(4, 11, 'Inizio');
insert into track(cd_id, track_id, title) values(4, 12, 'Limbo');
insert into track(cd_id, track_id, title) values(4, 13, 'Bella notte');
insert into track(cd_id, track_id, title) values(4, 14, 'Canzone Africana (part 4)');
insert into track(cd_id, track_id, title) values(6, 1, 'Go!');
insert into track(cd_id, track_id, title) values(6, 2, 'Northern Star');
insert into track(cd_id, track_id, title) values(6, 3, 'Goin Down');
insert into track(cd_id, track_id, title) values(6, 4, 'I Turn To You');
insert into track(cd_id, track_id, title) values(6, 5, 'If That Were Me');
insert into track(cd_id, track_id, title) values(6, 6, 'Never Be The Same Again');
insert into track(cd_id, track_id, title) values(6, 7, 'Why');
insert into track(cd_id, track_id, title) values(6, 8, 'Suddenly Monday');
insert into track(cd_id, track_id, title) values(6, 9, 'Ga Ga');
insert into track(cd_id, track_id, title) values(6, 10, 'Be The One');
insert into track(cd_id, track_id, title) values(6, 11, 'Closer');
insert into track(cd_id, track_id, title) values(6, 12, 'Feel The Sun');
Explanation / Answer
#include <iostream.h>
#include <fstream.h>
#include <process.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<iomanip.h>
#include<graphics.h>
typedef char option[15];
const int ROW = 10, COL = 10;
int scan; // To hold the special characters for moving the prompt in menu
int ascii;
// To display the main menu options
option a[]= {"NewCassPur", "ListOfPurchase", "DailyCassSales", "SalesReport", "AddOtherExp", "OtherExpRep", "ClosingStock", "MonthlyProfit", "Exit"};
// Function used to do screening
class main_menu
{
int i,done;
public:
void normalvideo(int x,int y,char *str);
void reversevideo(int x,int y,char *str);
void box(int x1,int y1,int x2,int y2);
char menu();
void control_menu();
void help(void);
};
/* Class member functions for drawing boxes */
class shape
{
public:
void line_hor(int, int, int, char);
void line_ver(int, int, int, char);
void box(int, int, int, int, char);
};
// Class contains the cassettes deposit of customers
class cassettes
{
public:
void new_cassettes(void); // Function to add new cassettes in music shop
// For cassettes entry into the cassettes.dat data file
void add_to_file(int, char t_Cass_name[30], char t_Comp_name[30], int,
int, int, int, float);
void display_list(void); // Displaying the cassettes list
void delete_cassette(int); // Deletes the temporary cassette record
int last_cas_code(void); // if the file is exist or not
char *return_name(int); // Function for validation entry of name
char *return_address(int); // Function for validation entry of address
int recordno(int);
void display(int); // To display the cassette information account
private:
// Data Members of cassette.dat data file
int cas_code; // Cassette code – film, nonfilm, religious
char Cass_name[30]; // Title of the cassette
char Comp_name[30]; // Cassette company
int tot_cassette; // Total cassette purchased
int dd, mm, yy; // Date of purchase
float price; // Price per cassette
};
class balance
{
public:
void add_to_file(int, int, int, int, int, float); // Add record for
void balance_cassette(void); // Function to display the balance cassette
void delete_balance(int); // Deleting the balance from Tbal.dat
int give_balance(int); // returns the current balance of a particular
// cassette code
void Update_balance(int, int, int , int , int, float); // Function to
float return_price(int); // Return the cassette price
void monthly_profit(void); // Monthly profit after every transaction
private:
// Data members of Tbal.dat data file
int cas_code; // Cassette code to be balance
int cas_bal; // Total number of cassettes in balance
int dd; // Balance date
int mm;
int yy;
float price; // Unit price of cassettes on code wise
};
// Class contains the customers daily cassette transaction entry
class account
{
public:
void new_account(void); // Function to sale cassettes
void close_account(void); // Function to close the cassette purchase
void clear(int, int); // Function to perform a clear screen function
void Display_sales(void); // Displaying the sales report of cassettes
int last_cas_code(void); // if the file is exist or not
float sales_status(int m1, int y1, float cod1, float cod2, float cod3);
private:
void add_to_file(int, char tP_name[30], char tP_address[30],int, int,
int, int); // Function to add transaction records
void delete_account(int); // Function to delete a transaction record
// Data members of person.dat data file
int cas_code; // Cassette code – film, nonfilm, religious
char P_name[30]; // Person Name
char P_address[30]; // Person Address
int No_cass; // Number of cassette
int dd, mm, yy; // To store the system date/ purchase date
};
class other
{
public :
// Function to display other expense screen like salary,
// electricity bill, telephone and miscellaneous expences
void Expense_other(void);
// Add the data to Other.dat data file
void add_to_file(int, char tNat_Expen[30], int, int, int, float);
void display_expense(void); // Display the expenses
float other_status(int m1, int y1);
private :
// Data members of other.dat data file
int O_code; // Other expence code
/* The other expence code as :
1 - Salary to workers,
2 - Electricity bill
3 - Telephone bills
4 - Miscellaneous expenses */
char Nat_Expen[30]; // Nature of expense description
int dd, mm, yy; // Expense date
float amount; // Expense amount
};
// Function to displays all the menu prompt messages
// from the pointer array of option a[]
void main_menu::normalvideo(int x,int y,char *str)
{
gotoxy(x,y);
cprintf("%s",str);
}
// Function to move the cursor on the menu prompt
// with a reverse video color
void main_menu::reversevideo(int x,int y,char *str)
{
textcolor(5+143);
textbackground(WHITE);
gotoxy(x,y);
cprintf("%s",str);
textcolor(GREEN);
textbackground(BLACK);
}
void main_menu::box(int x1,int y1,int x2,int y2)
{
for(int col=x1;col<x2;col++)
{
gotoxy(col,y1);
cprintf("%c",196);
gotoxy(col,y2);
cprintf("%c",196);
}
for(int row=y1;row<y2;row++)
{
gotoxy(x1,row);
cprintf("%c",179);
gotoxy(x2,row);
cprintf("%c",179);
}
gotoxy(x1,y1);
cprintf("%c",218);
gotoxy(x1,y2);
cprintf("%c",192);
gotoxy(x2,y1);
cprintf("%c",191);
gotoxy(x2,y2);
cprintf("%c",217);
}
// Displaying the main menu of music system
char main_menu::menu()
{
clrscr();
textcolor(22);
box(20, 6, 65, 20);
box(18, 4, 67, 22);
textcolor(5+143);
gotoxy(36, 5);
textbackground(BLUE);
cprintf("M U S I C");
textbackground(BLACK);
textcolor(22);
for(i = 1; i<9; i++)
normalvideo(32, i+10, a[i]);
reversevideo(32, 10, a[0]);
i = done = 0;
_setcursortype(_NOCURSOR);
do
{
int key = getch();
switch (key)
{
case 00:
key = getch();
switch (key)
{
case 72:
normalvideo(32, i+10, a[i]);
int i;
if (i==-1)
i=8;
reversevideo(32,i+10, a[i]);
break;
case 80:
normalvideo(32, i+10, a[i]);
i++;
if (i == 9)
i = 0;
reversevideo(32, i+10, a[i]);
break;
}
break;
case 13:
done = 1;
}
} while (!done);
_setcursortype(_NOCURSOR);
return(i+49);
}
/* The function main_menu() is used to display the main menu system */
void main_menu::control_menu()
{
char choice;
cassettes cas;
account a;
balance bal;
other oth;
do
{
choice = menu();
clrscr();
switch (choice)
{
case '1':
_setcursortype(_NORMALCURSOR);
box(3, 1, 75, 24);
box(5, 2, 73, 23);
cas.new_cassettes(); // New cassette entry function
break;
case '2':
box(3, 1, 75, 24);
box(5, 2, 73, 23);
cassettes ini;
ini.display_list(); // Glogal list of cassettes function
break;
case '3':
box(3, 1, 75, 24);
box(5, 2, 73, 23);
_setcursortype(_NORMALCURSOR);
a.new_account(); // Enter the personwise sale cassette
break;
case '4':
box(3, 1, 75, 24);
box(5, 2, 73, 23);
account a;
_setcursortype(_NORMALCURSOR);
a.Display_sales(); // Displays the sales cassettes
break;
case '5':
box(3, 1, 75, 24);
box(5, 2, 73, 23);
_setcursortype(_NORMALCURSOR);
oth.Expense_other(); // Entry of other expenses
break;
case '6':
box(3, 1, 75, 24);
box(5, 2, 73, 23);
gotoxy(10,10);
oth.display_expense(); // Displays the expenses
break;
case '7':
box(3, 1, 75, 24);
box(5, 2, 73, 23);
gotoxy(10,10);
bal.balance_cassette(); // Function to display the balance cassettes in shop
break;
case '8':
box(3, 1, 75, 24);
box(5, 2, 73, 23);
gotoxy(10,10);
// Monthly profit after every transaction
bal.monthly_profit();
break;
case '9':exit(0);
}
} while (choice != 8);
}
/* Function to draw horizontal line for menu*/
void shape::line_hor(int column1, int column2, int row, char c)
{
for (column1; column1 <= column2; column1++)
{
gotoxy(column1, row);
cout << c;
}
}
/* Function to draw vertical line for menu */
void shape::line_ver(int row1, int row2, int column, char c)
{
for (row1; row1 <= row2; row1++)
{
gotoxy(column, row1);
cout << c;
}
}
/* Function for drawing boxes for menu */
void shape::box(int column1, int row1, int column2, int row2, char c)
{
char ch = 218;
char c1, c2, c3, c4;
char l1 = 196, l2 = 179;
if (c == ch)
{
c1 = 218;
c2 = 191;
c3 = 217;
c4 = 217;
l1 = 196;
l2 = 179;
}
else
{
c1 = c;
c2 = c;
c3 = c;
c4 = c;
l1 = c;
c2 = c;
}
gotoxy(column1, row1);
cout << c1;
gotoxy(column2, row1);
cout << c2;
gotoxy(column1, row2);
cout << c3;
gotoxy(column2, row2);
cout << c4;
column1++;
column2;
line_hor(column1, column2, row1, l1); //Horizontal line
line_hor(column1, column2, row2, l1);
column1;
column2++;
row1++;
row2;
line_ver(row1, row2, column1, l2); // Vertical line
line_ver(row1, row2, column2, l2);
}
/* Function to display help about this project */
void main_menu::help(void)
{
clrscr();
setbkcolor(7);
settextstyle(7,HORIZ_DIR,5);
outtextxy(70,20,"Welcome to Music Shop");
settextstyle(2,HORIZ_DIR,5);
outtextxy(60,100, "This project your can keep record of daily music cassettes");
delay(2);
outtextxy(60,130, "transaction. This program is capable of holding any no. of cassettes.");
delay(2);
outtextxy(60,160, "-In first option you can enter new cassette information");
delay(2);
outtextxy(60,190, "-In second option you can see the list of all the cassettes");
delay(2);
outtextxy(60,220,"-In third option you can sales the cassettes according to demand");
delay(2);
outtextxy(60,250, "-Through fourth optiion you can see the sales status");
delay(2);
outtextxy(60,280, "In the fifth option enter your daily other expenses");
delay(2);
outtextxy(60,310, "-In fifth option you can take monthWise individual account report");
delay(2);
outtextxy(60,340,"-In sixth option you can take reports of other expenses");
delay(2);
outtextxy(60,370, "Note-: Enter only valid data while you maintain this package");
delay(2);
outtextxy(60,400, "-And last option is Quit (Exit From Music Window)");
delay(2);
settextstyle(7,HORIZ_DIR,4);
outtextxy(80,420,"Press any key to continue");
getch();
}
/* Function for displaying a cassette information when required */
void cassettes::display(int t_cas_code)
{
fstream file;
file.open("cassettes.dat", ios::in);
file.seekg(0, ios::beg);
// Displays the record contents matching
// with t_cas_code from cassettes.dat data file
while (file.read((char *)this, sizeof(cassettes)))
{
if (t_cas_code == cas_code)
{
gotoxy(8, 5);
cout << "Account no. " << cas_code;
gotoxy(10, 8);
cout << "Name : ";
puts(Cass_name);
gotoxy(10, 9);
cout << "Comany Name : ";
puts(Comp_name);
gotoxy(10, 10);
cout << "Price : " << setw(15) // setwidth
<< setprecision(2) // set position of decimal point
<< setiosflags(ios::left) // set left justified output
<< setiosflags(ios::showpoint) // always show decimal point
<< setiosflags(ios::fixed) // set fixed notation for display
<< price;
break;
}
}
file.close();
}
/* Function to find is their records in cassette.dat file or not */
int cassettes::last_cas_code(void)
{
fstream file;
file.open("cassettes.dat", ios::in);
file.seekg(0, ios::beg);
int tcount = 0;
int count = 0;
// Founds the last account no.
while (file.read((char *)this, sizeof(cassettes)))
{
tcount = cas_code;
count = count + tcount;
}
file.close();
return count;
}
/* Function to find is their records in file person.dat or not */
int account::last_cas_code(void)
{
fstream file;
file.open("Person.dat", ios::in);
file.seekg(0, ios::beg);
int tcount = 0;
int count = 0;
// Founds the last account no.
while (file.read((char *)this, sizeof(account)))
{
tcount = cas_code;
count = count + tcount;
}
file.close();
return count;
}
/* Function for returning balance cassette.
This function returns the balance cassette on code wise
to know the current balance from "Tbal.dat" data file. */
int balance::give_balance(int t_cas_code)
{
fstream file;
file.open("Tbal.dat", ios::in);
file.seekg(0, ios::beg);
int t_balance = 0;
// Gives the last balance of an individual account
while (file.read((char *)this, sizeof(balance)))
{
if (file.eof())
break;
if (cas_code == t_cas_code)
{
t_balance = cas_bal;
break;
}
}
file.close();
return t_balance;
}
// Function to return the cassette price
float balance::return_price(int t_cas_code)
{
float t_price = 0.0;
fstream file;
file.open("Tbal.dat", ios::in);
file.seekg(0, ios::beg);
// Gives the last balance of an individual account
while (file.read((char *)this, sizeof(balance)))
{
if (file.eof())
break;
if (cas_code == t_cas_code)
{
t_price = price;
break;
}
}
file.close();
return t_price;
}
/* This function add_to_file() is used to create
new/fresh record in the data file */
void cassettes::add_to_file(int t_cas_code, char t_Cass_name[30],
char t_Comp_name[30], int t_cas, int tdd, int tmm, int tyy, float t_price)
{
cas_code = t_cas_code;
strcpy(Cass_name, t_Cass_name);
strcpy(Comp_name, t_Comp_name);
tot_cassette = t_cas;
dd = tdd;
mm = tmm;
yy = tyy;
price = t_price;
fstream file;
// Appends new account record with the price into cassettes.dat data file
file.open("cassettes.dat", ios::out|ios::app);
file.write((char *)this, sizeof(cassettes));
file.close();
}
/* This function add_to_file() is used to
create new/fresh record in the data file */
void balance::add_to_file(int t_cas_code,
int t_cas, int tdd, int tmm, int tyy, float t_price)
{
int bal = give_balance(t_cas_code);
if (bal > 0)
{
fstream file;
file.open("Tbal.dat", ios::in);
fstream temp;
temp.open("TEMP.dat", ios::out);
file.seekg(0,ios::beg);
// Uses a copy method to delete the cassette
// from cassette.dat data file
while (!file.eof())
{
file.read((char *)this, sizeof(balance));
if (file.eof())
break;
if (cas_code != t_cas_code)
temp.write((char *)this, sizeof(balance));
else
{
cas_code = t_cas_code;
cas_bal = t_cas + bal;
dd = tdd;
mm = tmm;
yy = tyy;
price = t_price;
temp.write((char *)this, sizeof(balance));
}
}
file.close();
temp.close();
file.open("Tbal.dat", ios::out);
temp.open("TEMP.dat", ios::in);
temp.seekg(0, ios::beg);
// Copy the TEMP.dat contents into cassette.dat data file
while (!temp.eof())
{
temp.read((char *)this, sizeof(balance));
if (temp.eof())
break;
file.write((char *)this, sizeof(balance));
}
file.close();
temp.close();
}
else
{
cas_code = t_cas_code;
cas_bal = t_cas;
dd = tdd;
mm = tmm;
yy = tyy;
price = t_price;
fstream file;
// Appends new account record with the
// price into cassettes.dat data file
file.open("Tbal.dat", ios::out|ios::app);
file.write((char *)this, sizeof(balance));
file.close();
}
}
// Function for deleting a account from cassettes.dat file
void cassettes::delete_cassette(int t_cas_code)
{
fstream file;
file.open("cassettes.dat", ios::in);
fstream temp;
temp.open("TEMP.dat", ios::out);
file.seekg(0,ios::beg);
// Uses a copy method to delete the account
// from cassette.dat data file
while (!file.eof())
{
file.read((char *)this, sizeof(cassettes));
if (file.eof())
break;
if (cas_code != t_cas_code)
temp.write((char *)this, sizeof(cassettes));
}
file.close();
temp.close();
file.open("cassettes.dat", ios::out);
temp.open("TEMP.dat", ios::in);
temp.seekg(0, ios::beg);
// Copy the TEMP.dat contents into cassette.dat data file
while (!temp.eof())
{
temp.read((char *)this, sizeof(cassettes));
if (temp.eof())
break;
if (cas_code != t_cas_code)
file.write((char *)this, sizeof(cassettes));
}
file.close();
temp.close();
}
// Function for deleting a balance from Tbal.dat file
void balance::delete_balance(int t_cas_code)
{
fstream file;
file.open("Tbal.dat", ios::in);
fstream temp;
temp.open("TEMP.dat", ios::out);
file.seekg(0,ios::beg);
// Uses a copy method to delete the account from Tbal.dat data file
while (!file.eof())
{
file.read((char *)this, sizeof(balance));
if (file.eof())
break;
if (cas_code != t_cas_code)
temp.write((char *)this, sizeof(balance));
}
file.close();
temp.close();
file.open("Tbal.dat", ios::out);
temp.open("TEMP.dat", ios::in);
temp.seekg(0, ios::beg);
// Copy the TEMP.dat contents into Tbal.dat data file
while (!temp.eof())
{
temp.read((char *)this, sizeof(balance));
if (temp.eof())
break;
if (cas_code != t_cas_code)
file.write((char *)this, sizeof(balance));
}
file.close();
temp.close();
}
/* Function for add an account details of
daily tranaction into person.dat file. */
void account::add_to_file(int t_cas_code, char tP_name[30],
char tP_address[30],int tNo_cass, int d1, int m1, int y1)
{
cas_code = t_cas_code;
strcpy(P_name, tP_name);
strcpy(P_address, tP_address);
No_cass = tNo_cass;
dd = d1;
mm = m1;
yy = y1;
fstream file;
// Appends the transaction record into person.dat data file
file.open("person.dat", ios::out|ios::app);
file.write((char *)this, sizeof(account));
file.close();
}
/* Function for deleting an account from person.dat file. */
void account::delete_account(int t_cas_code)
{
fstream file;
file.open("person.dat", ios::in); // Open to read records
fstream temp;
temp.open("TEMP.dat", ios::out); // Open to write records
file.seekg(0, ios::beg); // Positioned from begining of the file
// Uses the copy method for deleting the
// transaction record from person.dat data file
while (!file.eof())
{
file.read((char *)this, sizeof(account));
if (file.eof())
break;
if (cas_code != t_cas_code)
temp.write((char *)this, sizeof(account));
}
file.close();
temp.close();
file.open("person.dat", ios::out);
temp.open("TEMP.dat", ios::in);
temp.seekg(0, ios::beg);
// Uses copy method to transfer the record
// from TEMP.dat file to person.dat data file
while (!temp.eof())
{
temp.read((char *)this, sizeof(account));
if (temp.eof())
break;
if (cas_code != t_cas_code)
file.write((char *)this, sizeof(account));
}
file.close();
temp.close();
}
// Function for add an other expenses details in other.dat data file
void other::add_to_file(int tO_code, char tNat_Expen[30],
int d1, int m1, int y1, float tamount)
{
O_code = tO_code;
strcpy(Nat_Expen, tNat_Expen);
dd = d1;
mm = m1;
yy = y1;
amount = tamount;
fstream file;
// Appends the transaction record into other.dat data file
file.open("other.dat", ios::out|ios::app);
file.write((char *)this, sizeof(other));
file.close();
}
/* Function for displaying an account from "cassettes.dat". */
void cassettes::display_list(void)
{
clrscr();
int flag;
float tot_price = 0.0, tot_balance = 0.0;
fstream file;
gotoxy(25,2);
cout << "List of cassettes in Music Shop";
gotoxy(25, 3);
cout << "===============================";
int d1, m1, y1;
struct date d; // For extracting system date
getdate(&d);
d1 = d.da_day;
m1 = d.da_mon;
y1 = d.da_year;
gotoxy(62, 3);
cout << "Date: " << d1 << "/" << m1 << "/" << y1;
gotoxy(1, 4);
for (int j = 1; j <= 79; j++)
cout << "=";
gotoxy(1, 5);
cout << "Code #";
gotoxy(9, 5);
cout << "Cassette Name";
gotoxy(34, 5);
cout << "Company Name";
gotoxy(55, 5);
cout << "Qty";
gotoxy(61, 5);
cout << "Price";
gotoxy(72, 5);
cout << "Total";
gotoxy(1, 6);
for (j = 1; j <= 79; j++)
cout << "=";
file.open("cassettes.dat", ios::in);
file.seekg(0,ios::beg);
int row = 7;
// Reads all the records to display on the screen
while (file.read((char *)this, sizeof(cassettes)))
{
tot_price = 0.0;
flag = 0;
delay(2);
gotoxy(3, row);
cout << cas_code;
gotoxy(9, row);
puts(Cass_name);
gotoxy(34, row);
puts(Comp_name);
gotoxy(55, row);
cout << tot_cassette;
gotoxy(61, row);
cout << setw(15)
<< setprecision(2)
<< setiosflags(ios::left)
<< setiosflags(ios::showpoint)
<< setiosflags(ios::fixed)
<< price;
tot_price = tot_cassette * price;
gotoxy(72, row);
cout << setw(15)
<< setprecision(2)
<< setiosflags(ios::left)
<< setiosflags(ios::showpoint)
<< setiosflags(ios::fixed)
<< tot_price;
tot_balance = tot_balance + tot_price;
row++;
if (row > 23)
{
flag = 1;
row = 6;
gotoxy(4, 24);
cout << "Press any key to continue…. ";
getch();
clrscr();
}
}
gotoxy(1, row);
for (j = 1; j <= 79; j++)
cout << "=";
row++;
gotoxy(3, row);
cout << "Total price of Cassettes is : ";
gotoxy(72, row);
cout << setw(15)
<< setprecision(2)
<< setiosflags(ios::left)
<< setiosflags(ios::showpoint)
<< setiosflags(ios::fixed)
<< tot_balance;
file.close();
if (!flag)
{
gotoxy(4, 24);
cout << "Press any key to continue…";
getch();
}
getch();
}
/* Function for displaying an cassette sales on day wise */
void account::Display_sales(void)
{
clrscr();
int flag;
fstream file;
int tcas_code;
int xdd, xmm, xyy;
clrscr();
gotoxy(10, 8);
cout << "Enter the Cassette Code ";
gotoxy(10, 9);
cout <<"As 1 or 2 or 3 ";
gotoxy(10, 11);
cout << "Enter the date " ;
gotoxy(30, 9);
cin >> tcas_code;
gotoxy(30, 11);
cin >> xdd;
gotoxy(32, 11);
cout << "-";
gotoxy(33, 11);
cin >> xmm;
gotoxy(35, 11);
cout << "-";
gotoxy(36, 11);
cin >> xyy;
if (tcas_code < 1)
{
gotoxy(5, 23);
cout << "Your entry is not valid";
getch();
return;
}
else
if (tcas_code > 3)
{
gotoxy(5, 23);
cout << "Your entry is not valid";
getch();
return;
}
clrscr();
gotoxy(25, 2);
cout << "Sales Report in Music Shop";
gotoxy(25, 3);
cout << "==========================";
int d1, m1, y1;
struct date d; // For extracting system date
getdate(&d);
d1 = d.da_day;
m1 = d.da_mon;
y1 = d.da_year;
gotoxy(62, 3);
cout << "Date: " << d1 << "/" << m1 << "/" << y1;
gotoxy(1, 5);
for (int j = 1; j <= 79; j++)
cout << "=";
gotoxy(1, 6);
cout << "Code #";
gotoxy(9, 6);
cout << "Name";
gotoxy(34, 6);
cout << "Address";
gotoxy(55, 6);
cout << "Qty";
gotoxy(61, 6);
cout << "Date";
gotoxy(1, 7);
for (j = 1; j <= 79; j++)
cout << "=";
file.open("Person.dat", ios::in);
file.seekg(0,ios::beg);
int row = 8;
// Reads all the records to display on the screen
while (file.read((char *)this, sizeof(account)))
{
if ((tcas_code == cas_code) && (xmm == mm) && (xyy == yy))
{
flag = 0;
delay(2);
gotoxy(3, row);
cout << cas_code;
gotoxy(9, row);
puts(P_name);
gotoxy(34, row);
puts(P_address);
gotoxy(55, row);
cout << No_cass;
gotoxy(61, row);
cout << dd << "-" << mm << "-" << yy;
++row;
if (row > 23)
{
flag = 1;
row = 6;
gotoxy(4, 24);
cout << "Press any key to continue…. ";
getch();
clrscr();
}
}
}
++row;
gotoxy(1, row);
for (j = 1; j <= 79; j++)
cout << "=";
row++;
file.close();
if (!flag)
{
gotoxy(4, 24);
cout << "Press any key to continue…";
getch();
}
getch();
}
/* Function for displaying other expenses in shop */
void other::display_expense(void)
{
clrscr();
int flag;
fstream file;
/* The other expence code as :
1 - Salary to workers,
2 - Electricity bill
3 - Telephone bills
4 - Miscellaneous expenses */
int tO_code;
int xdd, xmm, xyy;
clrscr();
gotoxy(10, 8);
cout << "Enter the Expense Code ";
gotoxy(10, 9);
cout <<"1 Salary to Worker ";
gotoxy(10, 10);
cout <<"2 Electricity bill ";
gotoxy(10, 11);
cout <<"3 Telephone bill ";
gotoxy(10, 12);
cout <<"4 Miscellaneous ";
gotoxy(10, 13);
cout <<"Enter your Choice";
gotoxy(10, 14);
cout << "Enter the date " ;
gotoxy(30, 13);
cin >> tO_code;
gotoxy(30, 14);
cin >> xdd;
gotoxy(32, 14);
cout << "-";
gotoxy(33, 14);
cin >> xmm;
gotoxy(35, 14);
cout << "-";
gotoxy(36, 14);
cin >> xyy;
if (tO_code < 1)
{
gotoxy(5, 23);
cout << "Your entry is not valid";
getch();
return;
}
else
if (tO_code > 4)
{
gotoxy(5, 23);
cout << "Your entry is not valid";
getch();
return;
}
clrscr();
gotoxy(25, 2);
cout << "Other Expenses in Music Shop";
gotoxy(25, 3);
cout << "============================";
int d1, m1, y1;
struct date d; // For extracting system date
getdate(&d);
d1 = d.da_day;
m1 = d.da_mon;
y1 = d.da_year;
gotoxy(62, 3);
cout << "Date: " << d1 << "/" << m1 << "/" << y1;
gotoxy(1, 5);
for (int j = 1; j <= 79; j++)
cout << "=";
gotoxy(1, 6);
cout << "Code #";
gotoxy(9, 6);
cout << "Nature Expense";
gotoxy(34, 6);
cout << "Date";
gotoxy(55, 6);
cout << "Amount";
gotoxy(1, 7);
for (j = 1; j <= 79; j++)
cout << "=";
file.open("other.dat", ios::in);
file.seekg(0,ios::beg);
int row = 8;
// Reads all the records to display on the screen
while (file.read((char *)this, sizeof(other)))
{
if ((tO_code == O_code) && (xmm == mm) && (xyy == yy))
{
flag = 0;
delay(2);
gotoxy(3, row);
cout << O_code;
gotoxy(9, row);
puts(Nat_Expen);
gotoxy(34, row);
cout << dd << "-" << mm << "-" << yy;
gotoxy(55, row);
cout << setw(15)
<< setprecision(2)
<< setiosflags(ios::left)
<< setiosflags(ios::showpoint)
<< setiosflags(ios::fixed)
<< amount;
++row;
if (row > 23)
{
flag = 1;
row = 6;
gotoxy(4, 24);
cout << "Press any key to continue…. ";
getch();
clrscr();
}
}
}
++row;
gotoxy(1, row);
for (j = 1; j <= 79; j++)
cout << "=";
row++;
file.close();
if (!flag)
{
gotoxy(4, 24);
cout << "Press any key to continue…";
getch();
}
getch();
}
/* Function for clearing specified row and column. */
void account::clear(int col, int row)
{
for (int j = col; j <= 79; j++)
{
gotoxy(j, row);
cout << " ";
}
}
/* Function for return name of the account
holder from cassettes.dat. */
char *cassettes::return_name(int t_cas_code)
{
fstream file;
file.open("cassettes.dat", ios::in);
file.seekg(0, ios::beg);
char t_Cass_name[30];
// Return the name to display at report screen if found
while (file.read((char *)this, sizeof(cassettes)))
{
if (cas_code == t_cas_code)
{
strcpy(t_Cass_name, Cass_name);
break;
}
}
file.close();
return t_Cass_name;
}
/* Function for return Comp_name of the account holder from
cassettes.dat. */
char *cassettes::return_address(int t_cas_code)
{
fstream file;
file.open("cassettes.dat", ios::in);
file.seekg(0, ios::beg);
char t_Comp_name[30];
// Return the Comp_name to display at report screen if found
while (file.read((char *)this, sizeof(cassettes)))
{
if (cas_code == t_cas_code)
{
strcpy(t_Comp_name, Comp_name);
break;
}
}
file.close();
return t_Comp_name;
}
void balance::monthly_profit()
{
clrscr();
int flag;
fstream file;
gotoxy(25,1);
cout << "Monthly Profit Statement";
gotoxy(25, 2);
cout << "========================";
int d1, m1, y1;
struct date d; // For extracting system date
getdate(&d);
d1 = d.da_day;
m1 = d.da_mon;
y1 = d.da_year;
float T_bal = 0.0;
float G_bal = 0.0;
gotoxy(55, 3);
cout << "As on Date: " << d1 << "/" << m1 << "/" << y1;
gotoxy(1, 4);
for (int j = 1; j <= 79; j++)
cout << "=";
gotoxy(1, 5);
cout << "Code #";
gotoxy(15, 5);
cout << "Total Balance";
gotoxy(40, 5);
cout << "Date";
gotoxy(50, 5);
cout << "Unit Price";
gotoxy(65, 5);
cout << "Total Amount";
gotoxy(1, 6);
for (j = 1; j <= 79; j++)
cout << "=";
file.open("Tbal.dat", ios::in);
file.seekg(0,ios::beg);
int row = 7;
float cod1=0.0;
float cod2=0.0;
float cod3=0.0;
// Reads all the records to display on the screen
while (file.read((char *)this, sizeof(balance)))
{
flag = 0;
if (cas_code == 1)
cod1 = price;
else
if (cas_code == 2)
cod2 = price;
else
cod3 = price;
T_bal = cas_bal * price;
delay(2);
gotoxy(3, row);
cout << cas_code;
gotoxy(20, row);
cout << cas_bal;
gotoxy(40, row);
cout << dd <<"-"<< mm << "-" << yy;
gotoxy(53, row);
cout << setw(15)
<< setprecision(2)
<< setiosflags(ios::left)
<< setiosflags(ios::showpoint)
<< setiosflags(ios::fixed)
<< price;
G_bal = G_bal + T_bal;
gotoxy(68, row);
cout << setw(15)
<< setprecision(2)
<< setiosflags(ios::left)
<< setiosflags(ios::showpoint)
<< setiosflags(ios::fixed)
<< T_bal;
T_bal = 0.0;
row++;
if (row > 23)
{
flag = 1;
row = 6;
gotoxy(4, 24);
cout << "Press any key to continue…. ";
getch();
clrscr();
}
}
gotoxy(1, row);
for (j = 1; j <= 79; j++)
cout << "=";
row++;
gotoxy(50, row);
cout << "Grand Total";
gotoxy(68, row);
cout << setw(15)
<< setprecision(2)
<< setiosflags(ios::left)
<< setiosflags(ios::showpoint)
<< setiosflags(ios::fixed)
<< G_bal;
file.close();
row++;
float saltotal = 0.0;
account a;
saltotal = a.sales_status(m1, y1, cod1, cod2, cod3); // Will display
row++;
gotoxy(1, row);
for (j = 1; j <= 79; j++)
cout << "=";
row++;
gotoxy(5, row);
cout << "This month’s Sales Amount";
gotoxy(50, row);
cout << setw(15)
<< setprecision(2)
<< setiosflags(ios::left)
<< setiosflags(ios::showpoint)
<< setiosflags(ios::fixed)
<< saltotal;
float gother = 0.0;
other oth;
gother = oth.other_status(m1, y1);
row = row + 2;
gotoxy(5, row);
cout << "Other expenses ";
gotoxy(50, row);
cout << setw(15)
<< setprecision(2)
<< setiosflags(ios::left)
<< setiosflags(ios::showpoint)
<< setiosflags(ios::fixed)
<< gother;
row++;
gotoxy(1, row);
for (j = 1; j <= 79; j++)
cout << "=";
row++;
gotoxy(5, row);
cout << "Net Profit";
float net_bal = 0.0;
net_bal = (G_bal + saltotal)*gother;
gotoxy(50, row);
cout << setw(15)
<< setprecision(2)
<< setiosflags(ios::left)
<< setiosflags(ios::showpoint)
<< setiosflags(ios::fixed)
<< net_bal;
if (!flag)
{
gotoxy(4, 24);
cout << "Press any key to continue…";
getch();
}
getch();
}
// Function to find the sales total value
float account::sales_status(int m1, int y1, float cod1, float cod2,
float cod3)
{
fstream file;
file.open("Person.dat", ios::in);
file.seekg(0,ios::beg);
// Reads all the records to display on the screen
float ts = 0.0;
float gts = 0.0;
while (file.read((char *)this, sizeof(account)))
{
if ((m1 == mm) && (y1 == yy))
{
if (cas_code == 1)
ts = No_cass * cod1;
else
if (cas_code == 2)
ts = No_cass * cod2;
else
ts = No_cass * cod3;
gts = gts + ts;
ts = 0;
}
}
file.close();
return gts;
}
// Function to find the other status
float other::other_status(int m1, int y1)
{
fstream file;
file.open("other.dat", ios::in);
file.seekg(0,ios::beg);
// Reads all the records to display on the screen
float goth = 0.0;
while (file.read((char *)this, sizeof(other)))
{
if ((m1 == mm) && (y1 == yy))
{
goth = goth + amount;
}
}
file.close();
return goth;
}
// Function to display the balance cassette in music shop
void balance::balance_cassette(void)
{
clrscr();
int flag;
fstream file;
gotoxy(25,1);
cout << "List of Balance Cassettes";
gotoxy(25, 2);
cout << "=========================";
int d1, m1, y1;
struct date d; // For extracting system date
getdate(&d);
d1 = d.da_day;
m1 = d.da_mon;
y1 = d.da_year;
float T_bal = 0.0;
float G_bal = 0.0;
gotoxy(55, 3);
cout << "As on Date: " << d1 << "/" << m1 << "/" << y1;
gotoxy(1, 4);
for (int j = 1; j <= 79; j++)
cout << "=";
gotoxy(1, 5);
cout << "Code #";
gotoxy(15, 5);
cout << "Total Balance";
gotoxy(40, 5);
cout << "Date";
gotoxy(50, 5);
cout << "Unit Price";
gotoxy(65, 5);
cout << "Total Amount";
gotoxy(1, 6);
for (j = 1; j <= 79; j++)
cout << "=";
file.open("Tbal.dat", ios::in);
file.seekg(0,ios::beg);
int row = 7;
// Reads all the records to display on the screen
while (file.read((char *)this, sizeof(balance)))
{
flag = 0;
T_bal = cas_bal * price;
delay(2);
gotoxy(3, row);
cout << cas_code;
gotoxy(20, row);
cout << cas_bal;
gotoxy(40, row);
cout << dd <<"-"<< mm << "-" << yy;
gotoxy(53, row);
cout << setw(15)
<< setprecision(2)
<< setiosflags(ios::left)
<< setiosflags(ios::showpoint)
<< setiosflags(ios::fixed)
<< price;
G_bal = G_bal + T_bal;
gotoxy(68, row);
cout << setw(15)
<< setprecision(2)
<< setiosflags(ios::left)
<< setiosflags(ios::showpoint)
<< setiosflags(ios::fixed)
<< T_bal;
T_bal = 0.0;
row++;
if (row > 23)
{
flag = 1;
row = 6;
gotoxy(4, 24);
cout << "Press any key to continue…. ";
getch();
clrscr();
}
}
gotoxy(1, row);
for (j = 1; j <= 79; j++)
cout << "=";
row++;
gotoxy(50, row);
cout << "Grand Total";
gotoxy(68, row);
cout << setw(15)
<< setprecision(2)
<< setiosflags(ios::left)
<< setiosflags(ios::showpoint)
<< setiosflags(ios::fixed)
<< G_bal;
file.close();
if (!flag)
{
gotoxy(4, 24);
cout << "Press any key to continue…";
getch();
}
getch();
}
/* Function for recording the new cassettes in shop */
void cassettes::new_cassettes(void)
{
char ch;
int i, valid;
clrscr();
// Declaring the class objects for different operations with
// member functions
account a;
balance bal;
cassettes ini;
shape s;
s.box(2, 1, 79, 25, 218);
s.box(25, 2, 54, 4, 219);
gotoxy(65, 2);
cout << "<0>=Exit";
gotoxy(3,3);
for (i = 1; i<= 76; i++)
cprintf(" ");
textbackground(BLACK);
textcolor(BLACK+BLINK);
textbackground(WHITE);
gotoxy(30, 3);
cprintf("Add New Cassette");
textcolor(LIGHTGRAY);
textbackground(BLACK);
int d1, m1, y1; // Declare the variable for purchase date of cassette
struct date d; // For extracting system date
getdate(&d); // Extract the system.date
d1 = d.da_day;
m1 = d.da_mon;
y1 = d.da_year;
// Declaring the temporary variables for cassette entry
char c_code[10];
int t_cas_code;
char t_Cass_name[30];
char t_Comp_name[30];
int t_cas;
int tdd, tmm, tyy;
float t_price;
t_cas_code = ini.last_cas_code();
// Appends and deletes a false record
// to create primary position in data files
if (t_cas_code == 0)
{
ini.add_to_file(t_cas_code, "abc", "xyz", 1, 1, 1, 1, 1.1);
ini.delete_cassette(t_cas_code);
bal.add_to_file(t_cas_code, 0, 0, 0, 0, 0.0);
bal.delete_balance(t_cas_code);
}
gotoxy(4, 6);
cout << "Date: " << d1 <<"/"<< m1 <<"/"<< y1;
gotoxy(5, 8);
cout << "Cassette Code # ";
gotoxy(5, 10);
cout << "Cassette Name : ";
gotoxy(5, 12);
cout << "Company Name : ";
gotoxy(5, 14);
cout << "Total Cassettes: ";
gotoxy(5, 16);
cout << "Individual Cassette price : ";
gotoxy(5, 18);
cout << "Enter the Date ";
// Steps to enter the cassette code either 1 – 2 – 3.
do
{
a.clear(22, 8);
a.clear(5, 23); // Clears the buttom message
gotoxy(5, 23);
cout << "Enter cassettes Code either 1/2/3 ";
valid = 1;
gotoxy(22, 8);
gets(c_code);
t_cas_code = atoi(c_code);
if (t_cas_code <= 0)
{
valid = 0;
a.clear(5, 23);
gotoxy(5, 23);
cprintf("IT Should not other than 1, 2, 3");
getch();
gotoxy(5, 23);
cout << "Enter cassettes Code either 1/2/3 ";
}
} while (!valid);
a.clear(5, 23);
// Steps to enter the Cassette name
do
{
a.clear(22, 10);
a.clear(5, 23);
gotoxy(5, 23);
cout << "Enter Name of the Cassette";
valid = 1;
gotoxy(22, 10);
gets(t_Cass_name);
strupr(t_Cass_name);
if (t_Cass_name[0] =='0')
return;
if (strlen(t_Cass_name) == 0 || strlen(t_Cass_name) > 25)
{
valid = 0;
gotoxy(5, 23);
cprintf("7Cassette Name should not greater than 25");
getch();
}
}while (!valid);
a.clear(5, 23);
// Steps to enter company name
do
{
a.clear(22, 12);
a.clear(5, 23);
gotoxy(5, 23);
cout << "Enter Company Name ";
valid = 1;
gotoxy(22, 12);
gets(t_Comp_name);
strupr(t_Comp_name);
if (t_Comp_name[0] =='0')
return;
if (strlen(t_Comp_name) == 0 || strlen(t_Comp_name) > 25)
{
valid = 0;
gotoxy(5, 23);
cprintf("7Company Name should not greater than 25");
getch();
}
}while (!valid);
a.clear(5, 23);
// Steps to enter the total cassettes purchased
do
{
a.clear(22, 14);
a.clear(5, 23);
gotoxy(5, 23);
cout << "Enter Total number of cassettes purchased";
valid = 1;
gotoxy(22, 14);
gets(c_code);
t_cas = atoi(c_code);
if (t_cas == 0)
{
valid = 0;
a.clear(5, 23);
gotoxy(5, 23);
cprintf("Enter valid cassette number");
getch();
gotoxy(5, 23);
cout << "Enter Total number of cassettes purchased";
}
}while (!valid);
a.clear(5, 23);
// Steps to enter the cassette/price
do
{
a.clear(35, 16);
a.clear(5, 23);
gotoxy(5, 23);
cout << "Enter individual cassette price";
valid = 1;
gotoxy(35, 16);
gets(c_code);
t_price = atof(c_code);
if (t_price <= 0)
{
valid = 0;
gotoxy(5, 23);
cprintf("Enter valid price for cassette");
getch();
}
}while (!valid);
a.clear(5, 23);
// Steps to enter the purchase date
a.clear(22, 18);
a.clear(5, 23);
gotoxy(5, 23);
cout << "Enter date on which the cassette is purchase";
valid = 1;
gotoxy(22, 18);
cin >> tdd;
gotoxy(25, 18);
cout << "-";
gotoxy(26, 18);
cin >> tmm;
gotoxy(28, 18);
cout << "-";
gotoxy(29, 18);
cin >> tyy;
a.clear(5, 23);
do
{
a.clear(5, 20);
valid = 1;
gotoxy(5, 20);
cout << "Do you want to save the record <Y/N>: ";
ch = getche();
if (ch =='0')
return;
ch = toupper(ch);
}while (ch !='N' && ch !='Y');
if (ch =='N')
return;
// Appends the records contents into
// both cassettes.dat and person.dat data files
ini.add_to_file(t_cas_code, t_Cass_name, t_Comp_name,
t_cas, tdd, tmm, tyy, t_price);
bal.add_to_file(t_cas_code, t_cas, tdd, tmm, tyy, t_price);
}
/* This function update_balance() is used to update the
balance cassette in Tbal.dat data file */
void balance::Update_balance(int t_cas_code,
int t_cas, int tdd, int tmm, int tyy, float t_price)
{
int bal = give_balance(t_cas_code);
if (bal > 0)
{
fstream file;
file.open("Tbal.dat", ios::in);
fstream temp;
temp.open("TEMP.dat", ios::out);
file.seekg(0,ios::beg);
// Uses a copy method to delete the account from Tbal.dat data file
while (!file.eof())
{
file.read((char *)this, sizeof(balance));
if (file.eof())
break;
if (cas_code != t_cas_code)
temp.write((char *)this, sizeof(balance));
else
{
cas_code = t_cas_code;
cas_bal = bal*t_cas;
dd = tdd;
mm = tmm;
yy = tyy;
price = t_price;
temp.write((char *)this, sizeof(balance));
}
}
file.close();
temp.close();
file.open("Tbal.dat", ios::out);
temp.open("TEMP.dat", ios::in);
temp.seekg(0, ios::beg);
// Copy the TEMP.dat contents into Tbal.dat data file
while (!temp.eof())
{
temp.read((char *)this, sizeof(balance));
if (temp.eof())
break;
file.write((char *)this, sizeof(balance));
}
file.close();
temp.close();
}
else
{
cas_code = t_cas_code;
cas_bal = t_cas;
dd = tdd;
mm = tmm;
yy = tyy;
price = t_price;
fstream file;
// Appends new account record with the price
// into cassettes.dat data file
file.open("Tbal.dat", ios::out|ios::app);
file.write((char *)this, sizeof(balance));
file.close();
}
}
/* Function for creating new account for new customer. */
void account::new_account(void)
{
char ch;
int i, valid;
clrscr();
balance bal;
shape s;
s.box(2, 1, 79, 25, 218);
s.box(25, 2, 54, 4, 219);
gotoxy(65, 2);
cout << "<0>=Exit";
gotoxy(3,3);
for (i = 1; i<= 76; i++)
cprintf(" ");
textbackground(BLACK);
textcolor(BLACK+BLINK);
textbackground(WHITE);
gotoxy(30, 3);
cprintf("Sales of Cassettes");
textcolor(LIGHTGRAY);
textbackground(BLACK);
int d1, m1, y1;
struct date d; // For extracting system date
getdate(&d);
d1 = d.da_day;
m1 = d.da_mon;
y1 = d.da_year;
int t_cas_code;
int C_bal = 0;
float t_price;
char c_code[2];
char tP_name[30]; // Person Name
char tP_address[30]; // Person Address
int tNo_cass; // Number of cassette
t_cas_code = last_cas_code();
// Appends and deletes a false record to create
// primary position in data files
if (t_cas_code == 0)
{
add_to_file(t_cas_code, "xxxx", "xxxxx", 1, 1, 1, 1);
delete_account(t_cas_code);
}
gotoxy(5, 6);
cout << "Date: " << d1 <<"/"<< m1 <<"/"<< y1;
gotoxy(5, 8);
cout << "Cassette Code ";
gotoxy(5, 10);
cout << "Name of Person : ";
gotoxy(5, 12);
cout << "Address : ";
gotoxy(5, 14);
cout << "Total Cassette : ";
// Steps to enter the cassette code either 1 – 2 – 3.
do
{
clear(22, 8);
clear(5, 23); // Clears the buttom message
gotoxy(5, 23);
cout << "Enter cassettes Code either 1/2/3 ";
valid = 1;
gotoxy(22, 8);
gets(c_code);
t_cas_code = atoi(c_code);
if (t_cas_code <= 0)
{
valid = 0;
clear(5, 23);
gotoxy(5, 23);
cprintf("7Should not other than 1, 2, 3");
getch();
gotoxy(5, 23);
cout << "Enter cassettes Code either 1/2/3 ";
}
else
{
C_bal = bal.give_balance(t_cas_code);
t_price = bal.return_price(t_cas_code);
if (C_bal > 0)
{
gotoxy(40, 8);
cout << "Total cassettes in Shop : " << C_bal;
break;
}
else
{
cout << "There is no cassette in shop";
return;
}
}
} while (!valid);
clear(5, 23);
// Steps to enter the name of the purchase person
do
{
clear(22, 10);
clear(5, 23);
gotoxy(5, 23);
cout << "Enter Name of the Person";
valid = 1;
gotoxy(22, 10);
gets(tP_name);
strupr(tP_name);
if (tP_name[0] =='0')
return;
if (strlen(tP_name) == 0 || strlen(tP_name) > 25)
{
valid = 0;
gotoxy(5, 23);
cprintf("7Name should not greater than 25");
getch();
clear(5, 23);
}
}while (!valid);
clear(5, 23);
// Steps to enter the address of the purchase person
do
{
clear(22, 12);
clear(5, 23);
gotoxy(5, 23);
cout << "Enter Name of the Person";
valid = 1;
gotoxy(22, 12);
gets(tP_address);
strupr(tP_address);
if (tP_address[0] =='0')
return;
if (strlen(tP_address) == 0 || strlen(tP_address) > 25)
{
valid = 0;
gotoxy(5, 23);
cprintf("7Address should not greater than 25");
getch();
clear(5, 23);
}
}while (!valid);
clear(5, 23);
do
{
clear(22, 14);
clear(5, 23);
gotoxy(5, 23);
cout << "No. of cassette ";
valid = 1;
gotoxy(22, 14);
cin >> tNo_cass;
if (tNo_cass > C_bal)
{
valid = 0;
gotoxy(5, 23);
cprintf("The availability of cassette is not sufficient");
getch();
}
}while (!valid);
clear(5, 23);
do
{
clear(5, 17);
valid = 1;
gotoxy(5, 17);
cout << "Do you want to save the record <Y/N>: ";
ch = getche();
if (ch =='0')
return;
ch = toupper(ch);
}while (ch !='N' && ch !='Y');
if (ch =='N')
return;
// Updates the new balance after deducting the current sales
// Appends the records contents into both person.dat data files
add_to_file(t_cas_code, tP_name, tP_address, tNo_cass, d1, m1, y1);
bal.Update_balance(t_cas_code, tNo_cass, d1, m1, y1, t_price);
}
/* Function for enter the other expences in other.dat data file. */
void other::Expense_other(void)
{
char ch;
int i, valid;
clrscr();
account a;
shape s;
s.box(2, 1, 79, 25, 218);
s.box(25, 2, 54, 4, 219);
gotoxy(65, 2);
cout << "<0>=Exit";
gotoxy(3,3);
for (i = 1; i<= 76; i++)
cprintf(" ");
textbackground(BLACK);
textcolor(BLACK+BLINK);
textbackground(WHITE);
gotoxy(30, 3);
cprintf("Other Expence in Shop");
textcolor(LIGHTGRAY);
textbackground(BLACK);
int d1, m1, y1;
struct date d; // For extracting system date
getdate(&d);
d1 = d.da_day;
m1 = d.da_mon;
y1 = d.da_year;
char c_code[2];
int tO_code; // Other expence code
char tNat_Expen[30]; // Nature of expense description
float tamount; // Expense amount
gotoxy(5, 6);
cout << "Date: " << d1 <<"/"<< m1 <<"/"<< y1;
gotoxy(5, 8);
cout << "Expense Code ";
gotoxy(5, 10);
cout << "Nature of Expense : ";
gotoxy(5, 12);
cout << "Amount : ";
// Steps to enter the other expense code
do
{
a.clear(22, 8);
a.clear(5, 23); // Clears the buttom message
gotoxy(5, 23);
cout << "Enter Expense code Code either 1/2/3/4 ";
valid = 1;
gotoxy(22, 8);
gets(c_code);
tO_code = atoi(c_code);
if (tO_code <= 0)
{
valid = 0;
a.clear(5, 23);
gotoxy(5, 23);
cprintf("7Expence code should not other than 1/2/3/4");
getch();
gotoxy(5, 23);
cout << "Enter other expense Codes either 1/2/3/4 ";
}
} while (!valid);
a.clear(5, 23);
// Steps to enter the nature of expense
do
{
a.clear(22, 10);
a.clear(5, 23);
gotoxy(5, 23);
cout << "Enter the Nature of expense";
valid = 1;
gotoxy(22, 10);
gets(tNat_Expen);
strupr(tNat_Expen);
if (tNat_Expen[0] =='0')
return;
if (strlen(tNat_Expen) == 0 || strlen(tNat_Expen) > 25)
{
valid = 0;
gotoxy(5, 23);
cprintf("7Nature of expense not greater than 25");
getch();
a.clear(5, 23);
}
}while (!valid);
a.clear(5, 23);
gotoxy(22, 12);
cin >> tamount;
do
{
a.clear(5, 17);
valid = 1;
gotoxy(5, 17);
cout << "Do you want to save the record <Y/N>: ";
ch = getche();
if (ch == ’0′)
return;
ch = toupper(ch);
}while (ch != ‘N’ && ch != ‘Y’);
if (ch == ‘N’)
return;
// Appends the records contents into both person.dat data files
if (tamount > 0)
add_to_file(tO_code, tNat_Expen, d1, m1, y1, tamount);
}
/* Function for returning the record no. for updating price */
int cassettes::recordno(int t_cas_code)
{
fstream file;
file.open("cassettes.dat", ios::in);
file.seekg(0, ios::beg);
int count = 0;
// Finds the record position in cassettes.dat data file
while (file.read((char *)this, sizeof(cassettes)))
{
count++;
if (t_cas_code == cas_code)
break;
}
file.close();
return count;
}
/* Function for closing any account after inputing account number. */
void account::close_account(void)
{
clrscr();
char t_acc[10];
int t, t_cas_code;
gotoxy(71, 1);
cout << "<0>=Exit";
gotoxy(5, 5);
cout << "Enter the account no. ";
gets(t_acc);
t = atoi(t_acc);
t_cas_code = t;
if (t_cas_code == 0)
return;
clrscr();
cassettes ini;
balance bal;
if (!bal.give_balance(t_cas_code))
{
gotoxy(5, 5);
cout << "Account not found ";
getch();
return;
}
gotoxy(71, 1);
cout << "<0>=Exit";
gotoxy(3, 3);
textbackground(WHITE);
for (int i = 1; i <= 76; i++)
cprintf(" ");
textbackground(BLACK);
textcolor(BLACK+BLINK);
textbackground(WHITE);
gotoxy(30, 3);
cprintf("Close account screen");
textcolor(LIGHTGRAY);
textbackground(BLACK);
int d1, m1, y1;
struct date d;
getdate(&d);
d1 = d.da_day;
m1 = d.da_mon;
y1 = d.da_year;
gotoxy(5, 6);
cout << "Date: " << d1 << "/" << m1 << "/" << y1;
char ch;
ini. display(t_cas_code);
do
{
clear(5, 15);
gotoxy(5, 15);
cout << "Close this account <y/n?? ";
ch = getche();
if (ch == ’0′)
return;
ch = toupper(ch);
}while (ch != ‘N’ && ch != ‘Y’);
if (ch == ‘N’)
return;
// Function calls to delete the existing account no.
ini.delete_cassette(t_cas_code);
delete_account(t_cas_code);
gotoxy(5, 20);
cout << "Account Deleted";
gotoxy(5, 23);
cout << "Press any key to continue…";
getch();
}
// Main program logic which control the class members and member functions.
void main(void)
{
main_menu m_menu;
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "c:\turboc3\bgi");
m_menu.help();
closegraph();
m_menu.control_menu();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.