I need help writing a registration program

This is a very important school based assignment, i need for u to shea

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 3261 Views - Last Post: 24 April 2009 - 03:02 AM Rate Topic: -----

#1 raz0rbl00d   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 09-April 09

I need help writing a registration program

Posted 09 April 2009 - 10:39 AM

-This registration program i am requesting must display questions;
student name?
Student national ID?
Date of birth?
CXC and or CAPE grades?
Current area of study?
Desired area of study?
Age?
Necessary Personal information___?
for students to fill out as a registration form.
-Then read and save the answers in system ( not sure how to do that, even if there is a way).
-Finally out put ID cards for students who fill out registration forms with their information displayed on it.

what i have so far is a menu broken into 3 parts:
#include <stdio.h>


typedef struct record
{
int studentid;
char fname[20];
char lname[20];
int age;
char adress[30];
float hourate;
}studentrecord;

studentrecord erec;


FILE *studentfile;

void enterstudent()
{
	system("cls");


	if((studentfile=fopen("C:\\SBA.dat", "a+"))==NULL)
	{
		printf("File could not be opened\n");
	}
	else
	{

		printf("Enter 999 for the studentid to stop entering information\n\n");

		printf("Enter the student ID number\t");
		fflush(stdin);
		scanf("%d",&erec.studentid);

		while(erec.studentid!=999)
		{
			printf("Enter the first name of the student\t");
			fflush(stdin);
			gets(erec.fname);

			printf("Enter the last anme of the student\t");
			fflush(stdin);
			gets(erec.lname);

			printf("Enter the age of the student\t");
			fflush(stdin);
			scanf("%d",&erec.age);

			printf("Enter the adress of the student\t");
			fflush(stdin);
			gets(erec.adress);

			printf("Enter the hourly rate of the student\t");
			fflush(stdin);
			scanf("%f",&erec.hourate);

			fprintf(studentfile,"%.20s%.20s%10d%5d%.30s%5.2f\n",erec.fname,erec.lname,erec.studentid,erec.age,erec.adress,erec.hourate);

			printf("Enter 999 for the studentid to stop entering information\n\n");

			printf("Enter the student ID number\t");
			fflush(stdin);
			scanf("%d",&erec.studentid);

		}

		fclose(studentfile);
	}
}



#include <stdio.h>
#include "EnterStudent.h"
#include "ViewStudent.h"

void displayMenu();

int main()
{
	int selection;

	displayMenu();
	scanf("%d",&selection);

	while (selection!=3)
	{

		if (selection==1)
		{
			enterstudent();
		}

		if (selection==2)
		{
			viewstudent();
		}

		displayMenu();
		scanf("%d",&selection);

	}

    return 0;
}

void displayMenu()
{
	system("cls");
	printf("\t\t\t********************************\n\n\n\n\n");
    printf ("\t\t\t\t1)Add student\n");
	printf ("\t\t\t\t2)View student File\n");
	printf ("\t\t\t\t3)Exit\n\n");
	printf("\t\t\t********************************\n\n");
	printf("\t\t\tPlease make your selecetion\t");
	return;
}


#include <stdio.h>

int studentid;
char fname[20];
char lname[20];
int age;
char adress[30];
float hourate;
FILE *studentfile;


void viewstudent()
{

	if((studentfile=fopen("C:\\SBA.dat", "r+"))==NULL)
	{
		printf("File could not be opened\n");
	}
	else

	{
	system("cls");


			fscanf(studentfile,"%.20s%.20s%10d%5d%.30s%5.2f\n",erec.fname,erec.lname,erec.studentid,erec.age,erec.adress,erec.hourate);

			
			
		
			
			//display to screen
			printf("First Name %5s\nLast Name  %5s\nStudentID  %2d\nAge %5d\nAddress %.30s\n Hourly Rate  %f\nf\n\n\n", erec.fname,erec.lname,erec.studentid,erec.age,erec.adress,erec.hourate);
		

		
	
		getch();
	}
}



*** MOD EDIT: Fixed code tags. ***

This post has been edited by JackOfAllTrades: 09 April 2009 - 01:08 PM


Is This A Good Question/Topic? 0
  • +

Replies To: I need help writing a registration program

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: I need help writing a registration program

Posted 09 April 2009 - 01:08 PM

