:cry:

Please help me,I'm a bigginner programmer.

I have to send a project after tomorrow .

My project is "Student Library".

Programmed :

-->Shor menu for user to select :
a)add : student id,name,score(mid,final)
b)delete
c)modify
d)list by id

like this --

***and in add menu user must not insert the same id***

I don't know how to add delete and modify and how to check if it match the old one..

I really don't know...please help

May be some of you write some code for me to learn more

#ifndef PROJ_H
#define PROJ_H

/*------------------------------------------------------------*/

enum ScoreIndex {Midterm,Lab,Final,Total};
enum GradeType {A,B,C,D,F};

unsigned short ScoreType;
unsigned int IDType;

const int NAMELENGTH=40;

struct Student{
       IDType sid;
       char name[NAMELENGTH];
       GradeType grade;
       ScoreType scores[Total+1];
};
/*------------------------------------------------------------*/

IDType getID();

void getName(char name[],int size);

ScoreType getMidterm();

ScoreType getLab();

ScoreType getFinal();

void displayStuTable(const Student stusrec[],int size);

void displayStuHL(const Student sturec[],int index);
       
/*------------------------------------------------------------*/

void addRecord(Student StuRec[],int maxsize);

void deleteRecord(Student StuRec[],int maxsize);

void modifyRecord(Student StuRec[],int maxsize);

double computeAverage (const Student StuRec[],short size);

short getMaxIndex (const Student StuRec[],short size);

short getMinIndex (const Student StuRec[],short size);

GradeType getGrade (ScoreType score);

void totGrade (const Student StuRec[],short size,short freq[]);

void bsortID(Student sturec[], short size);

void bsortScore(Student sturec[], short size);

/*------------------------------------------------------------*/

#endif
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include <iomanip>
using std::setw;
using std::left;

#include "proj.h"

/*------------------------------------------------------------*/
IDType getID()
{
    IDType sid; 
    cout<<"\nPlease,Enter Student ID : ";
    cin>>sid; 
    cin.ignore(80,'\n'); 
    return sid; 
}

void getName(char name[],int size)
{
     char buffer[40];
     cout<<"Please,Enter Student Name : ";
     cin.getline(buffer,40);
     //strcpy(name,buffer);
     for (int i = 0; i < size; ++i)
         name[i] = buffer[i]; 
     name[size - 1] = '\0';
}

ScoreType getMidterm()
{
      ScoreType score;
      cout<<"Please,Enter Midterm Score [0-20] : ";
      cin>>score;
      cin.ignore(80,'\n'); 
      return score;    
}

ScoreType getLab()
{
      ScoreType score;
      cout<<"Please,Enter Lab Score [0-30] : ";
      cin>>score;  
      cin.ignore(80,'\n'); 
      return score;  
}

ScoreType getFinal()
{
      ScoreType score;
      cout<<"Please,Enter Final Score [0-50] : ";
      cin>>score; 
      cin.ignore(80,'\n'); 
      return score;    
}

void displayStuTable(const Student stusrec[],int size)
{   
        cout<<setw(7)<<"ID  "
            <<setw(30)<<left<<" Name"
            <<setw(7)<<"Midterm"
            <<setw(5)<<"Lab"
            <<setw(5)<<"Final"
            <<setw(5)<<"Total";
    for (int i = 0; i < size; ++i)
    {
        cout<<setw(7)<<stusrec[i].sid<<"  "
            <<setw(30)<<left<<stusrec[i].name
            <<setw(7)<<stusrec[i].scores[Midterm]
            <<setw(5)<<stusrec[i].scores[Lab]
            <<setw(5)<<stusrec[i].scores[Final]
            <<setw(5)<<stusrec[i].scores[Total];
            
        switch (stusrec[i].grade)
        { case A: cout<<setw(5)<< 'A' <<endl; break;
          case B: cout<<setw(5)<< 'B' <<endl; break;
          case C: cout<<setw(5)<< 'C' <<endl; break;
          case D: cout<<setw(5)<< 'D' <<endl; break;
          case F: cout<<setw(5)<< 'F' <<endl; break;
        }
     }        
     cout<<endl;
}

