Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Omniverse Venting Thread
#27
ANYONE THAT KNOWS CPP, PLEASE, FOR THE LOVE OF CHRIST HELP ME

I WILL LITERALLY FIND YOU AND SUCK YOU OFF IF YOU DO AND ASK ME TO

For some god awful reason, cin.clear() and cin.ignore() are not even functioning, creating an infinite loop, and thus a segmentation fault because too much memory.

student.h

Code:
#include <fstream>
#include <iostream>
#include <cstring>
#include <string>
#include <iomanip>
#include <cstdlib>
#ifndef STDNT
#define STDNT
using namespace std;

class student{
    private:
        float hpTotalScore, testsTotalScore;
        float gradeInt;
        int stuHomeworkParticipationScores[11];
        int stuTestScores[4];
        char letGrade;
        string stuID, stuName, stuLname;
    public:
        string setName(string name, string lastName);
        string setID(string id);
        int setHPScores(int hpScores[11]);
        int setTestScores(int tScores[4]);
};
#endif

student.cpp

Code:
#include <fstream>
#include <iostream>
#include <cstring>
#include <string>
#include <iomanip>
#include <cstdlib>
#include "student.h"

string student::setID(string id)
{
    stuID = id;
}

string student::setName(string name, string lastName)
{
    stuName = name;
    stuLname = lastName;
}

int student::setHPScores(int hpScores[10])
{
    for (int i=0;i<11;i++)
    {
        stuHomeworkParticipationScores[i]=hpScores[i];
    }
}

int student::setTestScores(int tScores[4])
{
    for (int i=0;i<4;i++)
    {
        stuTestScores[i]=tScores[i];
    }
}

studentList.h

Code:
#include <fstream>
#include <iostream>
#include <cstring>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <vector>
#include "student.h"
#ifndef STDNTLST
#define STDNTLST
using namespace std;

class studentList{
    private:
        unsigned int maxSize;
        int nameLength, idLength;
        vector<student> stuList;
    public:
        /*stuList (unsigned int size=0)
        {
            nameLength=student::nameLength;
        }*/
        bool addStudent(student);
    //    void writeData(ostream& outfile, student);
};
#endif

studentList.cpp

Code:
#include <fstream>
#include <iostream>
#include <cstring>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <vector>
#include "studentList.h"
#include "student.h"

bool studentList::addStudent(student st)
{
    if ((stuList.size())>=maxSize)
        return false;
    stuList.push_back(st);
    return true;
}

/*void studentList::writeData(ostream& outfile, student)
{
    outfile << student;
}*/

main.cpp

Code:
#include <fstream>
#include <iostream>
#include <cstring>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <vector>
#include "student.h"
#include "studentList.h"
using namespace std;

const int fileNameSize=20;
ofstream outFile;
//char inputFileName [fileNameSize+1];
//char outputFilename [fileNameSize+1];
studentList stList;
string id, name, lastName;
    
void showmenu()
{
    cout << "Please type in one of the following opotions: \n";
    cout << "L or l to load the student list \n";
    cout << "D or d to display the student data \n";
    cout << "P or p to process grades\n";
    cout << "C or c to change a student \n";
    cout << "A or a to add a student. \n";
    cout << "S or s to search for a particular student's information \n";
    cout << "R or r to print the total grades and letter grade \n";
    cout << "M or m to display this menu \n";
    cout << "E or e to save and exit \n";
}

void loadStudents()
{
    //choice='1';
    //char temp=choice;
    int hpScores[10];
    int tScores[4];
    ifstream inFile;
    cout << "infile flag";
    student st;
    string fileName;
    cout << "What is the file we are reading from? \n";
    cin >> fileName;
    cout << "Loading students... \n";
    inFile.open(fileName.c_str());
    cout << "open check";
    if (!inFile)
    {
        cout << "Error, could not load/find file.";
        inFile.close();
        inFile.clear();
        return;// choice;
    }
    inFile >> lastName;
    inFile >> name;
    st.setName(name, lastName);
    while (!inFile.eof())
    {
        //cout << "open flag";
        cout << lastName; cout << " " << name;
        inFile >> id; st.setID(id);
        cout << " " << id;
        for(int i=0;i<10;i++)
        {
            inFile >> hpScores[i];
            cout << " " <<hpScores[i];
        }
        st.setHPScores(hpScores);
        for(int i=0;i<4;i++)
        {
            inFile >> tScores[i];
            cout << " " <<tScores[i];
        }
        st.setTestScores(tScores);
        stList.addStudent(st);
        inFile >> name;
        inFile >> lastName;
        st.setName(name, lastName);
    }
    //cout << "flag6";
    //return choice;
    string wastedata;
    getline(cin, wastedata);
    inFile.close();
    inFile.clear();
}

void displayStudentProfile()
{
    cout << "Displaying data...\n";
}

void processGrades()
{
    cout << "Processing grades... \n";
}

void changeGrades()
{
    cout << "Changing student grade(s)...\n";
}

void addStudent()
{
    cout << "Adding student... \n";
}

void searchStudent()
{
    cout << "Searhing student...\n";
}

void saveInfo()
{
    cout << "Saving data...";
}

void printGrades()
{
    cout << "Printing total grades and letter grade...";
}

int main()
{
    int ilchk=0;
    char choice='m';
    string wastedata;
    showmenu();
    cout << "Please indicate your choice of operation (m for menu): ";
    cin >> choice;
    while((choice!='e')&&(choice!='E') and ilchk<5)
    {
        switch(choice)
        {
            case 'l':
            case 'L': loadStudents(); cin.ignore(400, '\n'); cin.clear(); getline(cin, wastedata); break;
            case 'd':
            case 'D': displayStudentProfile(); cin.ignore(400, '\n'); cin.clear(); getline(cin, wastedata); break;
            case 'p':
            case 'P': processGrades(); cin.ignore(400, '\n'); cin.clear(); getline(cin, wastedata); break;
            case 'c':
            case 'C': changeGrades(); cin.ignore(400, '\n'); cin.clear(); getline(cin, wastedata); break;
            case 'a':
            case 'A': addStudent(); cin.ignore(400, '\n'); cin.clear(); getline(cin, wastedata); break;
            case 's':
            case 'S': searchStudent(); cin.ignore(400, '\n'); cin.clear(); getline(cin, wastedata); break;
            case 'r':
            case 'R': printGrades(); cin.ignore(400, '\n'); cin.clear(); getline(cin, wastedata); break;
            case 'm':
            case 'M': showmenu(); cin.ignore(400, '\n'); cin.clear(); getline(cin, wastedata); break;
            case 'e':
            case 'E': cin.ignore(400, '\n'); cin.clear(); getline(cin, wastedata); break;
            default : cout << "Invalid command." << endl;
        }
        cout << "Please indicate your choice of operation (m for menu): ";
        cin >> choice;
        ilchk++;
    }
    saveInfo();
    cout << "Thank you, have a good one!\n";
}

studentProfs.txt

Code:
Pondicherry, John XPQ23456 91 48 76 23 91 91 84 95 93 81 76 84 91 73
Quincy, Jane XPL27856 81 58 76 40 49 91 84 89 93 90 79 94 81 73
Ahrens, Thomas QER67087 99 99 99 99 99 99 99 99 99 99 99 99 99


PLEASE I'LL DO ANYTHING!
"Our fear is our weapon."


Messages In This Thread
Omniverse Venting Thread - by Aadibah - 02-27-2017, 08:24 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)