Saturday, August 23, 2008

Thursday, August 21, 2008

Saturday, August 2, 2008

Date & Time Management in C:


Introduction

I will discuss on Date & Time Management Functions of C. Though if someone is only interested about getting the time and date, then it can be done by some trivial function but the goal of this detail discussion is understanding the bios as well as decreasing the abstraction. I had to sum up this data when I was working on an algorithm. Hopefully some of you will find this useful.

Here you will find explanations of each run-time library functions that supports the capture, conversion and display of time, from which all date and date measures are derived. The examples provided here demonstrate the proper use of these functions and detail the relationship that exist between the global variable daylight, timezone and tzname[], and environment string TZ.


Computer Time

All system date and time measures available under DOS are derived from either the 8253 timer (oscillator) chip, or a real-time (battery-supported) if one is installed and operating. The 8253 timer oscillates at 1,193,180 Hz with a built-in divisor of 65,536 and emits a BIOS interrupt 0x08 18.2 times per second, or about every 0.055 seconds.


Universal Date & Time

To maintain compatibility with UNIX, several DOS run-time library functions and data structures are available that permit the underlying DOS clock device driver measures of time to support universal (GMT) time as well as standard and daylight saving time.

The non-Standard DOS-specific global variables (timezone, daylight and tzname[]) and environment string (TZ=) are used to implement universal GMT based time and to provide a complement of UNIX-compatible functions with within the DOS. These global variables assume default values based on an assumed TZ=string setting of
TZ=PST8PDT
where
PST : A three character standard time zone abbreviation –
PST – Pacific Standard Time
MST – Mountain Standard Time
CST – Central Standard Time
EST – Eastern Standard Time
8 : The number of whole hours, measured from the prime meridian; a positive value of 0 to 12 if west longitude, and 0 to –12 if east longitude.
PDT : A three-character abbreviation used to designate dayligyt saving time is in effect for this time zone, it stands for Pacific Daylight Time it is also can be of 4 types PDT, MDT, CDT, EDT


timezone : the number of seconds difference between the local time zone and the GMT is as follows :
PST : 8 hrs
MST : 7 hrs
CST : 6 hrs
EST : 5 hrs
daylight : A flag that is set to zero if daylight saving time is not in effect otherwise 1
tzname[] : Contains the three-character daylight saving time descriptive string or a null string
function tzset() sets these values


Terminology & Data Types

Ticks
Whenever we speak of ticks, we are referring to the count of interrupts that are generated by the 8285 timer chip or real-time clock, and accumulated by the BIOS. For example if you have a tick count of 66,733, using the BIOS constant, the measure of time would be calculated as follows

1-hour : 66733-(1*((1,193,180/65,536)*60*60))=1190

Standard C defines two data-object types, clock_t and time_t, for representing data in and one data structure, tm.


clock_t
The standard C clock_t type is defined as
typedef long clock_t;
and represents the elapsed process time in seconds divided by the object-like macro CLK_TCK or CLOCKS_PER_SEC which is set to 1000 for DOS in


time_t
It is defined as
typedef long time_t;
A time_t type represents the number of elapsed seconds since midnight relative to prime meridian (GMT) January 1, 1970, for compatibility with UNIX, whereas all DOS dates are originated at January 1, 1980.


struct tm
This is a special structure used in date time management functions. Template of this structure:

Code:

struct tm {

int tm_sec; //seconds after the minute

int tm_min; //minutes after the hour

int tm_hour; //hours since midnight

int tm_mday; //day of the month

int tm_mon; //months since January

int tm_year; //years since 1900

int tm_wday; //days since Sunday

int tm_yday; //days since January 1

int tm_isdst; //daylight saving time flag

};

Microsoft C defines the dosdate_t and dostime_t data structure in , the timeb data structure in .

The structure template is given by :


Code:

struct dosdate_t {

unsigned char hour;

unsigned char minute;

unsigned char second;

unsigned char hsecond;

};

Code:

struct dostime_t{

unsigned char day;

unsigned char month;

unsigned int year;

unsigned char dayofweek;

};

Code:

struct timeb {

time_t time; //GMT in seconds

unsigned short millitm; //millisecond fraction

short timezone; //GMT local time in minute

short dstflag; //=1 if DST in effect

};

Run-Time Library Functions For Date & Time Management

Here is a list of library functions that are used for Date and Time Management in C :
asctime() biostime() _bios_timeofday() ctime() difftime()
_dos_getdate() _dos_gettime() _dos_settime() _ dos_setdate()
dostounix() ftime() getdate() gettime() gmtime()localtime() mktime() stime() _strdate() _strtime()strftime() time() TDate(class) TTime(class) tzset() unixtodos()



Here are the example of few -
asctime() - convert the standard tm structure to a string

Spicification
#include
char *asctime(const struct tm *pointer)
Arguments
pointer : pointer to the Standard C date and time structure, tm
Return Value
A pointer to a static character string that is always 26 characters and in the format
Sun Jul 06 09:30:50 1980\n\0
Example

Code: C

#include

#include

#include

int main()

{

struct tm t;

char str[80];

/* Sample loading of tm structure */

t.tm_sec=1; //seconds

t.tm_min=30; //minutes

t.tm_hour=9; //hour

t.tm_mday=22; //day of the month

t.tm_mon=11; //month

t.tm_year=56; //year does not include century

t.tm_wday=4; //day of the week

t.tm_yday=0; //does not show in asctime

t.tm_isdst=0; //is Daylight SavTime, does not show in asctime

/* converts structure to null terminates string */

strcpy(str, asctime(&t));

printf("%s\n",str);

return 0;

}

biostime() - Reads or set the BIOS timer (interrupt 0x1A)

Specification
#include
long biostime (int cmd, long newtime);
Arguments & Return Value
If cmd equals 0, biostime returns the current value of the timer. If cmd=1, the timer is set to the long value in newtime.
Example

Code: c

#include

#include

#include

#include

int main(void)

{

long bios_time;

clrscr();

printf("The number of clock ticks since midnight : \n");

printf("The number of seconds since midnight : \n");

printf("The number of minutes since midnight : \n");

printf("The number of hours since midnight : \n");

printf("Press any key to stop....");

while(!kbhit())

{

bios_time=biostime(0,0L);

gotoxy(50,1);

printf("%lu",bios_time);

gotoxy(50,2);

printf("%.4f",bios_time/_BIOS_CLK_TCK);

gotoxy(50,3);

printf("%.4f",bios_time/_BIOS_CLK_TCK/60);

gotoxy(50,4);

printf("%.4f",bios_time/_BIOS_CLK_TCK/3600);

}

return 0;

}

clock() - Determines processor time

Specification
#include
clock_t clock(void);

Return Value
Clock can be used to determine the time interval between two events. On success clock returns the processor time elapsed since the beginning of the program invocation. On error clock returns –1.
Example

Code: c

#include

#include

#include

#include

void main(void)

{

long int bios_start,bios_end;

float elap_bios,elap_clock;

clock_t clock_start,clock_end;

_bios_timeofday(_TIME_GETCLOCK,&bios_start);

clock_start=clock();

printf("\n_bios = %ld\t\tclcok = %ld",bios_start,clock_start);

clock_end=clock();

_bios_timeofday(_TIME_GETCLOCK,&bios_end);

printf("\n_bios = %ld\t\tclock = %ld",bios_end,clock_end);

elap_bios=(bios_end-bios_start)/18.2F;

elap_clock=(clock_end-clock_start)/(float) CLK_TCK;

printf("\nelap_bios = %f sec\nelap_clock = %f sec",elap_bios,elap_clock);

exit(0);

}

_bios_timeofday() - Get/set the system timer clock ticks

Specification
#include
unsigned _bios_timeofday(unsigned service, long *ticks)
Arguments
service : use either the _TIME_GETCLOCK or _TIME_SETCLOCK object like macros found in
ticks : pointer to a long that is used either to return the clock tick count or to serve as the value to set the clock tick count.
Return Value
When the _TIME_GETCLOCK service is used, a value of 0 is returned if midnight has been passed since the last get or set time was performed; otherwise a value pf 1 is returned.
When _TIME_SETCLOCK service is used, there is no return value.
Example See previous example


ctime() - converts date and time to a string

Specification
#include
char *ctime(const time_t *timer);
Arguments
timer : pointer to a time value in time_t format that was acquired using function time().
Return Value
ctime returns a pointer to the character string containing the date and time.
Example

Code: c

#include

#include

int main(void)

{

time_t t;

time(&t);

printf("Todays date and time is : %s",ctime(&t));

return 0;

}

time() - get system time in time_t format

Specification
#include
time_t time(time_t *timer);
Arguments
timer : pointer to a time_t type variable that is assigned the number of seconds elapsed since 00:00:00 GMT January 1, 1970.If timer is null no value is stored.
Return Value
The elapsed time in seconds identical to that placed in timer.
Example
See previous example

References

C Encyclopedia, Compiler Help and various websites (credits to google)

Wednesday, July 30, 2008

Date & Time Management System using C

Introduction
It’s my first post here. I will discuss on Date & Time Management Functions of C. Though if someone is only interested about getting the time and date, then it can be done by some trivial function but the goal of this detail discussion is understanding the bios as well as decreasing the abstraction. I had to sum up this data when I was working on an algorithm. Hopefully some of you will find this useful.
Here you will find explanations of each run-time library functions that supports the capture, conversion and display of time, from which all date and date measures are derived. The examples provided here demonstrate the proper use of these functions and detail the relationship that exist between the global variable daylight, timezone and tzname[], and environment string TZ.
Computer Time
All system date and time measures available under DOS are derived from either the 8253 timer (oscillator) chip, or a real-time (battery-supported) if one is installed and operating. The 8253 timer oscillates at 1,193,180 Hz with a built-in divisor of 65,536 and emits a BIOS interrupt 0x08 18.2 times per second, or about every 0.055 seconds.
Universal Date & Time
To maintain compatibility with UNIX, several DOS run-time library functions and data structures are available that permit the underlying DOS clock device driver measures of time to support universal (GMT) time as well as standard and daylight saving time.
The non-Standard DOS-specific global variables (timezone, daylight and tzname[]) and environment string (TZ=) are used to implement universal GMT based time and to provide a complement of UNIX-compatible functions with within the DOS. These global variables assume default values based on an assumed TZ=string setting of TZ=PST8PDTwhere PST : A three character standard time zone abbreviation –PST – Pacific Standard Time MST – Mountain Standard Time CST – Central Standard Time EST – Eastern Standard Time 8 : The number of whole hours, measured from the prime meridian; a positive value of 0 to 12 if west longitude, and 0 to –12 if east longitude.PDT : A three-character abbreviation used to designate dayligyt saving time is in effect for this time zone, it stands for Pacific Daylight Time it is also can be of 4 types PDT, MDT, CDT, EDT
timezone : the number of seconds difference between the local time zone and the GMT is as follows : PST : 8 hrsMST : 7 hrsCST : 6 hrsEST : 5 hrsdaylight : A flag that is set to zero if daylight saving time is not in effect otherwise 1tzname[] : Contains the three-character daylight saving time descriptive string or a null stringfunction tzset() sets these values
Terminology & Data Types
TicksWhenever we speak of ticks, we are referring to the count of interrupts that are generated by the 8285 timer chip or real-time clock, and accumulated by the BIOS. For example if you have a tick count of 66,733, using the BIOS constant, the measure of time would be calculated as follows
1-hour : 66733-(1*((1,193,180/65,536)*60*60))=1190
Standard C defines two data-object types, clock_t and time_t, for representing data in and one data structure, tm.
clock_tThe standard C clock_t type is defined as typedef long clock_t;and represents the elapsed process time in seconds divided by the object-like macro CLK_TCK or CLOCKS_PER_SEC which is set to 1000 for DOS in
time_t It is defined as typedef long time_t;A time_t type represents the number of elapsed seconds since midnight relative to prime meridian (GMT) January 1, 1970, for compatibility with UNIX, whereas all DOS dates are originated at January 1, 1980.
struct tmThis is a special structure used in date time management functions. Template of this structure :
Code: struct tm { int tm_sec; //seconds after the minute int tm_min; //minutes after the hour int tm_hour; //hours since midnight int tm_mday; //day of the month int tm_mon; //months since January int tm_year; //years since 1900 int tm_wday; //days since Sunday int tm_yday; //days since January 1 int tm_isdst; //daylight saving time flag};Microsoft C defines the dosdate_t and dostime_t data structure in , the timeb data structure in .
The structure template is given by :
Code: struct dosdate_t { unsigned char hour; unsigned char minute; unsigned char second; unsigned char hsecond;};Code: struct dostime_t{ unsigned char day; unsigned char month; unsigned int year; unsigned char dayofweek;};Code: struct timeb { time_t time; //GMT in seconds unsigned short millitm; //millisecond fraction short timezone; //GMT local time in minute short dstflag; //=1 if DST in effect};Run-Time Library Functions For Date & Time Management
Here is a list of library functions that are used for Date and Time Management in C :asctime() biostime() _bios_timeofday() ctime() difftime()_dos_getdate() _dos_gettime() _dos_settime() _dos_setdate()dostounix() ftime() getdate() gettime() gmtime()localtime() mktime() stime() _strdate() _strtime()strftime() time() TDate(class) TTime(class) tzset()unixtodos()

Here are the example of few - asctime() - convert the standard tm structure to a string
Spicification #includechar *asctime(const struct tm *pointer)Argumentspointer : pointer to the Standard C date and time structure, tmReturn Value A pointer to a static character string that is always 26 characters and in the formatSun Jul 06 09:30:50 1980\n\0Example Code: C
#include#include#includeint main(){ struct tm t; char str[80]; /* Sample loading of tm structure */ t.tm_sec=1; //seconds t.tm_min=30; //minutes t.tm_hour=9; //hour t.tm_mday=22; //day of the month t.tm_mon=11; //month t.tm_year=56; //year does not include century t.tm_wday=4; //day of the week t.tm_yday=0; //does not show in asctime t.tm_isdst=0; //is Daylight SavTime, does not show in asctime /* converts structure to null terminates string */ strcpy(str, asctime(&t)); printf("%s\n",str);
return 0;}biostime() - Reads or set the BIOS timer (interrupt 0x1A)
Specification#includelong biostime (int cmd, long newtime);Arguments & Return ValueIf cmd equals 0, biostime returns the current value of the timer. If cmd=1, the timer is set to the long value in newtime.Example Code: c
#include#include#include#include
int main(void){ long bios_time; clrscr(); printf("The number of clock ticks since midnight : \n"); printf("The number of seconds since midnight : \n"); printf("The number of minutes since midnight : \n"); printf("The number of hours since midnight : \n"); printf("Press any key to stop...."); while(!kbhit()) { bios_time=biostime(0,0L);
gotoxy(50,1); printf("%lu",bios_time);
gotoxy(50,2); printf("%.4f",bios_time/_BIOS_CLK_TCK);
gotoxy(50,3); printf("%.4f",bios_time/_BIOS_CLK_TCK/60);
gotoxy(50,4); printf("%.4f",bios_time/_BIOS_CLK_TCK/3600);
} return 0;}clock() - Determines processor time
Specification#includeclock_t clock(void);
Return Value Clock can be used to determine the time interval between two events. On success clock returns the processor time elapsed since the beginning of the program invocation. On error clock returns –1.Example
Code: c
#include#include#include#include
void main(void){ long int bios_start,bios_end; float elap_bios,elap_clock; clock_t clock_start,clock_end;
_bios_timeofday(_TIME_GETCLOCK,&bios_start); clock_start=clock(); printf("\n_bios = %ld\t\tclcok = %ld",bios_start,clock_start); clock_end=clock(); _bios_timeofday(_TIME_GETCLOCK,&bios_end); printf("\n_bios = %ld\t\tclock = %ld",bios_end,clock_end);
elap_bios=(bios_end-bios_start)/18.2F; elap_clock=(clock_end-clock_start)/(float) CLK_TCK; printf("\nelap_bios = %f sec\nelap_clock = %f sec",elap_bios,elap_clock); exit(0);}_bios_timeofday() - Get/set the system timer clock ticks
Specification #includeunsigned _bios_timeofday(unsigned service, long *ticks)Argumentsservice : use either the _TIME_GETCLOCK or _TIME_SETCLOCK object like macros found in ticks : pointer to a long that is used either to return the clock tick count or to serve as the value to set the clock tick count.Return ValueWhen the _TIME_GETCLOCK service is used, a value of 0 is returned if midnight has been passed since the last get or set time was performed; otherwise a value pf 1 is returned.When _TIME_SETCLOCK service is used, there is no return value.Example See previous example
ctime() - converts date and time to a string
Specification#includechar *ctime(const time_t *timer);Argumentstimer : pointer to a time value in time_t format that was acquired using function time().Return Valuectime returns a pointer to the character string containing the date and time.ExampleCode: c
#include#include
int main(void){ time_t t; time(&t); printf("Todays date and time is : %s",ctime(&t)); return 0;}time() - get system time in time_t format
Specification#includetime_t time(time_t *timer);Argumentstimer : pointer to a time_t type variable that is assigned the number of seconds elapsed since 00:00:00 GMT January 1, 1970.If timer is null no value is stored.Return Value The elapsed time in seconds identical to that placed in timer.Example See previous example
References
C Encyclopedia, Compiler Help and various websites (credits to google)

Good places to check for latest virus information

These are just some of the places that you should visit frequently to keep up to date on information about the latest virus, trojan, backdoor, worm, etc. Some of these places will have removal tools (if available) or important information on what you can do to remove the threat if you have been infected. It is a good idea to check them regularly, along with updating the definitions of any virus program you may have installed. Symantec Security Response:
Code:
http://securityresponse.symantec.com/Symantec Security Response (Search):
Code:
http://www.symantec.com/avcenter/vinfodb.htmlSymantec Security Response (Removal Tools):
Code:
http://securityresponse.symantec.com...ools.list.htmlCA Virus Information Center:
Code:
http://www3.ca.com/securityadvisor/v...o/default.aspxUS-CERT Current Activity:
Code:
http://www.us-cert.gov/current/CERT/CC Computer Virus Resources (good list of sites to check for different things):
Code:
http://www.cert.org/other_sources/viruses.html

Basic BIOS password క్రాక్:

This is a password hack but it clears the BIOS such that the next time you start the PC, the CMOS does not ask for any password. Now if you are able to bring the DOS prompt up, then you will be able to change the BIOS setting to the default. To clear the CMOS do the following:Get DOS prompt and type:
Code:

DEBUG hit Enter

n-o 70 2e hit Enter

-o 71 ff hit Enter

-q hit Enter

exit hit Enter

Restart the computer. It works on most versions of the AWARD BIOS.
Accessing information on the hard disk
When you turn on the host machine, enter the CMOS setup menu (usually you have to press F2, or DEL, or CTRL+ALT+S during the boot sequence) and go to STANDARD CMOS SETUP, and set the channel to which you have put the hard disk as TYPE=Auto, MODE=AUTO, then SAVE & EXIT SETUP. Now you have access to the hard disk.
Standard BIOS backdoor passwords The first, less invasive, attempt to bypass a BIOS password is to try on of these standard manufacturer's backdoor passwords:
AWARD BIOSAWARD SW, AWARD_SW, Award SW, AWARD PW, _award, awkward, J64, j256, j262, j332, j322, 01322222, 589589, 589721, 595595, 598598, HLT, SER, SKY_FOX, aLLy, aLLY, Condo, CONCAT, TTPTHA, aPAf, HLT, KDD, ZBAAACA, ZAAADA, ZJAAADC, djonet, %øåñòü ïpîáåëîâ%, %äåâÿòü ïpîáåëîâ%
AMI BIOSAMI, A.M.I., AMI SW, AMI_SW, BIOS, PASSWORD, HEWITT RAND, Oder
Other passwords you may try (for AMI/AWARD or other BIOSes)
LKWPETER, lkwpeter, BIOSTAR, biostar, BIOSSTAR, biosstar, ALFAROME, Syxz, Wodj
Note that the key associated to "_" in the US keyboard corresponds to "?" in some European keyboards (such as Italian and German ones), so -- for example -- you should type AWARD?SW when using those keyboards. Also remember that passwords are Case Sensitive. The last two passwords in the AWARD BIOS list are in Russian.
Flashing BIOS via software
If you have access to the computer when it's turned on, you could try one of those programs that remove the password from the BIOS, by invalidating its memory. However, it might happen you don't have one of those programs when you have access to the computer, so you'd better learn how to do manually what they do. You can reset the BIOS to its default values using the MS-DOS tool DEBUG (type DEBUG at the command prompt. You'd better do it in pure MS-DOS mode, not from a MS-DOS shell window in Windows). Once you are in the debug environment enter the following commands:
AMI/AWARD BIOS
Code: O 70 17O 71 17QPHOENIX BIOS
Code: O 70 FFO 71 17QGENERICInvalidates CMOS RAM.Should work on all AT motherboards(XT motherboards don't have CMOS)
Code: O 70 2EO 71 FFQNote that the first letter is a "O" not the number "0". The numbers which follow are two bytes in hex format.
Flashing BIOS via hardware If you can't access the computer when it's on, and the standard backdoor passwords didn't work, you'll have to flash the BIOS via hardware. Please read the important notes at the end of this section before to try any of these methods. Using the jumpers
The canonical way to flash the BIOS via hardware is to plug, unplug, or switch a jumper on the motherboard (for "switching a jumper" I mean that you find a jumper that joins the central pin and a side pin of a group of three pins, you should then unplug the jumper and then plug it to the central pin and to the pin on the opposite side, so if the jumper is normally on position 1-2, you have to put it on position 2-3, or vice versa). This jumper is not always located near to the BIOS, but could be anywhere on the motherboard. To find the correct jumper you should read the motherboard's manual.
Once you've located the correct jumper, switch it (or plug or unplug it, depending from what the manual says) while the computer is turned OFF. Wait a couple of seconds then put the jumper back to its original position. In some motherboards it may happen that the computer will automatically turn itself on, after flashing the BIOS. In this case, turn it off, and put the jumper back to its original position, then turn it on again. Other motherboards require you turn the computer on for a few seconds to flash the BIOS.
If you don't have the motherboard's manual, you'll have to "brute force" it... trying out all the jumpers. In this case, try first the isolated ones (not in a group), the ones near to the BIOS, and the ones you can switch (as I explained before). If all them fail, try all the others. However, you must modify the status of only one jumper per attempt, otherwise you could damage the motherboard (since you don't know what the jumper you modified is actually meant for). If the password request screen still appear, try another one.
If after flashing the BIOS, the computer won't boot when you turn it on, turn it off, and wait some seconds before to retry.
Removing the battery
If you can't find the jumper to flash the BIOS or if such jumper doesn't exist, you can remove the battery that keeps the BIOS memory alive. It's a button-size battery somewhere on the motherboard (on elder computers the battery could be a small, typically blue, cylinder soldered to the motherboard, but usually has a jumper on its side to disconnect it, otherwise you'll have to unsolder it and then solder it back). Take it away for 15-30 minutes or more, then put it back and the data contained into the BIOS memory should be volatilized. I'd suggest you to remove it for about one hour to be sure, because if you put it back when the data aren't erased yet you'll have to wait more time, as you've never removed it. If at first it doesn't work, try to remove the battery overnight.
Important note: in laptop and notebooks you don't have to remove the computer's power batteries (which would be useless), but you should open your computer and remove the CMOS battery from the motherboard.
Short-circuiting the chip
Another way to clear the CMOS RAM is to reset it by short circuiting two pins of the BIOS chip for a few seconds. You can do that with a small piece of electric wire or with a bent paper clip. Always make sure that the computer is turned OFF before to try this operation.
Here is a list of EPROM chips that are commonly used in the BIOS industry. You may find similar chips with different names if they are compatible chips made by another brand. If you find the BIOS chip you are working on matches with one of the following you can try to short-circuit the appropriate pins. Be careful, because this operation may damage the chip. CHIPS P82C206 (square)
Short together pins 12 and 32 (the first and the last pins on the bottom edge of the chip) or pins 74 and 75 (the two pins on the upper left corner).
Code: gnd 74 __________________5v 75-- CHIPS 1 * P82C206 ___________________ gnd 5v 12 32OPTi F82C206 (rectangular) Short together pins 3 and 26 (third pin from left side and fifth pin from right side on the bottom edge).
Code: 80 51 ______________81 - - 50 OPTi F82C206 100-________________-31 1 30 3 26Dallas DS1287, DS1287ABenchmarq bp3287MT, bq3287AMT The Dallas DS1287 and DS1287A, and the compatible Benchmarq bp3287MT and bq3287AMT chips have a built-in battery. This battery should last up to ten years. Any motherboard using these chips should not have an additional battery (this means you can't flash the BIOS by removing a battery). When the battery fails, the RTC chip would be replaced.
CMOS RAM can be cleared on the 1287A and 3287AMT chips by shorting pins 12 and 21.The 1287 (and 3287MT) differ from the 1287A in that the CMOS RAM can't be cleared. If there is a problem such as a forgotten password, the chip must be replaced. (In this case it is recommended to replace the 1287 with a 1287A). Also the Dallas 12887 and 12887A are similar but contain twice as much CMOS RAM storage.
Code: __________ 1 - * U - 24 5v 2 - - 23 3 - - 22 4 - - 21 RCL (RAM Clear) 5 - - 20 6 - - 19 7 - - 18 8 - - 17 9 - - 16 10 - - 15 11 - - 14gnd 12 -__________- 13NOTE: Although these are 24-pin chips,the Dallas chips may be missing 5 pins,these are unused pins.Most chips have unused pins,though usually they are still present.
Dallas DS12885SBenchmarq bq3258SHitachi HD146818APSamsung KS82C6818A This is a rectangular 24-pin DIP chip, usually in a socket. The number on the chip should end in 6818. Although this chip is pin-compatible with the Dallas 1287/1287A, there is no built-in battery.Short together pins 12 and 24.
Code: 5v 24 20 13 _______________________________ DALLAS > DS12885S __________________________________ 1 12 gndMotorola MC146818AP Short pins 12 and 24. These are the pins on diagonally opposite corners - lower left and upper right. You might also try pins 12 and 20.
Code: __________ 1 - * U - 24 5v 2 - - 23 3 - - 22 4 - - 21 5 - - 20 6 - - 19 7 - - 18 8 - - 17 9 - - 16 10 - - 15 11 - - 14gnd 12 -__________- 13Replacing the chip
If nothing works, you could replace the existing BIOS chip with a new one you can buy from your specialized electronic shop or your computer supplier. It's a quick operation if the chip is inserted on a base and not soldered to the motherboard, otherwise you'll have to unsolder it and then put the new one. In this case would be more convenient to solder a base on which you'll then plug the new chip, in the eventuality that you'll have to change it again. If you can't find the BIOS chip specifically made for your motherboard, you should buy one of the same type (probably one of the ones shown above) and look in your motherboard manufacturer's website to see if there's the BIOS image to download. Then you should copy that image on the chip you bought with an EPROM programmer.
Important
Whether is the method you use, when you flash the BIOS not only the password, but also all the other configuration data will be reset to the factory defaults, so when you are booting for the first time after a BIOS flash, you should enter the CMOS configuration menu (as explained before) and fix up some things.
Also, when you boot Windows, it may happen that it finds some new device, because of the new configuration of the BIOS, in this case you'll probably need the Windows installation CD because Windows may ask you for some external files. If Windows doesn't see the CD-ROM try to eject and re-insert the CD-ROM again. If Windows can't find the CD-ROM drive and you set it properly from the BIOS config, just reboot with the reset key, and in the next run Windows should find it. However most files needed by the system while installing new hardware could also be found in C:\WINDOWS, C:\WINDOWS\SYSTEM, or C:\WINDOWS\INF .
Key Disk for Toshiba laptops
Some Toshiba notebooks allow to bypass BIOS by inserting a "key-disk" in the floppy disk drive while booting. To create a Toshiba Keydisk, take a 720Kb or 1.44Mb floppy disk, format it (if it's not formatted yet), then use a hex editor such as Hex Workshop to change the first five bytes of the second sector (the one after the boot sector) and set them to 4B 45 59 00 00 (note that the first three bytes are the ASCII for "KEY" :) followed by two zeroes). Once you have created the key disk put it into the notebook's drive and turn it on, then push the reset button and when asked for password, press Enter. You will be asked to Set Password again. Press Y and Enter. You'll enter the BIOS configuration where you can set a new password.
Key protected cases
A final note about those old computers (up to 486 and early Pentiums) protected with a key that prevented the use of the mouse and the keyboard or the power button. All you have to do with them is to follow the wires connected to the key hole, locate the jumper to which they are connected and unplug it.
more later...

Why must we Defrag the computer?

As everyone know once in a while everyone must defrag their computer. But do you really know why? Here i will show you basically why you must do it. When you start up a program the RAM (Randomly Access Memory) must find the files to the program you wanna start up. If the files aren't together the RAM will use longer time to find the files to the CPU. So this will basically say that your programs will startup slower than it should do. This is why you must defrag your computer it will Increase the performance.

How do we start defrag?

There are several ways you can do it on.

> START
> > All Programs
> > > Accessories
> > > > System Tools
> > > > > Defragment

> START
> > RUN
> > > dfrg.msc

> START
> > RUN
> > > cmd
> > > > defrag

Now you get up list of commands you may use.
Lets take an Example :

Defrag C: -a = Here you will Analyze and see if its needed to defrag this Volum.
Defrag C: -f = Here you will start defraging Volume C:

You must always type in the Volume you wanna defrag.

What are all the colors how can we understand them?

Red (Fragmented Files)

So what does Fragmented Files means? Here i am going to show you what it really is. Every time you download a Software or install something. The data so the file have will be written down on the hard disk it tries to find available space and it are just finding an space so is free. When you haven't defrag for a while the files will flow over everywhere and it will be much more harder to find the files for the computer. So Basically the defrag is taking away the Fragmented files and make them to Contextual files.

Blue (Contextual files)

This is files so are stored together. They are converted from Fragmented files to Contextual files. This means that the computer have easy access to the files. So this will get better for the RAM to find the files and send it to the CPU and the programs will startup faster.

Green (Files so can't be moved) "Sorry i don't know the English word" :/

This is files so cannot be moved this is since the files are in use by the system (This can basically mean WINDOWS files)

White (Free Space)

This is free space on your computer to more white you have to more space is available on your computer so you can use to store data on.

Wednesday, July 23, 2008




Your Ad Here

Thursday, July 17, 2008

yearn online vitout investing

Welcome to A.W.Surveys!

We would like to thank you for being part of A.W.Surveys. With your help we are one of the fastest growing survey companies in the world. We are proud that our Web Site Evaluations are helping change how the web looks. We believe we have the best survey takers in the world, which is why we value and pay so much for your evaluations.

July is Here!! - New Announcements

The $500 Monthly Bonus cash prize for June has ended! The winner for June is MandySa****! Congratulations!

7/1/2008 - The July Bonus Contest starts today. Please remember you receive $1 for completing this survey and will also be entered into our $500 Monthly Contest.

7/8/2008 - As A.W.Surveys continues to grow we are always looking for new ways to improve our services. We are now considering adding AlertPay as our 3rd payment option. Currently we pay members with PayPal or by Check. Further details on this will be available shortly.

7/14/2008 - AlertPay will be added as our 3rd Redeem Payment option later this month. Please remember we are not removing any of our previous payment methods but adding a 3rd payment option for you.

Determination of Prime Factors using Functions.
A positive integer is entered through the keyboard.
Write a function to obtain the prime factors of this number.
For example, prime factors of 24 are 2, 2, 2 and 3, whereas prime factors of 35 are 5 and 7.



#include
main()
{

int number;
int prime(int number);

int primefactor(int number);


printf("Enter the number whose prime factors are to be calculated:");

scanf ("%d", &number);

primefactor(number);

}

//The following function detects a Prime number.

prime(int num)
{
int i, ifprime;


for (i=2; i<=num-1; i++)

{
if (num%i==0)
{

ifprime=0;
}
else
ifprime=1;

}
return (ifprime);
}


//The following function prints the prime factors of a number.

primefactor(int num)
{
int factor,ifprime;
for (factor=2; factor<=num;)

{
prime(factor); //so that the factors are only prime and nothing else.
if (ifprime)

{
if (num%factor==0) //diving by all the prime numbers less than the number itself.
{

printf("%d ", factor);
num=num/factor;

continue;
}
else
{
factor++;//this cannot be made a part of the for loop

}
}
}
return 0;
}





Calculation of A to the power of B using Functions
Write a function power(a,b), to calculate the value of a raised to b.



#include
main()
{

int power (a,b);
int a, b, result;

printf("Enter the value of a and b:");
scanf ("%d %d", &a, &b);

result=power(a,b);
printf("%d raised to %d is %d", a, b, result);

}

power (int a, int b)
{

int calculation=1, calc;
for (calc=1; calc <=b; calc++)

{
calculation=calculation*a;
continue;
}

return(calculation);
}



Conver the given year to Roman Numerals using Functions.
Write a general-purpose function to convert any given year into its roman equivalent.
The following table shows the roman equivalents of decimal numbers:

Decimal:........Roman
1.....................i
5....................v
10..................x
50..................l
100................c
500...............d
1000.............m

Example:
Roman equivalent of 1988 is mdcccclxxxviii
Roman equivalent of 1525 is mdxxv

This program is a big lengthy owing to the use of Case Statements. This program can also be rewritten using Arrays, which will reduce the length considerably.


#include
main()
{

int year;
int convert (int year);



{

printf("Note:Enter a four year digit year.\n\n");

printf("Enter the year that you wanna convert to Roman: " );

scanf ("%d", &year);

if (year> 1999)

{
printf("Invalid Year.Please enter again.\n\n");
}
}

convert(year);


}



convert(int year)

{
int i;

printf("\nYear converted to Roman:");


i=(year/1000); //thousands place
if(i==1)

{
printf("m");
}


i=((year/100)%10); //hundreds place

switch (i)
{
case 1:
printf("c");

break;

case 2:
printf("cc");

break;

case 3:
printf("ccc");

break;

case 4:
printf("cd");

break;

case 5:
printf("d");

break;

case 6:
printf("dc");

break;

case 7:
printf("dcc");

break;

case 8:
printf("dccc");

break;

case 9:
printf("dcccc"); //this part you may think is wrong..9 -> cm

break; //but i have taken a hint from the example in the question.

}



i=((year/10)%10); //tens place

switch(i)
{
case 1:
printf("x");

break;

case 2:
printf("xx");

break;

case 3:
printf("xxx");

break;

case 4:
printf("xl");

break;

case 5:
printf("l");

break;

case 6:
printf("lx");

break;

case 7:
printf("lxx");

break;

case 8:
printf("lxxx");

break;

case 9:
printf("lxxxx"); //had it not been for this example, it would have been xc

break;

}



i=year%10; //ones place

switch(i)
{
case 1:
printf("i");

break;

case 2:
printf("ii");

break;

case 3:
printf("iii");

break;

case 4:
printf("iv");

break;

case 5:
printf("v");

break;

case 6:
printf("vi");

break;

case 7:
printf("vii");

break;

case 8:
printf("viii");

break;

case 9:
printf("ix");

break;
}


printf ("\n\n");

return 0;

}







Detection of Leap year using Functions.
Any year is entered through the keyboard.
Write a function to determine whether the year is a leap year or not.



#include
main()
{

int leap_year(year);
int year, lp;

printf("Enter the year:");
scanf ("%d", &year);

lp=leap_year(year);

if (lp)

{
printf("\nThe entered year is a leap year.");
}
else
{

printf("\nThe entered year is not a leap year.");
}

}


leap_year(int y)

{
int lp;

if (y%4==0)

{
lp=1;
}
else
lp=0;

return(lp);
}
Calculation of Sum, Average and Standard Deviation using Functions and Pointers.
Write a function that receives 5 integers and returns the sum, average and standard
deviation of these numbers. Call this function from main() and print the results in main().



#include
#include

int calc (float a, float b, float c, float d, float e, float *sum, float *avg,float *sd);

int main()
{
float a, b, c, d, e, sum=0.0, avg=0.0;

float sd=0.0;

printf("Enter Five Numbers:");
scanf("%f %f %f %f %f",&a,&b,&c,&d,&e);

calc (a, b, c, d, e, &sum, &avg, &sd);


printf("\nSum=%f", sum);
printf("\nAverage=%f", avg);

printf("\nStandard Deviation=%f\n", sd);


getchar();

return 0;
}

calc (float a, float b, float c, float d, float e, float *sum, float *avg, float *sd)

{
float Calc=0.0;

*sum = a+b+c+d+e;

*avg = *sum / 5.0;

Calc += ( a - *avg) * ( a - *avg);

Calc += ( b - *avg) * ( b - *avg);

Calc += ( c - *avg) * ( c - *avg);
Calc += ( d - *avg) * ( d - *avg);

Calc += ( e - *avg) * ( e - *avg);


*sd = sqrt((double)Calc/5.0);

}


Calculation of Product of Two Numbers using Function - Returns a Float
This program seems to be rather simple. But there's one little thing to be noted in this particular program. The thing is that the function in this program returns a float. The function declaration is usually given outside main..but due to some other standards that I am following, I have prototyed it inside main..but that doesn't cause much of a difference in this simple program.

Write a function which receives a float and an int from main(), finds the product
of these two and returns the product which is printed through main().

#include
main()
{

int i;
float j, prod;
float product (int x, float y);

printf("Enter the i(int) and j(float):");
scanf ("%d %f", &i, &j);

prod = product(i,j);

printf("Product:%f", prod);

}

product (int x, float y)
{

float product;
product = x*y;
return (product);

}




Calculation of Area and Circumference of a Circle using Pointers
The following program is one good example that illustrates how we can return more than one value in a function. The answer is certainly using Pointers. The following program demonstrates the method.

Write a function that calculates both Area and Perimeter/ Circumference of the Circle, whose Radius is
entered through the keyboard.


#include
main()
{

int radius;
float area, perimeter;

printf("\nEnter radius of a circle:");

scanf ("%d", &radius);
areaperi (radius, &area, &perimeter);

printf("Area=%f", area);
printf("\nPerimeter=%f", perimeter);

}


areaperi(int r, float *a, float *p)

{
*a=3.14*r*r;
*p=2*3.14*r;

}



//This Program exhibits the use of Call By Reference.

Monday, July 7, 2008

Access a Class Member Function Without Creating a Class Object

--------------------------------------------------------------------------------

In some cases, it is possible to call a class member function without creating the class object.
In the following example, the program will print "hello world" although class A has never been created. When the program enters the "PrintMe" function, the "this" pointer is zero. This is fine as long as you don't access data members through the "this" pointer.


Code: CPP
#include
class A {
public:
void PrintMe();
};


void A::PrintMe()
{
printf("Hello World\n");
}

void main()
{
A* p = 0;
p->PrintMe();

}
Negative Numbers Represented in C++

--------------------------------------------------------------------------------

You probably know that integers are represented in binary--in base 2. This is pretty straightforward for positive numbers, but it means you must choose an encoding for representing negatives. The encoding used by C++ (as well was by C and Java) is two's complement.
In two's complement, the first bit of a negative number is always 1. Otherwise, the number is 0 or postive. To find the bitstring representing a negative number, you take the bitstring representing the corresponding positive number and flip all the bits. Next, add 1 to the result.

In the following example, Ive used 4-bit numbers for simplicity:


-5d = -(0101b) = (1010b + 1b) = 1011b

Notice that -1d is represented as all 1's:

-1d = -(0001b) = 1110b + 1 = 1111b

A nice property of this encoding is that you can subtract by negating and then adding the following:

7d - 3d = 0111b
- 0011b

=> 0111b
+ 1100b + 1

=> 0111b
+ 1101b
= 0100b = 4d

Yet another nice property is that overflows and underflows wrap around and cancel one another out, like this:

5d + 6d = 0101b
+ 0110b
= 1011b
= -(0100b + 1)
= -0101b = -5d

If you subtract 6 from this result (by adding its negation), youll get 5 back. First, compute -6:

-6d = -(0110b) = 1001b + 1 = 1010b

Then, add -6d to -5d to get the original value:

1011b
+ 1010b
= 0101

Matthew Johnson
Debugging the Memory Leaks in MS VC++ 6.0

--------------------------------------------------------------------------------

The failure to deallocate previously allocated memory is known as a memory leak. A memory leak is one of those hard to detect bugs, and it may cause unpredictable behavior in your program.
To allocate memory on the heap, you call new. To deallocate, you call delete. If a memory object has not been deallocated, a memory leak dump for a leak can be seen in the Output window in the end of a VC++ debug session. The dump is as follows:

{N} normal block at 0x00421C90, 12 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD

In which N is a unique allocation request number that represents the sequence number of an allocation of the "leaked" object.
This dump is not very helpful. To improve this dump, you can insert additional code that extends the memory leak dump with a file name and line number within this file, where the "leaked" allocation has occurred. This capability began with MFC 4.0 with the addition of the Standard C++ library. The MFC and C run-time library use the same debug heap and memory allocator. Here's the additional code:

Code: CPP

#ifdef _DEBUG //for debug builds only
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
The __FILE__ is an ANSI C macro defined by compiler. The preprocessor fills the macro with a string, whose content is the current file name, surrounded by double quotation marks.
An improved memory leak dump is as follows:

Path\Filename (LineNumber): {N} normal block at 0x00421C90, 12 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD

MS VC++ AppWizard and ClassWizard place the additional code, shown above, in the .CPP files that they create by default. The filename that is shown above will be a .CPP file name or .H file that has a template class code in them where the N-th object was allocated.
Having the location where the "leaked" N-th object was allocated is not enough. You need to know when the memory leak occurred, because the line with allocation code can be executed hundreds of times. This is why setting a simple breakpoint on this line may not be adequate.

The solution is to break an execution of the debugged program only at the moment when the "leaked" N-th object is allocated. To do this, stop the execution of your program in the debugger just after the beginning. Type in _crtBreakAlloc in the Name column of the Watch window and press the Enter key. If you use the /MDd compiler option, type in {,,msvcrtd.dll}*__p__crtBreakAlloc() in the Name column. Replace a number in the Value column with the value of N. Continue to debug using the same execution path, and the debugger will stop the program when the "leaked" N-th object will be allocated.
Scope of Variables Declared in for()

The new ANSI C++ standard specifies that variables declared as in for(int i=1; ...) have a scope local to the for statement. Unfortunately, older compilers (like Visual C++ 5.0) use the older concept that the scope is the enclosing group. Below, I list two possible problems arising from this change and their recommended solutions.

Say you want to use the variable after the for() statement. You would have to declare the variable outside of the for() statement.

Code: CPP

int i;
for(i=1; i<5; i++)
{ /* do something */ }
if (i==5) ...Say you want to have multiple for() loops with the same variables. In this case, you'd put the for statement in its own group. You could also declare the variable outside of the 'for', but that would make it slightly trickier for an optimizing compiler (and a human) to know what you intended.

Code: CPP

{
for(i=1; i<5; i++)
{ /* do something */ }
}
inline vs. __forceinline

--------------------------------------------------------------------------------

MS Visual C++, as well as several other compilers, now offer non-standard keywords that control the inline expansion of a function, in addition to the standard inline keyword. What are the uses of the non-standard keywords? First, let's review the semantics of inline. The decision whether a function declared inline is actually inline-expanded is left to the sole discretion of the compiler. Thus, inline is only a recommendation. For example, the compiler may refuse to inline functions that have loops or functions that are simply too large, even if they are declared inline.
By contrast, the non-standard keyword __forceinline overrides the compiler's heuristics and forces it to inline a function that it would normally refuse to inline. I'm not sure I can think of a good reason to use __forceinline as it may cause a bloated executable file and a reduced instruction-cache hit. Furthermore, under extreme conditions, the compiler may not respect the __forceinline request either. So, in general, you should stick to good old inline. inline is portable and it enables the compiler to "do the right thing".

__forceinline should be used only when all the following conditions hold true: inline is not respected by the compiler, your code is not to be ported to other platforms, and you are certain that inlining really boosts performance (and of course, you truly need that performance boost).

Wednesday, July 2, 2008

!!!... Election Voting Software ...!!!

Well this is the project which i made in 12th , 3 yrs back. It took me 2 mnths to complete this project but in the end all was running fine. This Program wen runned (ignore 8 warnings ) in Turbo C++ asks for a password which i have initally set to "divakar" and u can change it . After that it displays a menu. Since their are no database of candidates and voters initally so you have to first edit and enter the records of candidates and voters and den start voting. Remember this " for evry time u run the program u have enter the details of candidates n voters and this database is temporary..".. for any problems contact..

//**********************************************************
// PROJECT ELECTION-VOTING SOFTWARE
//**********************************************************


/* THIS PROJECT IS MADE BY DIVAKAR GILANI OF CLASS XII-C */


//**********************************************************
// INCLUDED HEADER FILES
//**********************************************************



#include
#include
#include
#include
#include
#include
#include
#include
#include


char description()
{ delay(2000);
cout<<"\t\t ELECTION VOTING SOFTWARE \n\n";
delay(500);
cout<<"\t DESCRIPTION : IN THIS PROJECT , A PREDETERMINED SET OF \n\n\n";
delay(500);
cout<<"\t VOTERS WILL BE ABLE TO CAST THE VOTE .VOTERS WILL HAVE \n\n\n";
delay(500);
cout<<"\t TO PROVE THEIR IDENTITY BY GIVING THEIR IDENTIFICATION \n\n\n";
delay(500);
cout<<"\t NO. A AUTHENTICATED USER WILL BE ABLE TO CAST THE VOTE.\n\n\n";
delay(500);
cout<<"\t A USER WHO HAS CASTED THE VOTE CANNOT CAST AGAIN.AFTER \n\n\n";
delay(500);
cout<<"\t VOTING HAS FINISHED RESUTS WILL BE DECLAIR. A SETUP \n\n\n";
delay(500);
cout<<"\t OPTION BEFORE ELECTION STARTS , WILL ALLOW VOTER TO BE \n\n\n";
delay(500);
cout<<"\t CREATED AND CANDIDATE CHOOSEN. \n\n\n";
delay(1500);
cout<<"\n\n\n\t\t\tPLEASE PRESS ENTER TO CONTINUE & Esc. TO EXIT\t";
char ch;
for(;;)
{
ch=getch();
if(ch==13)
break;
else
if(ch==27)
exit(-1);
else
cout<<"\n\n\t\t\t\a ! WRONG KEY ENTERED !";
delay(300);
cout<<"\n\n\n\n\t\t\t PRESS ENTER ";
}
return 0;
}

int pass()
{
char ch;
int r=0;
char pass[20];
for(;;)
{
clrscr();
gotoxy(16,20);
cout<<"Enter the password to initialize the setup :";
r=0;
for(int i=0;;i++)
{
ch=getch();

if(ch==13)
{ pass[r]='\0';
break;
}

if(ch==8)
{

if(i>0)
{ cout<i-=2;r--;
}
else
i--;
}
else
{ cout<<"*";
pass[r]=ch;
r++;
}
}
if(strcmp("divakar",pass)==0)
return 0;
else
{
cout<<"\n\n\t\t\a!! INVALID PASSWORD !!";
delay(300);
cout<<"\n\n\t\t--> TRY AGAIN";
getch();
}
}
}



//**********************************************************
// THIS FUNCTION TRUE WHEN THE STRING PASSED AS ARGUMENT IS
// IS NUMBER
//**********************************************************

int string_is_number(char* s)
{
int size = strlen(s);
for(int i = 0; i < size; i++)
if (!(s[i] >= '0' && s[i] <= '9'))
return 0;
return 1;
}

class candidate_record
{
public:
int candidate_namecode ;
char candidate_name[50] ;
char partyname[50], partysign[50] ;
char summary[1];
char revenue[100];
char age[100];
char area[50];
};

class voter_record
{
public:
int voter_namecode ;
char voter_name[50] ;
char age[10], gender[10] ;
};

class voter_status
{
public:
int voter_namecode;
int voting_status;
};

class candidate_status
{
public:
int candidate_namecode;
int numVotes;
};


//**********************************************************
// CLASS NAME : vote
// DETAILS : IT CONTROLLS OVER ALL THE FUNCTIONS
// RELATED TO VOTING ITEMS
//**********************************************************

class vote
{
public :
void add_candidate_name(void) ;
void delete_candidate_name(void) ;
void modify_candidate_name(void) ;
void list_of_candidate_names(void) ;
void voting(void) ;

void add_voter_name(void) ;
void delete_voter_name(void) ;
void modify_voter_name(void) ;
void list_of_voters_names(void) ;
private :
int last_candidate_code(int &num_candidates) ;
void delete_candidate_record(int) ;
void modify_candidate_record(int) ;
void display_candidate_record(int) ;
int name_candidate_found(int) ;
int candidate_recordno(int, candidate_record&) ;
void candidate_sort(void) ;


int last_voter_code(int &num_voters) ;
void delete_voter_record(int) ;
void modify_voter_record(int) ;
void display_voter_record(int) ;
int name_voter_found(int) ;
int voter_recordno(int, voter_record &vr) ;
void voter_sort(void) ;
voter_status* init_voter_status(int &num);
candidate_status* init_candidate_status(int &num);
} ;


//**********************************************************
// CLASS NAME : menu
// DETAILS : IT CONTROLLS OVER ALL THE FUNCTIONS
//**********************************************************
class menu
{
public :
void main_menu(void) ;
private :
void edit_menu(void) ;
vote v;
} ;


//**********************************************************
// THIS FUNCTION CREATE MAIN MENU AND CALLS OTHER FUNCTIONS
//**********************************************************

void menu :: main_menu(void)
{
clrscr() ;
char ch ;
while (1)
{
clrscr();
gotoxy(27,4) ;
cout<<" E L E C T I O N ";
gotoxy(27,6);
cout <<" V O T I N G S O F T W A R E " ;
gotoxy(31,8) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~" ;
gotoxy(32,9) ;
cout <<"1: VOTE " ;
gotoxy(32,11) ;
cout <<"2: SEE MENU " ;
gotoxy(32,13) ;
cout <<"3: EDIT " ;
gotoxy(32,17) ;
cout <<"0: QUIT " ;
gotoxy(32,20) ;
cout <<"Enter Choice : " ;
ch = getche() ;
if (ch == 27)
return ;
else
if (ch == '1')
{
vote v ;
v.voting() ;
}
else

if (ch == '2')
{
vote v ;
v.list_of_candidate_names() ;
gotoxy(1,20) ;
cout <<"Press any key to see the voters details" ;
getche() ;

v.list_of_voters_names();
}
else
if (ch == '3')
edit_menu() ;

else
if (ch == '0')
break ;
}
}


//**********************************************************
// THIS FUNCTION CREATE EDIT MENU AND CALLS OTHER FUNCTIONS
//**********************************************************

void menu :: edit_menu(void)
{
clrscr();
char ch,choice;
cout<<" \EDIT \MENU \n\n";

cout<<" 1: \* EDIT CANDIDATE RECORD \*\n";

cout<<" 2: \* EDIT VOTER RECORD \*\n";

cout<<" 0: \* EXIT \*\n";
cout<<" \ENTER \CHOICE: ";
choice = getche();
if (choice == '1')
{
while(1)
{
gotoxy(28,10) ;
cout <<" * EDIT CANDIDATE RECORD *" ;
gotoxy(28,12) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
gotoxy(28,14) ;
cout <<"1: * \ADD \CANDIDATE \NAME * " ;
gotoxy(28,16) ;
cout <<"2: * \MODIFY \CANDIDATE \NAME *" ;
gotoxy(28,18) ;
cout <<"3: * \DELETE \CANDIDATE \NAME *" ;
gotoxy(28,20) ;
cout <<"0: * \EXIT *" ;
gotoxy(28,22) ;
cout <<" ENTER CHOICE: " ;
ch = getche() ;
if (ch == '1')
{
vote v ;
v.add_candidate_name() ;
break ;
}
else if (ch == '2')
{
vote v ;
v.modify_candidate_name() ;
break ;
}
else if (ch == '3')
{
vote v ;
v.delete_candidate_name() ;
break ;
}
else
if (ch == '0')
break ;
}
}
if(choice=='2')
{
while (1)
{
gotoxy(28,10) ;
cout <<" * EDIT VOTER RECORD *" ;
gotoxy(28,12) ;
cout <<" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
gotoxy(28,14) ;
cout <<"1: * \ADD \VOTER \NAME * " ;
gotoxy(28,16) ;
cout <<"2: * \MODIFY \VOTER \NAME * " ;
gotoxy(28,18) ;
cout <<"3: * \DELETE \VOTER \NAME * " ;
gotoxy(28,20) ;
cout <<"0: * EXIT " ;
gotoxy(28,22) ;
cout <<"Enter Choice: " ;
ch = getche() ;
if (ch == '1')
{
vote v ;
v.add_voter_name() ;
break ;
}
else if (ch == '2')
{
vote v ;
v.modify_voter_name() ;
break ;
}
else if (ch == '3')
{
vote v ;
v.delete_voter_name() ;
break ;
}
else if (ch == '0')
break ;
}
}
}




//**********************************************************
// THIS FUNCTION RETURNS THE CODE OF THE LAST RECORD OF THE
// VOTER IN THE VOTER FILE (VOTER.DAT).
//**********************************************************

int vote :: last_voter_code(int &num_voters)
{
voter_record vr;
fstream file ;
num_voters = 0;
file.open("VOTER.DAT", ios::in|ios::binary) ;
file.seekg(0,ios::beg) ;
int t=0 ;
while (file.read((char *)&vr,sizeof(voter_record)))
{
t = vr.voter_namecode ;
num_voters++;
}
file.close() ;
return t ;
}


//**********************************************************
// THIS FUNCTION DISPLAY THE LIST OF THE NAMES OF VOTERS
//**********************************************************

void vote :: list_of_voters_names(void)
{
clrscr() ;
voter_record vr;
fstream file ;
file.open("VOTER.DAT", ios::in|ios::binary) ;
file.seekg(0) ;
int row = 6 , found = 0 , pageno = 1 ;
gotoxy(30,2) ;
cout <<"LIST OF NAMES OF VOTERS" ;
gotoxy(29,3) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
gotoxy(3,4) ;
cout <<"NAME CODE NAME AGE GENDER" ;
gotoxy(2,5) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
while (file.read((char *)&vr, sizeof(voter_record)))
{
delay(20) ;
found = 1 ;
gotoxy(5,row) ;
cout <gotoxy(14,row) ;
cout <gotoxy(37,row) ;
cout <gotoxy(51,row) ;
cout <if ( row == 22 )
{
row = 5 ;
gotoxy(66,1) ;
cout <<"Page no. : " <gotoxy(66,2) ;
cout <<"===============" ;
pageno++ ;
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getche() ;
clrscr() ;
gotoxy(3,4) ;
cout << "NAME CODE NAME AGE GENDER " ;
gotoxy(2,5) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
}
else
row++ ;
}
if ( !found )
{
gotoxy(5,10) ;
cout <<"\7Records not found " ;
}
gotoxy(66,1) ;
cout <<"Page no. : " <gotoxy(66,2) ;
cout <<"===============" ;
gotoxy(1,20) ;
cout <<"Press any key to continue..." ;
getche() ;
file.close () ;
}


//**********************************************************
// THIS FUNCTION ADD RECORDS IN THE VOTER FILE (VOTER.DAT)
//**********************************************************

void vote :: add_voter_name(void)
{
voter_record vr;
int vcode, valid ;
char ch;
int num_voters;
vcode = last_voter_code(num_voters) ;
vcode++ ;
do
{
clrscr() ;
gotoxy(71,2) ;
cout <<"<0>=Exit" ;
gotoxy(23,3) ;
cout <<" ADD NAME TO THE VOTER LIST" ;
gotoxy(23,4) ;
cout <<" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
gotoxy(5,6) ;
cout <<"Name Code : " <gotoxy(5,8) ;
cout <<"Name: " ;
gotoxy(5,10) ;
cout <<"Age: " ;
gotoxy(5,12) ;
cout <<"Gender: " ;
do
{
valid = 1 ;
gotoxy(1,8) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER NAME OF THE VOTER TO ADD IN THE LIST" ;
gotoxy(5,8) ;
cout <<" Name : " ;
gets(vr.voter_name) ;
strupr(vr.voter_name) ;
if (vr.voter_name[0] == '0')
return ;
if ((strlen(vr.voter_name) <> 50))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = A...Z" ;
getch() ;
}
} while (!valid) ;
do
{
valid = 1 ;
gotoxy(1,10) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER AGE OF VOTER TO ADD IN THE LIST" ;
gotoxy(5,10) ;
cout <<"Age : " ;
gets(vr.age) ;
strupr(vr.age);
if (vr.age[0] == '0')
return ;
if ((strlen(vr.age) <> 3 ) || (!string_is_number(vr.age)))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = 18...100" ;
getch() ;
}
if (atoi(vr.age) < 18)
{
valid = 0;
gotoxy(3,24);
cout <<"\7 Voter's age is less than 18";
getch();
}

} while (!valid) ;
do
{
valid = 1 ;
gotoxy(1,12) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER GENDER OF VOTER TO ADD IN THE MENU" ;
gotoxy(5,12) ;
cout <<"GENDER : " ;
gets(vr.gender) ;
strupr(vr.gender);
if (vr.gender[0] == '0')
return ;
if ((strlen(vr.gender) <> 1)
|| (strcmp(vr.gender,"M") && strcmp(vr.gender,"F")))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = M/F" ;
getch() ;
}
} while (!valid) ;
do
{
gotoxy(1,15) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(5,15) ;
cout <<"Do you want to save this record (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'Y')
{
vr.voter_namecode = vcode ;
fstream file ;
file.open("VOTER.DAT", ios::out | ios::app |ios::binary) ;
file.write((char *)&vr, sizeof(voter_record)) ;
file.close() ;
vcode++ ;
}
do
{
gotoxy(1,17) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(5,17) ;
cout <<"Do you want to add more records (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
} while (ch == 'Y') ;
}


//**********************************************************
// THIS FUNCTION DISPLAY THE RECORD OF THE GIVEN CODE FROM
// THE VOTER FILE (VOTER.DAT)
//**********************************************************

void vote :: display_voter_record(int vcode)
{
voter_record vr;
fstream file ;
file.open("VOTER.DAT", ios::in|ios::binary) ;
file.seekg(0,ios::beg) ;
while (file.read((char *)&vr, sizeof(voter_record)))
{
if (vr.voter_namecode == vcode)
{
gotoxy(5,3) ;
cout <<"Name Code : "<gotoxy(5,4) ;
cout <<"Name : "<gotoxy(5,5) ;
cout <<"Age : "<gotoxy(5,6) ;
cout <<"Gender : "<break ;
}
}
file.close() ;
}


//**********************************************************
// THIS FUNCTION RETURN THE VALUE 1 IF THE RECORD IS FOUND
// FOR THE GIVEN CODE IN THE VOTER FILE (VOTER.DAT)
//**********************************************************

int vote :: name_voter_found(int tcode)
{
voter_record vr;
fstream file ;
file.open("VOTER.DAT", ios::in|ios::binary) ;
file.seekg(0,ios::beg) ;
int found=0 ;
while (file.read((char *)&vr, sizeof(voter_record)))
{
if (vr.voter_namecode == tcode)
{
found++ ;
break ;
}
}
file.close() ;
return found ;
}


//**********************************************************
// THIS FUNCTION RETURN THE RECORD NO. OF THE GIVEN CODE IN
// THE VOTER FILE (VOTER.DAT)
//**********************************************************

int vote :: voter_recordno(int tcode, voter_record &vr)
{
voter_record temp;
fstream file ;
file.open("VOTER.DAT", ios::in|ios::binary) ;
file.seekg(0,ios::beg) ;
int found=0 ;
while (file.read((char *)&temp, sizeof(voter_record)))
{
found++ ;
if (temp.voter_namecode == tcode)
{
vr = temp;
break ;
}
}
file.close() ;
return found ;
}


//**********************************************************
// THIS FUNCTION DELETES THE RECORD FOR THE GIVEN CODE FROM
// THE VOTER FILE (VOTER.DAT)
//**********************************************************

void vote :: delete_voter_record(int tcode)
{
voter_record vr;
fstream file ;
file.open("VOTER.DAT", ios::in|ios::binary) ;
fstream temp ;
temp.open("temp.dat", ios::out|ios::binary) ;
file.seekg(0,ios::beg) ;
while ( !file.eof() )
{
file.read((char *)&vr, sizeof(voter_record)) ;
if ( file.eof() )
break ;
if ( vr.voter_namecode != tcode )
temp.write((char *)&vr, sizeof(voter_record)) ;
}
file.close() ;
temp.close() ;
file.open("VOTER.DAT", ios::out|ios::binary) ;
temp.open("temp.dat", ios::in|ios::binary) ;
temp.seekg(0,ios::beg) ;
while ( !temp.eof() )
{
temp.read((char *)&vr, sizeof(voter_record)) ;
if ( temp.eof() )
break ;
file.write((char *)&vr, sizeof(voter_record)) ;
}
file.close() ;
temp.close() ;
}


//**********************************************************
// THIS FUNCTION GIVES THE CODE NO. TO DELETE RECORD FROM
// THE VOTER FILE (VOTER.DAT)
//**********************************************************

void vote :: delete_voter_name(void)
{
clrscr() ;
char t_code[5], ch ;
int tcode ;
gotoxy(3,25) ;
cout <<"Press to see the list" ;
gotoxy(5,3) ;
cout <<"Enter Name Code of the item to be deleted : " ;
gets(t_code) ;
tcode = atoi(t_code) ;
if (tcode == 0)
{
list_of_voters_names() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"Press to Exit" ;
gotoxy(5,24) ;
cout <<"Enter Name Code of the item to be deleted : " ;
gets(t_code) ;
tcode = atoi(t_code) ;
if (tcode == 0)
return ;
}
clrscr() ;
if (!name_voter_found(tcode))
{
gotoxy(5,5) ;
cout <<"\7Record not found" ;
getch() ;
return ;
}
display_voter_record(tcode) ;
do
{
gotoxy(1,8) ; clreol() ;
gotoxy(5,8) ;
cout <<"Do you want to delete this record (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'N')
return ;
delete_voter_record(tcode) ;
gotoxy(5,15) ;
cout <<"\7Record Deleted" ;
getch() ;
}


//**********************************************************
// THIS FUNCTION MODIFY THE RECORD FOR THE GIVEN CODE FROM
// THE VOTER FILE (VOTER.DAT)
//**********************************************************

void vote :: modify_voter_record(int tcode)
{
voter_record vr;
int recno ;
recno = voter_recordno(tcode,vr) ;

if (recno == 0)
return;
int valid, t_code ;
char ch,t_namecode[5] ;
gotoxy(71,2) ;
cout <<"<0>=Exit" ;
gotoxy(5,12) ;
cout <<"Name Code : " ;
gotoxy(5,14) ;
cout <<" Name : " ;
gotoxy(5,16) ;
cout <<" Age : " ;
gotoxy(5,18) ;
cout <<"Gender: " ;
do
{
gotoxy(20,12) ; clreol() ;
cout <<"Change (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
valid = 0 ;
while (ch == 'Y' && !valid)
{
valid = 1 ;
gotoxy(1,12) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER NAME CODE TO ADD IN THE MENU" ;
gotoxy(5,12) ;
cout <<"Name Code : " ;
gets(t_namecode) ;
vr.voter_namecode = atoi(t_namecode) ;
if (vr.voter_namecode == 0)
return ;
if (name_voter_found(vr.voter_namecode) && vr.voter_namecode != tcode)
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 CODE ALREADY GIVEN" ;
getch() ;
}
}
do
{
gotoxy(20,14) ; clreol() ;
cout <<"Change (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
valid = 0 ;
while (ch == 'Y' && !valid)
{
valid = 1 ;
gotoxy(1,14) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER NAME TO ADD IN THE MENU" ;
gotoxy(5,14) ;
cout <<" Name : " ;
gets(vr.voter_name) ;
strupr(vr.voter_name) ;
if (vr.voter_name[0] == '0')
return ;
if ((strlen(vr.voter_name) <> 50))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = 1..50" ;
getch() ;
}
}
do
{
gotoxy(20,16) ; clreol() ;
cout <<"Change (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
valid = 0 ;
while (ch == 'Y' && !valid)
{
valid = 1 ;
gotoxy(1,16) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER AGE OF VOTER TO ADD IN THE MENU" ;
gotoxy(5,16) ;
cout <<"Age : " ;
gets(vr.age) ;
strupr(vr.age);
if (vr.age[0] == '0')
return ;
if ((strlen(vr.age) <> 10) || !string_is_number(vr.age))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = 1..10" ;
getch() ;
}
}
do
{
gotoxy(20,18) ; clreol() ;
cout <<"Change (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
valid = 0 ;
while (ch == 'Y' && !valid)
{
valid = 1 ;
gotoxy(1,18) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER GENDER OF VOTER TO ADD IN THE MENU" ;
gotoxy(5,18) ;
cout <<"Gender : " ;
gets(vr.gender) ;
strupr(vr.gender);
if (vr.gender[0] == '0')
return ;
if ((strlen(vr.gender) <> 10))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = " <getch() ;
}
}
do
{
gotoxy(1,21) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(5,21) ;
cout <<"Do you want to save this record (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'N')
return ;

getch() ;
fstream file ;
file.open("VOTER.DAT", ios::out | ios::ate|ios::binary) ;
int location ;
location = (recno-1) * sizeof(vr) ;
cout << " Location is " << location;
file.seekp(location) ;
file.write((char *) &vr, sizeof(voter_record)) ;
file.close() ;
voter_sort() ;
clrscr() ;
gotoxy(5,15) ;
cout <<"\7Record Modified" ;
getch() ;
}


//**********************************************************
// THIS FUNCTION GIVES THE CODE NO. TO MODIFY RECORD FROM
// THE VOTER FILE (VOTER.DAT)
//**********************************************************

void vote :: modify_voter_name(void)
{
clrscr() ;
char t_code[5], ch ;
int tcode ;
gotoxy(3,25) ;
cout <<"Press to see the list" ;
gotoxy(5,3) ;
cout <<"Enter Name Code of the item to be Modify : " ;
gets(t_code) ;
tcode = atoi(t_code) ;
if (tcode == 0)
{
list_of_voters_names() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"Press to Exit" ;
gotoxy(5,24) ;
cout <<"Enter Name Code of the item to be modify : " ;
gets(t_code) ;
tcode = atoi(t_code) ;
if (tcode == 0)
return ;
}
clrscr() ;
if (!name_voter_found(tcode))
{
gotoxy(5,5) ;
cout <<"\7Record not found" ;
getch() ;
return ;
}
display_voter_record(tcode) ;
do
{
gotoxy(5,8) ;
cout <<"Do you want to Modify this record (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'N')
return ;
modify_voter_record(tcode) ;
}



//**********************************************************
// THIS FUNCTION SORT THE RECORD IN THE VOTER FILE (VOTER.DAT)
// ACCORDING TO THE CODE NOS.
//**********************************************************

void vote :: voter_sort(void)
{
int i=0,j ;
voter_record *arr, temp ;
fstream file ;
file.open("VOTER.DAT", ios::in|ios::binary) ;


//*************************************************************
// COUNT THE NUMBER OF RECORDS IN THE FILE
//************************************************************
while (file.read((char *) &temp, sizeof(voter_record)))
i++ ;
file.clear();



//*************************************************************
// CREATE AN ARRAY TO HOD ALL THE RECORDS
//*************************************************************
arr = (voter_record*) new voter_record[i];
int size ;
size = i ;


//*************************************************************
// SEEK THE FIE BACK TO THE BEGINNING
//*************************************************************
file.seekg(0,ios::beg) ;

//*************************************************************
// READ THE RECORDS FROM THE FILE TO THE ARRAY
//*************************************************************
for( i = 0; i < size; i++)
file.read((char*)&(arr[i]),sizeof(voter_record));
file.close() ;

for (i=1; i{
for (j=0; j{
if (arr[j].voter_namecode > arr[j+1].voter_namecode)
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}

file.open("VOTER.DAT", ios::out|ios::binary) ;

for (i=0; ifile.write((char *) &arr[i], sizeof(voter_record));
delete[] arr;

file.close() ;
}



//**********************************************************
// THIS FUNCTION IS THE MAIN FUNCTION CALLING THE MAIN MENU
//**********************************************************

void main(void)
{
clrscr() ;
char des;
description();
// exit();
clrscr();
char p;
pass();
clrscr();
menu m ;
m.main_menu() ;

}



//**********************************************************
// THIS FUNCTION SORT THE RECORD IN THE CANDIDATE FILE (CANDIDATE.DAT)
// ACCORDING TO THE CODE NOS.
//**********************************************************


void vote :: candidate_sort(void)
{
int i=0,j ;
candidate_record *arr, temp ;
fstream file ;
file.open("CANDIDATE.DAT", ios::in|ios::binary) ;

while (file.read((char *) &temp, sizeof(candidate_record)))
i++ ;

file.clear();

arr = (candidate_record*) new candidate_record[i];

int size ;
size = i ;

file.seekg(0,ios::beg) ;

for( i = 0; i < size; i++)
file.read((char*)&arr[i],sizeof(candidate_record));

file.close() ;

for (i=1; i{
for (j=0; j{
if (arr[j].candidate_namecode > arr[j+1].candidate_namecode)
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}

file.open("CANDIDATE.DAT", ios::out|ios::binary) ;

for (i=0; ifile.write((char *) &arr[i], sizeof(candidate_record));
delete[] arr;

file.close() ;
}


//**********************************************************
// THIS FUNCTION GIVES THE CODE NO. TO MODIFY RECORD FROM
// THE CANDIDATE FILE (CANDIDATE.DAT)
//**********************************************************

void vote :: modify_candidate_name(void)
{
clrscr() ;
char t_code[5], ch ;
int tcode ;
gotoxy(3,25) ;
cout <<"Press to see the list" ;
gotoxy(5,3) ;
cout <<"Enter Name Code of the item to be Modify : " ;
gets(t_code) ;
tcode = atoi(t_code) ;
if (tcode == 0)
{
list_of_candidate_names() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"Press to Exit" ;
gotoxy(5,24) ;
cout <<"Enter Name Code of the item to be modify : " ;
gets(t_code) ;
tcode = atoi(t_code) ;
if (tcode == 0)
return ;
}
clrscr() ;
if (!name_candidate_found(tcode))
{
gotoxy(5,5) ;
cout <<"\7Record not found" ;
getch() ;
return ;
}
display_candidate_record(tcode) ;
do
{
gotoxy(5,8) ;
cout <<"Do you want to Modify this record (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'N')
return ;
modify_candidate_record(tcode) ;
}


//**********************************************************
// THIS FUNCTION MODIFY THE RECORD FOR THE GIVEN CODE FROM
// THE CANDIDATE FILE (CANDIDATE.DAT)
//**********************************************************

void vote :: modify_candidate_record(int tcode)
{
candidate_record cr;
int recno ;
int revenue;
recno = candidate_recordno(tcode,cr) ;
int valid, t_code ;
char ch,t_namecode[5] ;
gotoxy(71,2) ;
cout <<"<0>=Exit" ;
gotoxy(5,12) ;
cout <<"Name Code : " ;
gotoxy(5,14) ;
cout <<" Name : " ;
gotoxy(5,16) ;
cout <<" Party Name : " ;
gotoxy(5,18) ;
cout <<"Party Sign: " ;
gotoxy(5,20) ;
cout <<"Summary : " ;
do
{
gotoxy(20,12) ; clreol() ;
cout <<"Change (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
valid = 0 ;
while (ch == 'Y' && !valid)
{
valid = 1 ;
gotoxy(1,12) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER NAME CODE TO ADD IN THE MENU" ;
gotoxy(5,12) ;
cout <<"Name Code : " ;
gets(t_namecode) ;
cr.candidate_namecode = atoi(t_namecode) ;
if (cr.candidate_namecode == 0)
return ;
if (name_candidate_found(cr.candidate_namecode) && cr.candidate_namecode != tcode)
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 CODE ALREADY GIVEN" ;
getch() ;
}
}
do
{
gotoxy(20,14) ; clreol() ;
cout <<"Change (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
valid = 0 ;
while (ch == 'Y' && !valid)
{
valid = 1 ;
gotoxy(1,14) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER NAME TO ADD IN THE MENU" ;
gotoxy(5,14) ;
cout <<" Name : " ;
gets(cr.candidate_name) ;
strupr(cr.candidate_name) ;
if (cr.candidate_name[0] == '0')
return ;
if ((strlen(cr.candidate_name) <> 50))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = 1..50" ;
getch() ;
}
}
do
{
gotoxy(20,16) ; clreol() ;
cout <<"Change (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
valid = 0 ;
while (ch == 'Y' && !valid)
{
valid = 1 ;
gotoxy(1,16) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER PARTY NAME TO ADD IN THE MENU" ;
gotoxy(5,16) ;
cout <<"Party Name : " ;
gets(cr.partyname) ;
strupr(cr.partyname);
if (cr.partyname[0] == '0')
return ;
if ((strlen(cr.partyname) <> 50))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = 1..50" ;
getch() ;
}
}
do
{
gotoxy(20,18) ; clreol() ;
cout <<"Change (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
valid = 0 ;
while (ch == 'Y' && !valid)
{
valid = 1 ;
gotoxy(1,18) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER PARTY SIGN TO ADD IN THE MENU" ;
gotoxy(5,18) ;
cout <<"Party Sign : " ;
gets(cr.partysign) ;
strupr(cr.partysign);


if (cr.partysign[0] == '0')
return ;
if ((strlen(cr.partysign) <> 50))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = " <getch() ;
}
}
do
{
gotoxy(20,20) ; clreol() ;
cout <<"Change (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
valid = 0 ;
while (ch == 'Y' && !valid)
{
valid = 1 ;
gotoxy(1,20) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER THE SUMMARY OF THE CANDIDATE" ;
gotoxy(5,20) ;
cout <<"Summary declared: " ;
gets(cr.summary) ;
strupr(cr.summary);


if (cr.summary[0] == '0')
return ;
if ((strlen(cr.summary) <> 50))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = " <getch() ;
}
}
do
{
gotoxy(1,21) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(5,21) ;
cout <<"Do you want to save this record (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'N')
return ;
getch() ;
fstream file ;
file.open("CANDIDATE.DAT", ios::out | ios::ate|ios::binary) ;
int location ;
location = (recno-1) * sizeof(cr) ;
file.seekp(location) ;
file.write((char *) &cr, sizeof(candidate_record)) ;
file.close() ;
candidate_sort() ;
clrscr() ;
gotoxy(5,15) ;
cout <<"\7Record Modified" ;
getch() ;
}


//**********************************************************
// THIS FUNCTION RETURN THE VALUE 1 IF THE RECORD IS FOUND
// FOR THE GIVEN CODE IN THE CANDIDATE FILE (CANDIDATE.DAT)
//**********************************************************

int vote :: name_candidate_found(int tcode)
{
candidate_record cr;
fstream file ;
file.open("CANDIDATE.DAT", ios::in|ios::binary) ;
file.seekg(0,ios::beg) ;
int found=0 ;
while (file.read((char *)&cr, sizeof(candidate_record)))
{
if (cr.candidate_namecode == tcode)
{
found++ ;
break ;
}
}
file.close() ;
return found ;
}


//**********************************************************
// THIS FUNCTION DISPLAY THE RECORD OF THE GIVEN CODE FROM
// THE CANDIDATE FILE (CANDIDATE.DAT)
//**********************************************************

void vote :: display_candidate_record(int tcode)
{ candidate_record cr;
fstream file ;
file.open("CANDIDATE.DAT", ios::in|ios::binary) ;
file.seekg(0,ios::beg) ;
while (file.read((char *)&cr, sizeof(candidate_record)))
{
if (cr.candidate_namecode == tcode)
{
gotoxy(5,3) ;
cout <<"Name Code : "<gotoxy(5,4) ;
cout <<"Name : "<gotoxy(5,5) ;
cout <<"Party Name : "<gotoxy(5,6) ;
cout <<"Party Sign : "<gotoxy(5,7) ;
cout <<"Revenue : "<gotoxy(5,8) ;
cout <<"Age : "<gotoxy(5,9) ;
cout <<"Area : "<break ;
}
}
file.close() ;
}


//**********************************************************
// THIS FUNCTION ADD RECORDS IN THE CANDIDATE FILE (CANDIDATE.DAT)
//**********************************************************

void vote :: add_candidate_name(void)
{
candidate_record cr;
int tcode, valid ;
char ch;
int num_candidates;
tcode = last_candidate_code(num_candidates) ;
tcode++ ;
do
{
clrscr() ;
gotoxy(71,2) ;
cout <<"<0>=Exit" ;
gotoxy(27,3) ;
cout <<" ADD NAME TO THE CANDIDATE LIST" ;
gotoxy(26,4) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
gotoxy(5,6) ;
cout <<"Name Code : " <gotoxy(5,8) ;
cout <<"Name : " ;
gotoxy(5,10) ;
cout <<"Party Name : " ;
gotoxy(5,12) ;
cout <<"Party Sign : " ;
gotoxy(5,14) ;
cout <<"Summary : " ;
do
{
valid = 1 ;
gotoxy(1,8) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"ENTER NAME TO ADD IN THE CANDIDATE LIST" ;
gotoxy(5,8) ;
cout <<"Name : " ;
gets(cr.candidate_name) ;
strupr(cr.candidate_name) ;
if (cr.candidate_name[0] == '0')
return ;
if ((strlen(cr.candidate_name) <> 50))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = A.....Z" ;
getch() ;
}
}while (!valid) ;
do
{
valid = 1 ;
gotoxy(1,10) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(5,25) ;
cout <<"ENTER PARTY NAME TO ADD IN THE LIST" ;
gotoxy(5,10) ;
cout <<"Party Name : " ;
gets(cr.partyname) ;
strupr(cr.partyname);
if (cr.partyname[0] == '0')
return ;
if ((strlen(cr.partyname) <> 50))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = A.....Z" ;
getch() ;
}
} while (!valid) ;
do
{
valid = 1 ;
gotoxy(1,12) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;

gotoxy(5,25) ;
cout <<"ENTER PARTY SIGN TO ADD IN THE MENU" ;
gotoxy(5,12) ;
cout <<"Party Sign : " ;
gets(cr.partysign) ;
strupr(cr.partysign);
if (cr.partysign[0] == '0')
return ;
if ((strlen(cr.partysign) <> 50))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = A.....Z" ;
getch() ;
}
} while (!valid) ;
do
{
valid = 1;
gotoxy(1,14) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;

gotoxy(5,25) ;
cout <<"ENTER SUMMARY OF THE CANDIDATE" ;
gotoxy(5,14) ;
cout <<"SUMMARY AS FOLLOWS " ;
getch();
// gets(cr.summary) ;
strupr(cr.summary);
if (cr.summary[0] == '0')
return ;
if ((strlen(cr.summary) <> 50))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = A.....Z" ;
getch() ;
}
} while (!valid) ;
do
{
valid = 1;
gotoxy(1,16) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;

gotoxy(5,25) ;
cout <<"ENTER REVENUE OF THE CANDIDATE" ;
gotoxy(5,16) ;
cout <<"Revenue : " ;
gets(cr.revenue) ;
strupr(cr.revenue);
if (cr.revenue[0] == '0')
return ;
if ((strlen(cr.revenue) <> 50))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = A.....Z" ;
getch() ;
}
} while (!valid) ;
do
{
valid = 1;
gotoxy(1,18) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;

gotoxy(5,25) ;
cout <<"ENTER AGE OF THE CANDIDATE" ;
gotoxy(5,18) ;
cout <<"Age : " ;
gets(cr.age) ;
strupr(cr.age);
if (cr.age[0] == '0')
return ;
if ((strlen(cr.age) <> 50))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = A.....Z" ;
getch() ;
}
} while (!valid) ;
do
{
valid = 1;
gotoxy(1,20) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;

gotoxy(5,25) ;
cout <<"ENTER AREA OF THE CANDIDATE" ;
gotoxy(5,20) ;
cout <<"Area : " ;
gets(cr.area) ;
strupr(cr.area);
if (cr.area[0] == '0')
return ;
if ((strlen(cr.area) <> 50))
{
valid = 0 ;
gotoxy(3,24) ;
cout <<"\7 Range = A.....Z" ;
getch() ;
}
} while (!valid) ;
do
{
gotoxy(1,15) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(5,28) ;
cout <<"Do you want to save this record (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'Y')
{
cr.candidate_namecode = tcode ;
fstream file ;
file.open("CANDIDATE.DAT", ios::out | ios::app | ios::binary) ;
file.write((char *)&cr, sizeof(candidate_record)) ;
file.close() ;
tcode++ ;
}
do
{
gotoxy(1,17) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(1,25) ; clreol() ;
gotoxy(5,30) ;
cout <<"Do you want to add more records (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
} while (ch != 'N' && ch != 'Y') ;
} while (ch == 'Y') ;
}


//**********************************************************
// THIS FUNCTION DISPLAY THE LIST OF THE NAMES OF CANDIDATES
//**********************************************************

void vote :: list_of_candidate_names(void)
{
clrscr() ;

candidate_record cr;
fstream file ;
file.open("CANDIDATE.DAT", ios::in|ios::binary) ;
file.seekg(0) ;
int row = 6 , found = 0 , pageno = 1 ;
gotoxy(30,2) ;
cout <<"LIST OF NAMES OF CANDIDATES" ;
gotoxy(29,3) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
gotoxy(3,4) ;
cout <<"NAME CODE NAME PARTY NAME PARTY SIGN REVENUE AGE AREA";
gotoxy(2,5) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
while (file.read((char *)&cr, sizeof(candidate_record)))
{
delay(20) ;
found = 1 ;
gotoxy(5,row) ;
cout <gotoxy(14,row) ;
cout <gotoxy(31,row) ;
cout <gotoxy(45,row) ;
cout <gotoxy(58,row) ;
cout <gotoxy(69,row) ;
cout <gotoxy(75,row) ;
cout <if ( row == 22 )
{
row = 5 ;
gotoxy(66,1) ;
cout <<"Page no. : " <gotoxy(66,2) ;
cout <<"===============" ;
pageno++ ;
gotoxy(1,25) ;
cout <<"Press any key to continue..." ;
getche() ;
clrscr() ;
gotoxy(3,4) ;
cout << "NAME CODE NAME PARTY NAME PARTY SIGN REVENUE AGE AREA" ;
gotoxy(2,5) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
}
else
row++ ;
}
if ( !found )
{
gotoxy(5,10) ;
cout <<"\7Records not found " ;
}
gotoxy(66,1) ;
cout <<"Page no. : " <gotoxy(66,2) ;
cout <<"===============" ;
gotoxy(1,20) ;
cout <<"Press any key to continue..." ;
getche() ;
file.close () ;
}



//**********************************************************
// THIS FUNCTION RETURNS THE CODE OF THE LAST RECORD IN THE
// CANDIDATE FILE (CANDIDATE.DAT).
//**********************************************************

int vote :: last_candidate_code(int &num_candidates)
{
candidate_record cr;
fstream file ;
num_candidates = 0;
file.open("CANDIDATE.DAT", ios::in|ios::binary) ;
file.seekg(0,ios::beg) ;
int t=0 ;
while (file.read((char *) &cr, sizeof(candidate_record)))
{
t = cr.candidate_namecode ;
num_candidates++;
}
file.close() ;
return t ;
}



//**********************************************************
// THIS FUNCTION RETURN THE RECORD NO. OF THE GIVEN CODE IN
// THE CANDIDATE FILE (CANDIDATE.DAT)
//**********************************************************

int vote :: candidate_recordno(int tcode,candidate_record &cr)
{
candidate_record temp;
fstream file ;
file.open("CANDIDATE.DAT", ios::in|ios::binary) ;
file.seekg(0,ios::beg) ;
int found=0 ;
while (file.read((char *) &temp, sizeof(candidate_record)))
{
found++ ;
if (temp.candidate_namecode == tcode)
{
cr = temp;
break ;
}
}
file.close() ;
return found ;
}



//**********************************************************
// THIS FUNCTION DELETES THE RECORD FOR THE GIVEN CODE FROM
// THE CANDIDATE FILE (CANDIDATE.DAT)
//**********************************************************

void vote :: delete_candidate_record(int tcode)
{
candidate_record cr;
fstream file ;
file.open("CANDIDATE.DAT", ios::in|ios::binary) ;
fstream temp ;
temp.open("temp.dat", ios::out|ios::binary) ;
file.seekg(0,ios::beg) ;
while ( !file.eof() )
{
file.read((char *)&cr, sizeof(candidate_record)) ;
if ( file.eof() )
break ;
if ( cr.candidate_namecode != tcode )
temp.write((char *)&cr, sizeof(candidate_record)) ;
}
file.close() ;
temp.close() ;
file.open("CANDIDATE.DAT", ios::out|ios::binary) ;
temp.open("temp.dat", ios::in|ios::binary) ;
temp.seekg(0,ios::beg) ;
while ( !temp.eof() )
{
temp.read((char *)&cr, sizeof(candidate_record)) ;
if ( temp.eof() )
break ;
file.write((char *) &cr, sizeof(candidate_record)) ;
}
file.close() ;
temp.close() ;
}



//**********************************************************
// THIS FUNCTION GIVES THE CODE NO. TO DELETE RECORD FROM
// THE CANDIDATE FILE (CANDIDATE.DAT)
//**********************************************************

void vote :: delete_candidate_name(void)
{
clrscr() ;
char t_code[5], ch ;
int tcode ;
gotoxy(3,25) ;
cout <<"Press to see the list" ;
gotoxy(5,3) ;
cout <<"Enter Name Code of the item to be deleted : " ;
gets(t_code) ;
tcode = atoi(t_code) ;

if (tcode == 0)
{
list_of_candidate_names() ;
gotoxy(1,25) ; clreol() ;
gotoxy(3,25) ;
cout <<"Press 0 to EXIT" ;
gotoxy(5,24) ;
cout <<"Enter Name Code of the item to be deleted : " ;
gets(t_code) ;
tcode = atoi(t_code) ;
if (tcode == 0)
return ;
}
clrscr() ;
if (!name_candidate_found(tcode))
{
gotoxy(5,5) ;
cout <<"\7Record not found" ;
getch() ;
return ;
}
display_candidate_record(tcode) ;
do
{
gotoxy(1,8) ; clreol() ;
gotoxy(5,8) ;
cout <<"Do you want to delete this record (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
} while (ch != 'N' && ch != 'Y') ;
if (ch == 'N')
return ;
delete_candidate_record(tcode) ;
gotoxy(5,15) ;
cout <<"\7Record Deleted" ;
getch() ;
}

voter_status* vote::init_voter_status(int &num)
{
voter_status *vs = NULL;
num = 0;
last_voter_code(num);
if (num != 0)
{
vs = new voter_status[num];
voter_record vr;
fstream file ;
file.open("VOTER.DAT", ios::in|ios::binary) ;
for(int i = 0; i < num; i++)
{
file.read((char *)&vr, sizeof(voter_record));
vs[i].voter_namecode = vr.voter_namecode;
vs[i].voting_status = 0;
}
file.close();
}
return vs;
}
candidate_status* vote::init_candidate_status(int &num)
{
candidate_status *cs = NULL;;
num = 0;
last_candidate_code(num);
if (num != 0)
{
cs = new candidate_status[num];
candidate_record cr;
fstream file;
file.open("CANDIDATE.DAT",ios::in|ios::binary);
for(int i = 0; i < num; i++)
{
file.read((char *)&cr, sizeof(candidate_record));
cs[i].candidate_namecode = cr.candidate_namecode;
cs[i].numVotes = 0;
}
file.close();
}
return cs;

}



void vote::voting()
{
clrscr() ;

char ch,name[50];
int n ,num_voters = 0, num_candidates = 0;
int vtr_rec;
voter_status* vs = init_voter_status(num_voters);
candidate_status* cs = init_candidate_status(num_candidates);
int valid=0;
if (num_voters == 0)
{
gotoxy(3,6);
cout << "There are NO VOTERS";
ch = getche();
delete[] vs;
delete[] cs;
return;
}
if (num_candidates == 0)
{
gotoxy(3,6);
cout << "There are NO CANDIDATES";
ch = getche();
delete[] vs;
delete[] cs;
return;
}

while(1)
{
clrscr();
gotoxy(30,2);
cout <<"VOTING HAS STARTED";
gotoxy(29,3);
cout <<"~~~~~~~~~~~~~~~~~~~~~~";

{
int i;
for(i = 0; i < num_voters; i++)
{
if (vs[i].voting_status == 0) break;
}
if (i == num_voters)
{
gotoxy(3,4);
cout<<"All VOTES have been casted";
getche();
break;
}

}

gotoxy(3,24) ;
clreol();
cout <<"To End the voting Enter .\n";
gotoxy(3,25);
clreol();
cout <<"Once voting is stopped it cann't resume. You will have to start a fresh" ;

gotoxy(6,3);
clreol();
cout <<"Enter the voter code - ";
gets(name);
if (strcmp(name,"STOP") == 0)
{
//Terminate the Voting;
gotoxy(6,5);
clreol();
cout <<"Do you want to STOP the voting and start counting votes (y/n) - ";
ch = getche();
ch = toupper(ch);
while(!(ch == 'Y' || ch == 'N'))
{
gotoxy(70,5);
clreol();
ch = getche();
ch = toupper(ch);
}
if (ch == 'N')
{
gotoxy(6,5);
clreol();
continue;
}
else break;
}

n = string_is_number(name);
gotoxy(6,5);
clreol();

if (n == 0)
{
cout << "Incorrect voter code, enter only digits, try again ";
getche();
continue;
}

n = atoi(name);
if (n == 0)
{
list_of_voters_names();
continue;
}


for(vtr_rec = 0; vtr_rec < num_voters; vtr_rec++)
{
if (vs[vtr_rec].voter_namecode == n)
{
if (vs[vtr_rec].voting_status == 1)
{
cout << "Voter with voter code "<< n <<" has alread voted";
}
getche();
break;
}
}
if ( vtr_rec == num_voters)
{
cout << "Voter code "<< n << " not found in Voter list";
getche();
continue;
}
if (vs[vtr_rec].voting_status == 1)
{
cout << "Voter code "<getche();
continue;
}

while(1)
{
clrscr();

gotoxy(3,24) ;
clreol();
cout<<"To cast invalid vote press ";

gotoxy(3,3);
cout <<"Voter with voter code " << vs[vtr_rec].voter_namecode<<" is voting";
gotoxy(3,4);
cout<<"Enter the candidate code -" ;

char can_code[50];
gets(can_code);

if (can_code[0] == 'Y' || can_code[0] == 'y')
{
vs[vtr_rec].voting_status = 1;
clrscr();
cout<<"Voter ";
gotoxy(3,7);
display_voter_record(vs[vtr_rec].voter_namecode);
gotoxy(3,8);
cout <<"has casted a invalid vote";
getche();
break;
}


int can = string_is_number(can_code);

gotoxy(3,6);
if (can == 0)
{
cout << "Incorrect candidate code, enter only digits, try again ";
getche();
continue;
}

can = atoi(can_code);
if (can == 0)
{
list_of_candidate_names();
getche();
continue;
}
int can_rec;
for(can_rec=0; can_rec{
if (cs[can_rec].candidate_namecode == can)
break;
}
if (can_rec == num_candidates)
{
cout <<"Candidate code "<getche();
continue;
}
cs[can_rec].numVotes++;
vs[vtr_rec].voting_status = 1;
clrscr();
gotoxy(3,6);

voter_record vr;
voter_recordno(vs[vtr_rec].voter_namecode, vr) ;

cout<<"Voter " << vr.voter_name<< " has voterd for Candidate ";

candidate_record cr;
candidate_recordno(cs[can_rec].candidate_namecode,cr);

cout << cr.candidate_name;

gotoxy(35,20);
cout<<"VOTE CASTED";
getche();
valid=1;
break;
}
}


if (valid)
{
clrscr();
gotoxy(20,9);
cout<<"VOTING RESULTS";
int tie =0;
int winner=0;
int max = 0;
int i;
for(i = 0; i < num_candidates; i++)
{
if (cs[i].numVotes > max)
{
max = cs[i].numVotes;
}
else if (cs[i].numVotes == max && max > 0)
tie = 1;
}

gotoxy(20,12);
if (tie) cout<<"Voting has resulted in tie, joint winners are";
else cout <<"WINNER is ";
gotoxy(20,13);
for(i = 0; i < num_candidates; i++)
{
if (cs[i].numVotes == max)
{

candidate_record cr;
candidate_recordno(cs[i].candidate_namecode,cr);
if (winner)
cout<<", ";
cout << "\n\n\t\t\t"<gotoxy(25,25);
cout<<"THE SUMMARY FOLLOWS";
delay(500);
gotoxy(25,27);
delay(500);
cout << "PARTY NAME -->"<gotoxy(25,29);
delay(500);
cout << "PARTY SIGN -->"<gotoxy(25,31);
delay(500);
cout << "REVENUE -->"<gotoxy(25,33);
delay(500);
cout << "AGE -->"<gotoxy(25,35);
delay(500);
cout << "AREA -->"<winner++;
}
}

}
ch = getche();
delete[] vs;
delete[] cs;
}