Moving to Homework forum
Was This Post Helpful? 0
  • +
  • -

#3 janotte   User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: I need help writing a registration program

Posted 09 April 2009 - 11:12 PM

Did you have a question?
Was This Post Helpful? 0
  • +
  • -

#4 raz0rbl00d   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 09-April 09

Re: I need help writing a registration program

Posted 14 April 2009 - 01:27 PM

View Postjanotte, on 9 Apr, 2009 - 10:12 PM, said:

Did you have a question?


the question was as i briefly stated before was to write a registration program for students in a university, the programs can differ from person to person, and is not specific, i am trying to have my program give a list of questions (registration form) to be filled out by students, and then simply the answers will be used to register students into the system (saved info in database) and give each student who filled out the form ID cards with if not all some of the information from the registration form to show membership of collage etc.

P.S tank u very much to take the time out and help the reply u gave meant alot...
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: I need help writing a registration program

Posted 14 April 2009 - 02:30 PM

And...what is the problem you're having? We're not a homework checking and/or completion service. We help people with specific problems they may be having.
Was This Post Helpful? 0
  • +
  • -

#6 raz0rbl00d   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 09-April 09

Re: I need help writing a registration program

Posted 16 April 2009 - 09:12 AM

View PostJackOfAllTrades, on 14 Apr, 2009 - 01:30 PM, said:

And...what is the problem you're having? We're not a homework checking and/or completion service. We help people with specific problems they may be having.

jackofalltrades, if i get this program done ill get into a really good computing school but! surprisingly programing is not a course for this school and i need not fully understand codes etc...but to get in i need to get this program done, i kno that the program i am asking for is such a low class code and is very simple, plz take 3minutes of ur time and help me gain a chance for a good future help me finish my code.
Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: I need help writing a registration program

Posted 16 April 2009 - 12:49 PM

Sorry, that's not the way it works in the real world.
Was This Post Helpful? 0
  • +
  • -

#8 janotte   User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: I need help writing a registration program

Posted 17 April 2009 - 04:05 AM

If you can't write code good enough to get into the school then you will fail when you get there.

That would be a waste of your time and a waste of a place for someone who can write this code.

Sorry the world is a tough competitive place but it is.
Was This Post Helpful? 0
  • +
  • -

#9 sbell1099   User is offline

  • Inspiring StoryTeller
  • member icon

Reputation: 16
  • View blog
  • Posts: 685
  • Joined: 28-October 08

Re: I need help writing a registration program

Posted 17 April 2009 - 04:19 PM

Lol WHo does this kid think he is?

Listen I started on this forum With basic knowledge just learn at least a bit don't tottaly expect some one to do it for you.Aswell some one would be paid for this in te real world.and read the rules:

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#10 raz0rbl00d   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 09-April 09

Re: I need help writing a registration program

Posted 17 April 2009 - 11:26 PM

View Postjanotte, on 17 Apr, 2009 - 03:05 AM, said:

If you can't write code good enough to get into the school then you will fail when you get there.

That would be a waste of your time and a waste of a place for someone who can write this code.

Sorry the world is a tough competitive place but it is.

ill explain further, the school requires the knowledge of coding but the course that i wish to uptake does not...

View Postsbell1099, on 17 Apr, 2009 - 03:19 PM, said:

Lol WHo does this kid think he is?

Listen I started on this forum With basic knowledge just learn at least a bit don't tottaly expect some one to do it for you.Aswell some one would be paid for this in te real world.and read the rules:

[rules][/rules]

ok ok i can see am giving u guyes stress, can with work, i need help with this code, i dont know why it wount work, plz assist.
#ifndef DATE1_H
#define DATE1_H

class Date {
	public:
	Date( int=1, int=1, int=1900);
	void print() const;
	~Date();
	private:
	int month;
	int day;
	int year;
	int checkDay(int);
};
#include <iostream>

using std::cout;
using std::endl;

#include "date1.h"

