Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  mmm
Language: C/C++
Code:
#include <iostream>
//#include<stdio.h>
#include <fstream>
#include<string>
//#include <iomanip>
using namespace std;
ifstream indata;
ofstream outdata;
void addStudent(int i)
{
     int id, grade, average;
     char name[100], lname[100];
     cout << "enter ID of student" << i  << endl;
     cin >> id;
     cout << "enter Name of student" << i  << endl;
     cin >> name;
     cout << "enter LastName of student" << i << endl;
     cin >> lname;
     cout << "enter Grade of student" << i  << endl;
     cin >> grade;
     cout << "enter Average of student" << i << endl;
     cin >> average;
     outdata << id << "," << name << "," << lname << "," << grade << "," << average << endl;
}
void main()
{
     outdata.open("excel.csv");
     int num, numberOfStudent =0;
     char ch[100];
     string row[100];
     outdata << "studentID,Name,LastName,Grade,Average" << endl;
     for (int i = 0; i < 5; i++)
     {
          numberOfStudent++;
          addStudent(numberOfStudent);
     }
     bool condition = true;
     int studentid,idnum[100];
     while (condition)
     {
          cout << "\nmenu\n1:show all\n2:del\n3:add\n4:search\n5:end\n";
          cin >> num;
          int j = 0;
          int loopCounter = numberOfStudent;
          switch (num)
          {
               case(1) :
                    indata.open("excel.csv");
                    indata >> row[0];
                    cout << row[0] << endl;
                    for (int i = 0; i < numberOfStudent; i++)
                    {
                         indata >> idnum[j];
                         indata >> row[j+1];
                         cout << idnum[j] << row[j + 1] << endl;
                         j++;
                    }
                    indata.close();
               break;
               case(2) :
                    cout << "enter StudentID:" << endl;
                    cin>> studentid;
                    indata.open("excel.csv");
                    indata >> row[0];
                    for (int i = 0; i < loopCounter; i++)
                    {
                         indata >> idnum[j];
                         indata >> row[j+1];
                         if (idnum[j] == studentid)
                         {
                              cout << row[0] << endl;
                              cout << idnum[j] << row[j + 1] << endl;
                              cout << "delet?(y/n)" << endl;
                              char confirm;
                              cin >> confirm;
                              if (confirm == 'y')
                              {
                                   j--;
                                   numberOfStudent--;
                              }
                        }
                         j++;
                    }
                    indata.close();
                    outdata.close();
                    outdata.open("excel.csv");
                    outdata << row[0]<<endl;
                    for (int i = 0; i < numberOfStudent; i++)
                    {
                         outdata << idnum[i] << row[i + 1] << endl;
                    }
               break;
               case(3) :
                    numberOfStudent++;
                    addStudent(numberOfStudent);
                    break;
               case(4) :
                    cout << "enter StudentID:" << endl;
                    cin >> studentid;
                    for (int i = 0; i < numberOfStudent; i++)
                    {
                         indata >> idnum[j];
                         indata >> row[j + 1];
                         if (idnum[j] == studentid)
                         {
                              cout << row[0] << endl;
                              cout << idnum[j] << row[j + 1] << endl;
                         }
                         j++;
                    }
                    break;
               case(5) :
                    condition = false;
                    break;
          }
     }
     return 0;
}     
Comments: