Project Due Tomorrow 11-26 Seeking Help.

Ask for help with your homework/assignments in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Project Due Tomorrow 11-26 Seeking Help.

Postby Alloria » Tue Nov 25, 2003 7:40 pm

My project is due in the tomorrow afternoon. I need to finish adding two more functions.

1. Need to be able to add a new voter into current array and increase the size of the array. I cannot use vectors

2. Need to be able to select a current voter in the array an change there party id letter.

My adviser told me that it would be a good idea to take cs121 as an elective god i wish i new back then what I was about to get myself into.

Right now my code compiles and and could get enough points to pass but i hate to hand in unfinished work even if this class is an elective. Any help would be a great help to me. -alexia

Remember i dont plan on being a programmer im just trying to pass this class i took as an elective. -alexia

Code: Select all

#include "fileutil.cpp"

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<string.h>
#include<ctype.h>
#include<fstream.h>

#if !defined(microsoft)
#include<stdlib.h>
#define cls() system("cls");
#endif

class voter
{

private:   
   int  idnumber;
   char lastname [25];
   char firstname[25];
   char party      [2];
   int  birthyear;
   int  currentage;

public:
   voter();
   voter(int,char[], char[], char[], int, int);
   voter(const voter&);
   void operator = (const voter&);
   void print();
   void disksave(ofstream& outfile);
   ~voter();

};


// =========================== Default Constructor =================================

voter::voter()
{
   idnumber       =   0;
   lastname [0]   = '\0';
   firstname[0]   = '\0';
   party    [0]   = '\0';
   birthyear      =   0;
   currentage     =   0;
}


// =========================== Constructor with Arguments ==========================

voter::voter(int id,char ln[], char fn[], char pid[], int year, int by)
{
   idnumber   = id;
   strcpy(lastname, ln);
   strcpy(firstname, fn);
   strcpy(party, pid);
   birthyear  = year;
   currentage = 2003 - birthyear;
}


// =========================== Copy Constructor ====================================


voter::voter(const voter& v1)
{
   idnumber   = v1.idnumber;
   strcpy(lastname, v1.lastname);
   strcpy(firstname, v1.firstname);
   strcpy(party, v1.party);
   birthyear  = v1.birthyear;
   currentage = 2003 - v1.birthyear;
}


// =========================== Assignment Operator  ================================

void voter::operator = (const voter& v1)
{
   idnumber   = v1.idnumber;
   strcpy(lastname, v1.lastname);
   strcpy(firstname, v1.firstname);
   strcpy(party, v1.party);
   birthyear  = v1.birthyear;
   currentage = 2003 - v1.birthyear;
}


// =========================== Display List of Voters  =============================

void voter::print()
{
   cout << idnumber    << setw(12)
       << lastname    << setw(12)
       << firstname   << setw(12)
        << party       << setw(12)
       << birthyear   << setw(12)
       << currentage  << setw(12)
         << endl;
}


// =========================== Save to File on Disk ================================

void voter::disksave(ofstream& outfile)
{
outfile  << idnumber    << setw(14)
       << lastname    << setw(12)
       << firstname   << setw(12)
        << party       << setw(12)
       << birthyear   << setw(12)
       << currentage  << setw(12)
         << endl;
}


// =========================== Destructor Argument  ================================

voter::~voter()
{

}



void getdata( voter voterlist[], int&, ifstream&);
void savefile(voter voterlist[], int , ofstream&);
void savereport(voter voterlist[], int , ofstream&);
void printreport( voter voterlist[], int);


void main()
{

   const int arraysize = 8;
        int error     = 0;
       
   voter voterlist[arraysize];
   
   ifstream infile;
   ofstream outfile;

   getdata (voterlist, error, infile);
   //savefile(voterlist, error, outfile);
   savereport(voterlist, error, outfile);
   
   //printreport(voterlist, error);



}


void getdata( voter voterlist[], int& error, ifstream& infile)
{
   int      age,
         idnumber,
         birthyear,
         currentage  = 0,
         numvoters   = 0;

   char    lastname[25],
          firstname[25],
          party[2],
          trash[2];

OpenInput( infile, "Give name of Data File:  " );

while (infile.good() )
{
   infile >> idnumber;
   infile.getline(trash,2);
   infile.getline(lastname,25,'\t');
   infile.getline(firstname, 25, '\t');
   infile.getline(party, 2, '\t');
   infile >> birthyear;
   age = 2003 - birthyear;

if ((strcmp(party, "r") == 0) || (strcmp(party, "R") == 0)  ||
   ( strcmp(party, "d") == 0) || (strcmp(party, "D") == 0)  ||
   ( strcmp(party, "l") == 0) || (strcmp(party, "L") == 0)  ||
   ( strcmp(party, "c") == 0) || (strcmp(party, "C") == 0))
{
   if ((idnumber > 1000) && ( idnumber < 10000))
   {
      if ((age > 17) && (age < 126))
      {
      voterlist[numvoters] = voter(idnumber,lastname, firstname, party, birthyear, currentage);
      ++ numvoters;
      }
      else
      error = error + 1;
      }
      else
      error = error + 1;
      }
      else
      error = error + 1;

   if (infile.fail())
   break;
}
infile.close();
}


void printreport(voter voterlist[], int error)
{

   for (int n = 0;n<(8 - error) ;n++)
   {
      voterlist[n].print();
   }
}


void savefile(voter voterlist[], int error, ofstream& outfile)
{
   OpenOutput(outfile);

   for (int n = 0;n<(8 - error) ;n++)
   {
      voterlist[n].disksave(outfile);
   }
}

void savereport(voter voterlist[], int error, ofstream& outfile)
{
   OpenOutput(outfile);

   outfile  << "idnumber"    << setw(10)
          << "lastname"    << setw(12)
          << "firstname"   << setw(20)
          << "party"       << setw(20)
          << "birthyear"   << setw(20)
          << "currentage"  << setw(12)
          <<  endl;


   for (int n = 0;n<(8 - error) ;n++)
   {
      voterlist[n].disksave(outfile);
   }
}




Alloria
 
Posts: 12
Joined: Sun Nov 23, 2003 8:26 pm

Postby devil_slayer » Wed Nov 26, 2003 4:41 am

Create a public method called setID(int ID);

Code: Select all
voter::setID(int ID)
{
  idnumber=ID;
}
User avatar
devil_slayer
 
Posts: 489
Joined: Wed Oct 01, 2003 3:44 am
Location: Warsaw, POLAND


Return to Homeworks

Who is online

Users browsing this forum: Google [Bot] and 1 guest