Date::Date(int mn, int dy, int yr)
{
	if( mn>0 && mn <=12)
	month=mn;
	else{
		month=1;
		cout <<"Month" <<mn<<"invalid. et to month 1.\n";
	}
	year=yr;
	day=checkDay(dy);

	cout<< "Date object constructor for date";
	print();
	cout << endl;
}
	void Date::print() const
	{ cout<< month<<'/'<<day<<'/'<<year;}
	Date::~Date()
{
	cout<< "Date object destructor for data";
	print();
	cout <<endl;
}
int Date::checkDay(int testDay)
{
	static const int daysPerMonth[13]={0, 31, 28, 31, 30, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	if ( testDay>0 && testDay<= daysPerMonth[month])
	return testDay;

	if(month == 2&&
	testday==29&&
	(year % 400==0
	(year % 4 ==0 && yar % 100 !=0)))
	return testday;

	cout<< "Day" << testDay <<"invalid. set to day1.\n";
	return1;
}

#ifndef EMPLY_H
#define EMPLY_H

#include "date1.h"

class Employee {
public:
Employee( char*, char*, int, int, int, int, int, int);
void print() const;
~Employee();
Private;
char firstName[ 25 ];
char LastName [ 25 ];
const Date birthDate;
const Date hireDate;
};
#endif

#include <iostream>

using std::cout;
using std::end1;

#incude <cstring>
#include"emply1.h"
#include "date1.h"

Employee::Employee(char *fname, char *lname,
int bmonth, int bday, int, byear,
int hmonth, int hday, int, hyear)
:birthDate(bmonth, bday, byear),
hireDate(hmonth, hday, hyear)
{

int length=strlen (fname);
length= (length<25? length: 24):
strncpy(FirstName, fname, length);
firstName [length]='\0';

length=strlen (lname);
length=(length< 25?length: 24):
strncpy(LastName, lname, length);
LastName [length]='\0';

cout<<Employee object constructor:"
<<firstName<<''<<LastName<<endl;
}

void Employee::print() const
{
	cout <<LastName<<","<<firstName<<"\nhired:";
	hireDate.print();
	cout<<endl;
}
Employee::~Employee()
{
	cout<<"Employee object destructor:"
	<< lastName<<",",,firstName<<endl;
}

#include <iostream>

using std::cout;
using std::endl;

#include "emply1.h"
int main()
{
	Employee e("Bob", "Jones", 7, 24, 1949, 3, 12, 1988);
	cout<<'\n';
	e.print();
	cout << "\nTest Date constructor with invalid values:\n";
	cout << endl;
	return 0;
}



Was This Post Helpful? 0
  • +
  • -

#11 janotte   User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: I need help writing a registration program

Posted 17 April 2009 - 11:44 PM

View Postraz0rbl00d, on 17 Apr, 2009 - 10:26 PM, said:

ill explain further, the school requires the knowledge of coding but the course that i wish to uptake does not...


The the experience of the school is that people who can write the required code do better in the course than those who don't. That's why they have it as an entry barrier. So the point remains.

(Alternatively the school is bad at entry requirements which means you probably should avoid it anyway.)



View Postraz0rbl00d, on 17 Apr, 2009 - 10:26 PM, said:

ok ok i can see am giving u guyes stress, can with work, i need help with this code, i dont know why it wount work, plz assist.


You need to ask explicit specific questions that are able to be given specific answers.

"How can this be better?" is not really a question that is going to get an answer of the kind you want.


However, I will say that what was has ended up on the page here is not formatted consistently nor well so that's something simple to work on.

Choose one of the two main indent/brace styles and go through and ensure each and every line exactly matches the style you have chosen. Don't mix the two styles and always indent correctly.

Take the time to vertically line up things like "=" and "(" and variable types and names where that makes sense.

Make use of whitespace (including blank lines) appropriately.

Put meaningful comments into your code. Especially include pre- and post-conditions for functions / methods.

Consider forcing your IDE / editor to break lines at 78 characters and lay your code out under that constraint. Old school trick but pays back in the appearance of code on a printed page.

These little (and not so little) formatting issues make a huge difference in how professional or sloppy your code looks.
Was This Post Helpful? 0
  • +
  • -

#12 David W   User is offline

  • DIC supporter
  • member icon

Reputation: 298
  • View blog
  • Posts: 1,839
  • Joined: 20-September 08

Re: I need help writing a registration program

Posted 19 April 2009 - 07:21 AM

Thanks for your recent comments re ...

http://www.dreaminco...snippet2614.htm

You might like to see the upgraded snippet there now. That upgrade was sitting on my PC for some time ...Your recent comments jogged my memory. I also did a list version as well as that vector version ... that I might submit as a snippet.

Shalom,
David

P.S.

You might like to take a look here also ... for ideas re. C/C++ student problems and solutions ...

http://developers-he.../index.p...opic,127.0.html
http://developers-he.../index.p...opic,134.0.html
http://developers-he.../index.p...opic,106.0.html
Was This Post Helpful? 0
  • +
  • -

#13 David W   User is offline

  • DIC supporter
  • member icon

Reputation: 298
  • View blog
  • Posts: 1,839
  • Joined: 20-September 08

Re: I need help writing a registration program

Posted 21 April 2009 - 04:46 AM

If you are doing the project using C ... I would suggest using a linked-list something like this ...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Globals ... */

#define HEADER1 "Student CXC and CAPE Record Management System ... "
#define HEADER2 "1. (I)nitialize Student record list in RAM\n" \
                "2. (A)dd i.e. insert in order, by name, a NEW Student record\n" \
                "3. view/(D)elete a Student record\n" \
                "4. view/(E)dit a Student record\n" \
                "5. (S)how all Student records (as inserted BY NAME above)\n" \
                "6. (F)ile all Student records presently in RAM\n" \
                "7. (R )ead all Student records on file into RAM\n" \
                "8. set/change (P)assword\n" \  /* if password used */
                "9. e(X)it"

#define FILE_NAME "StudentCXCCAPE.txt"



typedef struct Student
{
    long id;
    char* last;
    char* first;
    long dob; /* enter/store as: yyyymmdd  */
    char sCX[13]; /* 12+1  for ... 112233AABBCC */
    char sCA[15]; /* 14+1  for ... 1112233AAABBCC */
    char* currentArea;
    char* desiredArea;
    char* otherInfo;
    struct Student* next;
}Student;


typedef Student* pStudent;

/* global var's to keep function calls simple ... */

pStudent pHead = NULL;
int numStudents = 0; /* to hold 'num Student records in memory' ...*/
int fileFlag = 0;    /* fileFlag indicates 'the need to update the file' ... */


/*
    Student Registration Program ...

    1. Student national id ... an integer > 0 and a unique number
    2. Student last name ... a C string of any length
    3. Student first name ... a C string of any length
    4. Date of birth dob yyyymmdd (can calculate age from this)
    5. CXC (by subject) grades: I, II, III, ..., VI 
        and A, B, C ..., F (profile grades)
    6. CAPE (by subject) grades: I, II, III, ... VII 
        and A, B, C, ..., G (profile grades)

    Note: 1..6 Core Subjects are ...
        1 - Caribbean Studies,
        2 - Communication Studies,
        3 - Functional French,
        4 - Functional Spanish,
        5 - Information Technology, and
        6 - Statistical Analysis

    7. Current area of study ... a C string of any length
    8. Desired area of study ... a C string of any length
    9. Other info ... a C string of any length
*/


/* forward declarations ... would go here ...*/


int menu()
{
    puts( HEADER1 );
    if( numStudents == 1 ) puts( "Presently there is 1 record in RAM.\n" );
    else printf( "Presently there are %d records.\n\n", numStudents );
    puts( HEADER2 );
    printf( "\nPlease enter your selection: " );
    int selection = getchar();
    int c = selection;
    while( c!='\n' ) c=getchar(); /* 'flush' stdin */
    return selection;
}


int main() 
{
    int choice, readNum;

    /* recall ... using a global variable 'numStudents'  */
    /* numStudents = readFile(); */

    for(;;)/> /* Loop forever ... until 'return' ... */
    {

        choice = -1; /*  error flag */
        choice = menu();

        /* printf("You picked %d ... \n", choice ); */
        switch( choice )
        {

        } /* end switch */

    } /* end for ... */
    return 0;
}

This post has been edited by David W: 22 April 2009 - 10:06 PM

Was This Post Helpful? 0
  • +
  • -

#14 David W   User is offline

  • DIC supporter
  • member icon

Reputation: 298
  • View blog
  • Posts: 1,839
  • Joined: 20-September 08

Re: I need help writing a registration program

Posted 21 April 2009 - 05:45 AM

Quote

class Date 
{
	public:
	Date( int=1, int=1, int=1900);
	void print() const;
	~Date();
	private:
	int month;
	int day;
	int year;
	int checkDay(int);
};


You may like to see here re. some working C++ and C 'dates' ...

http://developers-he.../index.p...opic,106.0.html
Was This Post Helpful? 0
  • +
  • -

#15 David W   User is offline

  • DIC supporter
  • member icon

Reputation: 298
  • View blog
  • Posts: 1,839
  • Joined: 20-September 08

Re: I need help writing a registration program

Posted 22 April 2009 - 06:54 PM

This copy of the C++ 'snippet' recently submitted (using the STL 'list' container instead of the STL 'vector' container) to hold C++ objects of class Student ... may give you some ideas ... and some working code ... i.e a working shell from which to start ...

// A simple example of Student records ...
// using a C++ 'list' container to hold each 'Student' element

// 1. adds info from keyboard into a list of 'Student' records (using push_back)
// 2. shows the 'records' in memory on the screen
// 3. writes to file ...         all the records in memory
// 4. reads from file and stores all the records in memory (in a C++ list)
// 5. allows edit/erase ... to a Student record
// 6. sorts Student records by student name ...
// 7. sorts Student records by student id number ...
// Note:
// * this program allows only unique student id's for each record
// * this program is set to update its file, (if there were any changes),
//   before quitting

#include <fstream>
#include <iostream>
#include <string>
#include <list>
#include <cctype>

// Globals ...
using namespace std;
const char THIS_TERM[] = "fall.txt"; // file name for this term's records
const string MENU = "\nWhat do you want to do ?\n\n"
                    "\t1. A dd a new student name and id ? \n"
                    "\t2. E dit/E rase a student record ? \n"
                    "\t3. S ort student records ? \n"
                    "\t4. V iew all in memory at present ? \n"
                    "\t5. U pdate file with data currently in memory ? \n"
                    "\t6. L oad in data from file ? \n"
                    "\t7. e X it program ? ";
                        
class Student
{
public:
    // constructors ...
    Student(){}
    Student(string nam, string num ) { name=nam; id=num; }
    
    // setters ...
    void setName(string nam){ name = nam; }
    void setID(string num) { id = num; }

    // getters ...
    string getName() { return name; }
    string getID() { return id; }
private:
    string name, // add any needed info here, just like in a C/C++ 'struct'
           id;
};


// functions used by main to process a list of Student records

// returns a valid iterator if ID is used already ... otherwise returns NULL
list< Student >::iterator existID( list< Student >& term, string& ID )
{
    list< Student >::iterator it;
    for( it = term.begin(); it != term.end(); ++it )
    {
        if( it->getID() == ID )
            return it;
    }
            
    return NULL;
}

// adds Student records to end of end of list of Student records ... 'term'
// gets input from keyboard ...
int newStud( list< Student >& term )
{
    cout << "\nEnter an empty record to exit this 'Input Loop' ..." << endl;
    int count = 0, reply;
    string nam, num;
    for( ;; ) // loop forever until break ...
    {
        cout << "\nID   : ";
        getline(cin, num);
        if( existID( term, num ) != NULL )
        {
            cout << "\nThat 'id' " << num << " already exits ... " << endl;
            continue; // from the top of the forever loop right now
        }
        cout << "Name : ";
        getline(cin, nam);
        if( nam=="" || num=="")
            break;

        cout << "Add or Redo (a/r) ? ";
        reply=cin.get();
        cin.sync();
        if ( toupper(reply)!='A' )
        {
            cout << "Aborted ..." << endl;
            continue;
        }
        
        // ok ... create and add this record to the end of the list ...
        term.push_back( Student(nam, num) );
        ++count;
        cout << "Added ..." << endl;
    }
    return count;
}

// shows (to console screen) all student records in list container ... 'term'
void viewStuds( list< Student >& term )
{
    list< Student >::iterator it;
    int i = 0;
    for( it = term.begin(); it != term.end(); ++it )
    {
        cout << ++i << ".\n"
             << "Name   : " << it->getName() << endl
             << "Number : " << it->getID() << endl;
    }
}

// file all records in memory ... create/overwrite file with name 'THIS_TERM'
int fileStuds( list< Student >& term )
{
    ofstream fout( THIS_TERM );  // recall 'THIS_TERM' is a Global variable
    if ( !fout )
    {
        cout << "\nError attempting to open file ..." << endl;
        return -1;    // report error condition ...
    }

    // else ...
    list< Student >::iterator it;
    int i = 0;
    for( it = term.begin(); it != term.end(); ++it )
    {
        fout << it->getName() << "," << it->getID() << endl;
        ++i;
    }
    
    fout.close();
    
    if( i == (int)term.size() )
        cout << "\nAll " << i << " records filed ok." << endl;
    else
        cout << "\nOnly " << i << " of " << term.size()
             << " records were written ..." << endl;
             
    return i; // report success ... i.e. report count of records filed
}

// reads in all Student records from file 'THIS_TERM' ... if it exists
// returns -1 if no file exists; else returns the number of records read
int readStuds( list< Student >& term )
{
    ifstream fin( THIS_TERM ); // recall THIS_TERM is a Global variable
    if ( !fin )
    {
        cout << "Error attempting to open file ... "
             << "(Perhaps it dosen't exist yet?)" << endl;
        return -1;          // report error condition ...
    }

    // else ... check existing term.size() first before re-setting?
    if( term.size() ) // i.e. if not == 0 ...
    {
        cout << "\nDo you want over-write the " << term.size()
             << " records in memory (y/n) ? " << flush;
        int reply = toupper( cin.get() );
        cin.sync();
        if( reply != 'Y' )
        {
            cout << "Aborted ... " << flush;
            return 0;
        }
        // if reach here ...
        cout << "Ok ... will over-write the " << term.size()
             << " records in memory ... " << flush;
    }
    
    // if reach here ...
    list < Student > temp; // create a new emty list
    term = temp; // set term to empty list ...
    string nam, num;
    int i;
    for( i=0; getline( fin, nam, ',' ); ++i ) //first get 1st string (up to ',')
    {
        getline( fin, num, '\n' ); // then get rest of line (up to '\n')
        term.push_back( Student(nam, num) ); // construct and add new Student
    }
    fin.close();
    return i; // report success? ... i.e. return the record count ...
}

// returns 'true' if a record was edited or erased; otherwise returns false
bool editStud( list< Student > &term )
{
    cout << "\nEnter an empty record to exit this 'Edit/Erase Function' ..."
         << "\nEnter the ID of the student record to edit ? " << flush;
    string idStr, nam;
    getline( cin, idStr );

    list< Student >::iterator i, index;
    i =  existID( term, idStr );
    if( i == NULL )
    {
        cout << "This '" << idStr << "' does not exist." << endl;
        return false;
    }
    
    // else ... show ... and ask if ok to edit ...
    cout << "Name   : " << i->getName() << endl
         << "Number : " << i->getID() << endl
         
         << "Ok to edit/erase (y/n) ? " << flush;
         
    int reply = toupper( cin.get() );
    cin.sync();
    if( reply != 'Y' )
    {
        cout << "Aborted ... " << endl;
        return false;
    }
    
    cout << "\nDo you want to erase this record (y/n) ? " << flush;
    reply = toupper( cin.get() );
    cin.sync();
    if( reply == 'Y' )
    {
        term.erase( i );
        cout << "Erased ..." << endl;
        return true;
    }
        
    
    // else ...
    
    cout << "\nNew ID   : ";
    getline(cin, idStr);
    index = existID( term, idStr );
    if( index != NULL && index!= i )
    {
        cout << "\nThat " << idStr << " already exits ... " << endl;
        return false; // exit to menu now ...
    }
    
    cout << "New Name : ";
    getline(cin, nam);
    if( nam=="" || idStr=="")
        return false;

    cout << "Ok or Redo (o/r) ? ";
    reply=cin.get();
    cin.sync();
    if( toupper(reply)!='O' ) // cap 'O' ... as in Ok
    {
        cout << "Aborted ..." << endl;
        return false;
    }

    // ok ... do edit
    i->setName( nam );
    i->setID( idStr );
    cout << "Edited ..." << endl;
    return true;
}

// name comparison here is NOT case sensitive ...
bool compare_nocaseName(Student& first, Student& second)
{
  unsigned int i=0;
  while( i<first.getName().length() && i<second.getName().length() )
  {
    if( tolower(first.getName()[i]) < tolower(second.getName()[i]) ) return true;
    else if( tolower(first.getName()[i]) > tolower(second.getName()[i]) ) return false;
    ++i;
  }
  if( first.getName().length() < second.getName().length() ) return true;
  else return first.getID() < second.getID();;
}

bool compare_id(Student& first, Student& second)
{
    return first.getID() < second.getID();
}

void pauseForEnter()
{
    cout << "\nPress 'Enter' to continue ... " << flush;
    cin.sync();
    cin.get();
}



int main()
{
    // create a 'fall list' to hold student names and ids for the 'Fall Term'
    // also holds number of records, via 'fall.size()'
    list <Student > fall;

    // now get all records from file ... if it exists ?
    int count = readStuds( fall );
    if( count >= 0 )
        cout << count << " student record(s) read into memory ..." << endl;
    else
        cout <<"(The file will be created when some student records exist.)"
             <<endl;

    bool changes = false; // set 'update file flag' to initial value ...
    int reply;
    for( ;; ) // loop forever ... until break ...
    {
        cout << MENU;
        reply = toupper(cin.get());
        cin.sync(); // flush cin stream ...

        if( reply == '1' || reply == 'A' )
        {
            int numStuds = newStud( fall );
            cout << endl << numStuds << " student record(s) added ..."
                 << " The total number of student records now is "
                 << fall.size() << endl;
            if( numStuds )
                changes = true; // if >0 update bool variable changes
        }
        else if( reply == '2' || reply == 'E' )
        {
            if( editStud( fall ) )
                changes = true;
        }
        else if( reply == '3' || reply == 'S' )
        {
            cout << "\nSort by id or name  (i/n) ? " << flush;
            reply = toupper( cin.get() );
            cin.sync();
            cout << "Now sorted in memory by ";
            if( reply == 'I' )
            {
                fall.sort(compare_id);
                cout << "id. ";
            }
            else
            {
                fall.sort(compare_nocaseName);
                cout << "name. ";
            }
            cout << "Update file (y/n) ? " << flush;
            reply = toupper( cin.get() );
            cin.sync();
            if( reply == 'Y' )
            {
                changes = true;
                cout << "File to be updated ...\n";
            }
        }
        else if( reply == '4' || reply == 'V' )
            viewStuds( fall );
        else if( reply == '5' || reply == 'U' )
        {
            if( !changes )
                cout << "\nNo changes to file ..." << endl;
            else
            {
                cout << "Are you sure you want to update the file (y/n) ? "
                     << flush;
                reply = toupper( cin.get() );
                cin.sync();
                if( reply == 'Y' )
                {
                    if( fileStuds( fall ) != (int)fall.size() )
                        cout << "\nUNEXPECTED ERROR! NOT all records were filed!"
                             << "\nTry again ... If Error persits call IT."
                             << endl;
                    else
                    {
                        changes = false;// update file flag ...
                        cout << "File write operation confirmed." << endl;
                    }
                }
            }
        }
        else if( reply == '6' || reply == 'L' )
        {
            int condition = readStuds( fall );
            if(  condition >= 0 )
            {
                cout << "\nThere were " << condition
                     << " student records read into memory from file." << endl;
                changes = false;
            }
        }
        else if( reply == '7' || reply == 'X' )
        {
            if( changes ) // then ...
                fileStuds( fall );
            break; // and exit program ...
        }
        else
        {
            cout << "\nThis choice not implemented yet ... " << endl;
        } // end of if( reply == ? ) switch structure ...

    } // end of forever loop ...


    // debug exit routine ...

    ifstream ftest( THIS_TERM );  // recall 'THIS_TERM' is a Global variable
    if ( !ftest )
    {
        cout << "\nError attempting to open file ..." << endl;
        pauseForEnter();
        return -1;    // report error condition ...
    }
    
    // if reach here ... first ...
    ftest.close();
    
    // then ... proceed ... to open the file in a system text editor ...

    // if you have a Win OS ... show structure of file
    string tmpSee = " ";
    tmpSee = "notepad" + tmpSee + THIS_TERM;
    system( tmpSee.c_str() );
}

This post has been edited by David W: 22 April 2009 - 10:09 PM

Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2