void displayStuHL(const Student sturec[],int index)
{
     cout<<sturec[index].sid<<' '<<left<<setw(30)<<sturec[index].name<<' '
         <<sturec[index].scores[Midterm]<<' '<<sturec[index].scores[Lab] 
         <<' ' << sturec[index].scores[Final] << ' ' 
         <<sturec[index].scores[Total]<<' '; 
         
     switch (sturec[index].grade){ 
          case A: cout<< 'A' ; break;
          case B: cout<< 'B' ; break;
          case C: cout<< 'C' ; break;
          case D: cout<< 'D' ; break;
          case F: cout<< 'F' ; break;
     }
     cout<<endl;
}
/*------------------------------------------------------------*/
void addRecord(Student sturec[], int maxsize)
{
     int counter = 0;
     while ( counter < 100 ) {
     int i = 0;
     sturec[i].sid = getID();
     int id=sturec[i].sid;
     for( ; i < 100; i++) {
     if ( id != sturec[i].sid) {
     getName(sturec[i].name, NAMELENGTH);
     sturec[i].scores[Midterm] = getMidterm();
     sturec[i].scores[Lab] = getLab();
     sturec[i].scores[Final] = getFinal();
     sturec[i].scores[Total] = sturec[i].scores[Midterm] + 
                        sturec[i].scores[Lab] + sturec[i].scores[Final];
     sturec[i].grade = getGrade(sturec[i].scores[Total]); 
     
     cout<<"\nNew Record ("<<sturec[i].sid<<") Added successfully\n";break;}
     
     else cout<<"A student record with the ID already exists"
              <<"\nPlease enter again.";
     }
     counter++; break;}
     cout<<"You can not add records more than 100 records.";
}

void deleteRecord(Student sturec[], int maxsize)
{    
     for (int i=0;i<100;i++)
         if ( getID() == sturec[i].sid){
              //delete sturec[i];
              sturec[i].sid=0;}
     
}
void modifyRecord(Student sturec[], int maxsize)
{    int i=0;
     for (;i<100;i++)
         if ( getID() == sturec[i].sid){
              //delete sturec[i];
              sturec[i].sid=0;}
              sturec[i].sid = getID();
              getName(sturec[i].name, NAMELENGTH);
              sturec[i].scores[Midterm] = getMidterm();
              sturec[i].scores[Lab] = getLab();
              sturec[i].scores[Final] = getFinal();
              sturec[i].scores[Total] = sturec[i].scores[Midterm] + 
                        sturec[i].scores[Lab] + sturec[i].scores[Final];
              sturec[i].grade = getGrade(sturec[i].scores[Total]); 
}

GradeType getGrade(ScoreType score)
{
    switch (score/10)
    { case 10:
      case 9: return A;
      case 8: return B;
      case 7: return C;
      case 6: return D;
      case 5:
      case 4:
      case 3:
      case 2:
      case 1:
      case 0: return F;
    }    
}

double computeAverage(const Student sturec[], short size)
{
   if(size>0) 
   {
     int sum = sturec[0].scores[Total];
     for(int i = 1; i < size; ++i)
       sum += sturec[i].scores[Total];
       
     return static_cast<double>(sum)/size; 
   }
   else return 0.0;
}

short getMaxIndex(const Student sturec[], short size)
{
    short index = -1;
    if(size>0) 
    {
       index = 0;
       for(int i = 1;i<size;++i)
           if(sturec[i].scores[Total] > sturec[index].scores[Total])
               index = i;
    }
    return index;
}    

short getMinIndex(const Student sturec[], short size)
{
    short index = -1;
    if(size>0) 
    {
       index = 0;
       for(int i = 1;i<size;++i)
           if(sturec[i].scores[Total] < sturec[index].scores[Total])
               index = i;
    }
    return index;
}    

