A Student's Mark Database

This is a discussion on A Student's Mark Database within the C++ Programming forums, part of the General Programming Boards category; Hi, I am in Electrical Engineering at UofT and I have to take a C++ programming course. I have never ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    1

    A Student's Mark Database

    Hi,

    I am in Electrical Engineering at UofT and I have to take a C++ programming course. I have never taken a programming course in highschool or anywhere else and I am having great difficulty understanding C++. I have read the tutorials and they are useful to some degree, but the assignments that I get seem to be far more complicated for me to understand.

    I have to implement a database to store and retrieve student marks in a school term. There will be an implementation of two classes: studentRecord and studentDB. The studentRecord class will be used to create objects that hold a single
    studentís information. The studentDB class will be used to create a database of studentRecord objects. I have to implement two variants of the studentDB class; one is array based, while the other is linked-list based.


    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    For my arrayDriver Program This is what I have:

    Code:
    */
    
      #include <iostream> //required for cin and cout
      #include <iomanip>  //input/output manipulation
      #include <cctype>   //required by tolower()
      #include <cstring>  //required by strlen()
      
      
      using namespace std;
    
    //Function: New Command.
    bool stnumber(int stnum1)
    { 
      if(stnum1 > 999999999)                               
      {  
        cout<<"Error number is too large."<<endl;  //Prints error if stnum1 is greater than 9 digits.
        return false;
      }
      return true;
    }
    
    //Function: Locate Command (Similar to New command code).
    bool stnumbertwo(int stnum1)
    {
      
      
      if(stnum1 > 999999999)
      {
        cout<<"Error number is too large."<<endl;
        return false;
      }
      cout<<"Locate: " <<setw(9) << setfill('0') << stnum1<<endl;  //Fills blank digits with '0' digit. 303-> 000000303 
      
    }
    
    //Function: Updatename Command (Similar to New Command code except takes in three parameters). 
    bool stnumberthree(int stnum1, char lastname[], char firstname[])
    {
      if(stnum1 > 999999999)
      {
        cout<<"Error: " << stnum1 << " is too large."<<endl;
        return false;
      }
      
      cout<< "Updatename: " <<stnum1 << " " << firstname<< " " << lastname<< " "<<endl; //Switch firstname with lastname.
    }
    
    
    //Function: Delete Command (Similar to New command code).
    
    bool stnumberthree(int stnum1)
    {
      
      
      if(stnum1 > 999999999)
      {
        cout<<"Error number is too large."<<endl;
        return false;
      }
      else {
        cout<<"Delete: " <<setw(9) << setfill('0') << stnum1<<endl;
        
      }
    }
    
    
    /* Main Method: While not at the end of the file, (Ctrl + D) to exit, keep waiting for the user to supply commands and its parameters. It first takes in the command and compares it to one of the following predefined commands implemented in this program.  If the user-supplied command matches one of
                    the predefined commands then it asks the user for the different parameters each command has. 
    		The program checks for any mistakes the user may supply and outputs an error message. Otherwise
    		it outputs whatever it has to based on the commands entered.
    */
    
    int main()
    {
     while(!cin.eof())   
      {
        char command[20]={0};
        cin >> command;
        
        if (strcmp(command,"new") == 0)
        {
          int stnum;            
          if (!(cin>>stnum))
          {
            cout << "Error: argument is not a number." << endl;
            cin.clear();
            cin.ignore(1000,'\n');
            continue;
          }
          if (stnumber(stnum) == false)
          {
            cin.clear();
            cin.ignore(1000, '\n');
            continue;
          }
          cout << "New: " << setw(9) << setfill('0') << stnum << endl;
        } 
        
        else if (strcmp(command,"locate") == 0)
        {
          int stnum;
          if (!(cin>>stnum))
          {
            cout << "Error: argument is not a number." << endl;
            cin.clear();
            cin.ignore(1000,'\n');
            continue;
          }
          if(stnumbertwo(stnum) == false)
          {
            cin.ignore(1000, '\n');
            continue;
          }
        }
        
        else if (strcmp(command, "delete") == 0)
        {
          int stnum;
          if (!(cin>>stnum))
          {
            cout << "Error: argument is not a number." << endl;
            cin.clear();
            cin.ignore(1000,'\n');
            continue;
          }
          if(stnumberthree(stnum) == false)
          {
            cin.ignore(1000, '\n');
            continue;
          }
        }
        
    
        //Printall Command: - (if command entered is printall then output Printall)
    
        else if (strcmp(command, "printall") ==0)
        {
          cout<<"Printall"<<endl;
        }
        
       
       //Deleteall command: - (if command entered is deleteall then output Deleteall)
    
       else if (strcmp(command, "deleteall") ==0)
        {
          cout<<"Deleteall"<<endl;
        }
        
        else if (strcmp(command, "updatename") ==0)
        {
          int stnum;
          char lname[20];
          char fname[20];
          
          cin>> stnum;
          cin>> lname; 
          cin>> fname;
          if(stnumberthree(stnum, lname, fname)==false)
          {
            cin.ignore(1000, '\n');
            continue;
          }
        }
        
       //Updatemark Command.
        else if (strcmp(command, "updatemark") ==0)
        {
          int stnum;
          int idx;
          int mark;
          
          if (!(cin>>stnum))
          {
            cout << "Error: argument is not a number." << endl;
            cin.clear();
            cin.ignore(1000,'\n');
            continue;
          }  if(stnum > 999999999)
          {
            cout<<"Error: " << stnum << " is too large."<<endl;
            cin.ignore(1000, '\n');
            continue;
            
          }
          if (!(cin>>idx))
          {
            cout << "Error: argument is not a number." << endl;
            cin.clear();
            cin.ignore(1000,'\n');
            continue;
          }  if(idx < 0 || idx > 4)
          {
            cout<<"Error: " << idx<< " is out of the range 0-4."<<endl;
            cin.ignore(1000, '\n');
            continue;
          }
          if (!(cin>>mark))
          {
            cout << "Error: argument is not a number." << endl;
            cin.clear();
            cin.ignore(1000,'\n');
            continue;
          }  if(mark < 0 || mark > 100)
          {
            cout<<"Error: " << mark << " is out of the range 0-100."<<endl; 
            cin.ignore(1000, '\n');
            continue;
          }
          
          cout<<"Updatemark: " <<setw(9) << setfill('0') << stnum << " " << idx << " " << mark <<endl;
        }
        
        else
        {
          if (cin.eof()) break;
          
          cout<<"Error: unknown command."<<endl;
          cin.ignore(1000, '\n');
          continue;
        } 
      }
      return 0;
    }
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    For My StudentRec Class: (There may be a few mistakes)
    
    
    
    # include <iostream>
    # include <iomanip>  
    # include "studentRec.h"
    
    using namespace std;
    
    
    studentRecord::studentRecord()
    {
    studentNumber = 0;
    firstName = new char[100]; 
    lastName =  new char[100];
    
    for (int i=0; i < NUM_OF_MARKS; i++)
    marks[i] = 0;
    }
    }
    
    studentRecord::~studentRecord()
    {
    }
    
    void studentRecord::setStudentNumber (unsigned int studentNum)
    {
    studentNumber = studentNum;
    }
    
    
    void studentRecord::setFirstName(char* firstname)
    {
    for (int i = 0; i < 100; i++)
    {
    *(_firstName + i) = * (firstName + i) 
    }
    
    
    void studentRecord::setLastName(char* lastname)
    {
    for (int i = 0; i < 100; i++)
    {
    *(_lastName + i) = * (lastName + i) 
    }
    
    void studentRecord::setMark(int index, unsigned int mark)
    {
    marks[index] = mark;
    }
    
    
    void studentRecord::getStudentNumber()
    {
    return studentNumber;
    }
    
    
    void studentRecord::getFirstName()
    {
    return _firstName;
    }
    
    
    void studentRecord::getLastName()
    {
    return _lastName;
    }
    
    
    void studentRecord::getMark(int index)
    {
    return mark[index];
    }
    
    
    void studentRecord::print()
    {
    cout << "Student Number: "<< studentNumber << endl;
    
    cout <<"Student Name: " << lastName << firstName << endl;
    
    cout << "Student Marks: ";
    
    for (i = 0; i < 5; i++)
    {
    cout << marks[i] << ", ";
    }
    cout << endl; 
    }
    }
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Any help will be greatly appreciated,

    Thanks,

    Matt

    email: mapper13@hotmail.com
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    1) Don't post anything inside code tags that is wider than one screen width. code tags preserve the exact format of the text, so if you have a sentence that is 3 screens wide, you need to use some carriage returns.

    I have never taken a programming course in highschool or anywhere else and I am having great difficulty understanding C++....

    I have to implement two variants of the studentDB class; one is array based, while the other is linked-list based.
    Ouch.
    For my arrayDriver Program This is what I have:
    What is your question?

    All the defintions of your studentRecord functions should be in a separate file than the one with main() in it. The separate file should have a .cpp extension. At the top of that file, you include studentRecord.h, which contains your class declaration. Then, at the top of your file with main(), all you have to do is include studentRecord.h, and everything will be taken care of.
    Last edited by 7stud; 03-01-2006 at 12:33 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C program using structs to calculate grades
    By TampaTrinDM88 in forum C Programming
    Replies: 4
    Last Post: 07-06-2009, 12:33 PM
  2. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  3. new problem with class
    By jrb47 in forum C++ Programming
    Replies: 0
    Last Post: 12-01-2006, 07:39 AM
  4. Adding Students to a database
    By lofty in forum C++ Programming
    Replies: 3
    Last Post: 01-10-2005, 01:51 PM
  5. Developing database management software
    By jdm in forum C++ Programming
    Replies: 4
    Last Post: 06-15-2004, 04:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21