void totGrade(const Student sturec[], short size, short freq[])
{
   freq[A] = freq[B] = freq[C] = freq[D] = freq[F] = 0; 
   if(size>0) 
     for( int i=0; i < size; ++i)
         freq[sturec[i].grade]++ ; 
}

void bsortID(Student sturec[], short size)
{
    for (int i = 0; i < size - 1; i++)
        for (int j = 0; j < size - 1 - i; j++)
             if (sturec[j].sid > sturec[j+1].sid)
             {
                 Student tmp = sturec[j];
                 sturec[j] = sturec[j+1];
                 sturec[j+1] = tmp;
             }
}

void bsortScore(Student sturec[], short size)
{
    for (int i = 0; i < size - 1; i++)
        for (int j = 0; j < size - 1 - i; j++)
             if (sturec[j].scores[Total] > sturec[j+1].scores[Total])
             {
                 Student tmp = sturec[j];
                 sturec[j] = sturec[j+1];
                 sturec[j+1] = tmp;
             }
}
/*------------------------------------------------------------*/
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
using std::fixed;

#include <iomanip>
using std::setprecision;

#include "proj.h"  

int main () 
{
    const short MaxStudentSize = 100;
    Student students[MaxStudentSize]; 
    short counter = 0; 
    double average; 
    short highindex,lowindex;  
    short frequency [F+1] = {0}; 
    int choice;
    do
   {  
      start:
      cout<<"  1. Add a new student record\n"	
          <<"  2. Delete a student record\n"
          <<"  3. Modify a student record\n"
          <<"  4. List all records by student ID\n"
          <<"  5. List all records by total scores\n"
          <<"  6. Show Grade Statistics\n"	
          <<"  7. Quit\n";
          
      cout << "Please,enter your choice : ";
      cin >> choice; 
      
      switch(choice){
      case 1 ://add
           counter++;
           addRecord(students, MaxStudentSize);goto start;
           break;
      
      case 2 ://delete
           deleteRecord(students, MaxStudentSize);
           break;
      
      case 3 ://modify
           modifyRecord(students, MaxStudentSize);
           break;
    
      case 4 ://List ID
           cout << "\t\tList of All Students by ID Number\n"; 
           bsortID(students, counter);
           displayStuTable(students,counter);
           break;

      
      case 5 ://List score
           cout << "\t\tList of All Students by TotalScore\n"; 
           bsortScore(students, counter);
           displayStuTable(students,counter);
           break;

      
      case 6 ://Show Stat
           bsortID(students, counter);
           average = computeAverage(students, counter);
           totGrade(students, counter, frequency);
           highindex = getMaxIndex(students, counter);
           lowindex = getMinIndex(students, counter);
    
          
        cout << "\tNumber of Students: " << counter << "\tAverage: "
             << fixed << setprecision(2) << average << endl;
                   
        cout << " Numbers of Grade A : "   << frequency[A] 
             << "\n Numbers of Grade B : " << frequency[B]
             << "\n Numbers of Grade C : " << frequency[C] 
             << "\n Numbers of Grade D : " << frequency[D]
             << "\n Numbers of Grade F : " << frequency[F] << endl;
           
        cout << "Highest Score : ";
        displayStuHL(students, highindex);
        cout << "Loweset Score : ";
        displayStuHL(students,lowindex);
        break;
    
       case 7 : break;
      default : "The number should be  1 - 7 : Try again.\n"; }
         goto start; 
   } while (choice!=7);
   
    system("PAUSE");
    return 0;
}

All you need is to have some data structure and look for the record ID in the data structure for duplicates before you carry out operations like add.

I would suggest that you at least use an array. You could use a liner search algorithm to look for existing records.

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

Programming ( Assignment / Project ) Help

can anyone show the right code for me

I really need it

Nothing

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.