Ejemplo n.º 1
0
Bob::~Bob()
{
    s_counter--;
    s_sumGrades-=getGrade();
    #ifdef I_AM_REFERENCE_GRADE
        setReferenceGrade(getAverageOfInstitute());
    #endif
}
int main(int argc, char * argv[])
{
    //checks to make sure that there are 2 arguments - one for input and output
    inputCheck(argv);
    
    //Get the input file name...
    char *inputFileName = *(argv + 1);
    char *outputFileName = *(argv + 2);
    
    //Find out how many students are on the input file...
    int numberOfStudents = getRecordCount(inputFileName);
    
    //Create the number of students depending on the record count...
    Student listOfStudents[numberOfStudents];
    createStudents(listOfStudents, numberOfStudents);
    
    //Read the data of the input file...
    FILE *myFile = openFile(inputFileName);
    
    //Fill out all the student's info...
    fillStudentRecord(myFile, listOfStudents, numberOfStudents);
    
    //sortStudents using the array of student struct
    sortStudents(listOfStudents, numberOfStudents);
    
    //Calculate each student's GPA and recorded in the structure...
    getGPA(listOfStudents, numberOfStudents);
    
    //Calculate each student's Letter Grade and record in the structure...
    getGrade(listOfStudents, numberOfStudents);
    
    //Create ClassGrade structure pointer...
    ClassGrade *classGrade;
    classGrade = (ClassGrade *)malloc((sizeof classGrade) * 20);
    
    //Call functions to calculate the scores...
    getScoreAverage(listOfStudents, classGrade, numberOfStudents);
    getMinScore(listOfStudents, classGrade, numberOfStudents);
    getMaxScore(listOfStudents, classGrade, numberOfStudents);
    
    //Generate and output file with the student grade information
    generateOutputFile(outputFileName, inputFileName, listOfStudents, numberOfStudents);
    
    //Print out student's info...
    printAllStudents(listOfStudents, classGrade, numberOfStudents, inputFileName, outputFileName);
    
    return 0;
}
Ejemplo n.º 3
0
void DBFileDialog::sNameGradeChanged()
{
  QString name  = getName();
  QString grade = QString("%1").arg(getGrade());
  QTreeWidgetItem * item = 0;
  for(int i = 0; i < _list->topLevelItemCount(); i++)
  {
    item = _list->topLevelItem(i);
    if(item->text(0) == name && item->text(1) == grade)
    {
      _list->setCurrentItem(item);
      return;
    }
  }
  if(_list->currentItem())
    _list->currentItem()->setSelected(false);
}
Ejemplo n.º 4
0
void DBFileDialog::sNameGradeChanged()
{
  QString name  = getName();
  QString grade = QString("%1").arg(getGrade());
  Q3ListViewItem * item = _list->firstChild();
  while(item)
  {
    if(item->text(0) == name && item->text(1) == grade)
    {
      _list->setCurrentItem(item);
      return;
    }
    item = item->nextSibling();
  }
  if(_list->currentItem())
    _list->setSelected(_list->currentItem(), FALSE);
}
Ejemplo n.º 5
0
int main (void) {
    // Initialize test score with 0
    double testValue = 0.00;

    printf("What did you get on your test? \n");
    scanf("%lf", &testValue);

    // Only call getGrade if we have a valid test score
    if (testValue < 0.00 || testValue < 100.0) {
        printf("Your test score: %lf\n", testValue);
        printf("Your grade is: %c\n", getGrade(testValue));
    }
    else
    {
        printf("That is not a valid test score\n");
    }
    return 0;
}
Ejemplo n.º 6
0
//MTGAllCards
int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primitive)
{
    if ('#' == s[0]) return 1; // a comment shouldn't be treated as an error condition
    size_t i = s.find_first_of('=');
    if (i == string::npos || 0 == i)
        return 0;

    char* key = const_cast<char*> (s.c_str()); // I know what I'm doing, let me do it
    key[i] = 0;
    char* val = key + i + 1;

    switch (key[0])
    {
    case 'a':
        if (0 == strcmp("auto", key))
        {
            if (!primitive) primitive = NEW CardPrimitive();
            primitive->addMagicText(val);
        }
        else if (0 == strncmp("auto", key, 4))
        {
            if (!primitive) primitive = NEW CardPrimitive();
            primitive->addMagicText(val, key + 4);
        }
        else if (0 == strcmp("alias", key))
        {
            if (!primitive) primitive = NEW CardPrimitive();
            primitive->alias = atoi(val);
        }
        else if (0 == strcmp("abilities", key))
        {
            if (!primitive) primitive = NEW CardPrimitive();
            string value = val;
            //Specific Abilities
            std::transform(value.begin(), value.end(), value.begin(), ::tolower);
            vector<string> values = split(value, ',');
            for (size_t values_i = 0; values_i < values.size(); ++values_i)
            {

                for (int j = Constants::NB_BASIC_ABILITIES - 1; j >= 0; --j)
                {
                    if (values[values_i].find(Constants::MTGBasicAbilities[j]) != string::npos)
                    {
                        primitive->basicAbilities[j] = 1;
                        break;
                    }
                }
            }
        }
        break;

    case 'b': //buyback
        if (!primitive) primitive = NEW CardPrimitive();
        if (ManaCost * cost = primitive->getManaCost())
        {
            string value = val;
            std::transform(value.begin(), value.end(), value.begin(), ::tolower);
            cost->BuyBack = ManaCost::parseManaCost(value);
        }
        break;

    case 'c': //color
        if (!primitive) primitive = NEW CardPrimitive();
        {
            string value = val;
            std::transform(value.begin(), value.end(), value.begin(), ::tolower);
            vector<string> values = split(value, ',');
            int removeAllOthers = 1;
            for (size_t values_i = 0; values_i < values.size(); ++values_i)
            {
                primitive->setColor(values[values_i], removeAllOthers);
                removeAllOthers = 0;
            }
        }
        break;

    case 'f': //flashback//morph
        {
            if (!primitive) primitive = NEW CardPrimitive();
            if(ManaCost * cost = primitive->getManaCost())
            {
                if( s.find("facedown") != string::npos)//morph
                {
                    string value = val;
                    std::transform(value.begin(), value.end(), value.begin(), ::tolower);
                    cost->morph = ManaCost::parseManaCost(value);
                }
                else
                {
                    string value = val;
                    std::transform(value.begin(), value.end(), value.begin(), ::tolower);
                    cost->FlashBack = ManaCost::parseManaCost(value);
                }
            }
            break;
        }

    case 'g': //grade
        if (s.size() - i - 1 > 2) currentGrade = getGrade(val[2]);
        break;

    case 'i': //id
        if (!card) card = NEW MTGCard();
        card->setMTGId(atoi(val));
        break;

    case 'k': //kicker
        if (!primitive) primitive = NEW CardPrimitive();
        if (ManaCost * cost = primitive->getManaCost())
        {
            string value = val;
            std::transform(value.begin(), value.end(), value.begin(), ::tolower);
            size_t multikick = value.find("multi");
            bool isMultikicker = false;
            if(multikick != string::npos)
            {
                size_t endK = value.find("{",multikick);
                value.erase(multikick, endK - multikick);
                isMultikicker = true;
        }
            cost->kicker = ManaCost::parseManaCost(value);  
            cost->kicker->isMulti = isMultikicker;
        }
        break;

    case 'm': //mana
        if (!primitive) primitive = NEW CardPrimitive();
        {
            string value = val;
            std::transform(value.begin(), value.end(), value.begin(), ::tolower);
            primitive->setManaCost(value);
        }
        break;

    case 'n': //name
        if (!primitive) primitive = NEW CardPrimitive();
        primitive->setName(val);
        break;

    case 'o': //othercost/otherrestriction
        if (!primitive) primitive = NEW CardPrimitive();
        if(key[5] == 'r')//otherrestrictions
        {
            string value = val;
            primitive->setOtherRestrictions(value);
        }
        else
        {
            if (ManaCost * cost = primitive->getManaCost())
            {
                string value = val;
                std::transform(value.begin(), value.end(), value.begin(), ::tolower);
                size_t name = value.find("name(");
                string theName = "";
                    if(name != string::npos)
                    {
                        size_t endName = value.find(")",name);
                        theName = value.substr(name + 5,endName - name - 5);
                        value.erase(name, endName - name + 1);
                    }
                    cost->alternative = ManaCost::parseManaCost(value);
                    if(theName.size())
                        cost->alternative->alternativeName.append(theName);
            }
        }
        break;

    case 'p':
        if ('r' == key[1])
        { // primitive
            if (!card) card = NEW MTGCard();
            map<string, CardPrimitive*>::iterator it = primitives.find(val);
            if (it != primitives.end()) card->setPrimitive(it->second);
        }
        else
        { //power
            if (!primitive) primitive = NEW CardPrimitive();
            primitive->setPower(atoi(val));
        }
        break;

    case 'r': //retrace/rarity//restrictions
        if('s' == key[2] && 't' == key[3])//restrictions
        {
            if (!primitive) primitive = NEW CardPrimitive();
            string value = val;
            primitive->setRestrictions(value);
        }
        else if ('e' == key[1] && 't' == key[2])
        { //retrace
            if (!primitive) primitive = NEW CardPrimitive();
            if (ManaCost * cost = primitive->getManaCost())
            {
                string value = val;
                std::transform(value.begin(), value.end(), value.begin(), ::tolower);
                cost->Retrace = ManaCost::parseManaCost(value);
            }
        }
        else if (s.find("rar") != string::npos)
        {//rarity
            if (!card) card = NEW MTGCard();
            card->setRarity(val[0]);
        }
        break;

    case 's': //subtype, suspend
        {
            if (s.find("suspend") != string::npos)
            {
            size_t time = s.find("suspend(");
            size_t end = s.find(")=");
            int suspendTime = atoi(s.substr(time + 8,end - 2).c_str());
                if (!primitive) primitive = NEW CardPrimitive();
                if (ManaCost * cost = primitive->getManaCost())
                {
                    string value = val;
                    std::transform(value.begin(), value.end(), value.begin(), ::tolower);
                    cost->suspend = ManaCost::parseManaCost(value);
                    primitive->suspendedTime = suspendTime;
                }
                
            }
            else
            {
                if (!primitive) primitive = NEW CardPrimitive();
                vector<string> values = split(val, ' ');
                for (size_t values_i = 0; values_i < values.size(); ++values_i)
                    primitive->setSubtype(values[values_i]);
            }
            break;
        }

    case 't':
        if (!primitive) primitive = NEW CardPrimitive();
        if (0 == strcmp("target", key))
        {
            string value = val;
            std::transform(value.begin(), value.end(), value.begin(), ::tolower);
            primitive->spellTargetType = value;
        }
        else if (0 == strcmp("text", key))
            primitive->setText(val);
        else if (0 == strcmp("type", key))
        {
            vector<string> values = split(val, ' ');
            for (size_t values_i = 0; values_i < values.size(); ++values_i)
                    primitive->setType(values[values_i]);
        }
        else if (0 == strcmp("toughness", key)) primitive->setToughness(atoi(val));
        break;

    default:
        if(primitive) {
            DebugTrace( endl << "MTGDECK Parsing Error: " << " [" << primitive->getName() << "]" << s << std::endl);
        } else {
            DebugTrace( endl << "MTGDECK Parsing Generic Error: " << s << std::endl);
        }
        break;
    }

    tempPrimitive = primitive;
    tempCard = card;

    return i;

}
Ejemplo n.º 7
0
int MTGAllCards::load(const char * config_file, const char * set_name, int autoload)
{
    conf_read_mode = 0;
    const int set_id = set_name ? setlist.Add(set_name) : MTGSets::INTERNAL_SET;
    MTGSetInfo *si = setlist.getInfo(set_id);

    int lineNumber = 0;
    std::string contents;
    izfstream file;
    if (!JFileSystem::GetInstance()->openForRead(file, config_file))
        return total_cards;

    string s;

    while (getline(file,s))
    {
        lineNumber++;
        if (!s.size()) continue;
        if (s[s.size() - 1] == '\r')
            s.erase(s.size() - 1); //Handle DOS files
        if (!s.size()) continue;

        if (s.find("#AUTO_DEFINE ") == 0)
        {
            string toAdd = s.substr(13);
            AutoLineMacro::AddMacro(toAdd);
            continue;
        }

        switch (conf_read_mode)
        {
        case MTGAllCards::READ_ANYTHING:
            if (s[0] == '[')
            {
                currentGrade = Constants::GRADE_SUPPORTED; // Default value
                if (s.size() < 2)
                {
                    DebugTrace("FATAL: Card file incorrect");
                }
                else
                {
                    conf_read_mode = ('m' == s[1]) ? MTGAllCards::READ_METADATA : MTGAllCards::READ_CARD; // M for metadata.
                }
            }
            else
            {
                //Global grade for file, to avoid reading the entire file if unnnecessary
                if (s[0] == 'g' && s.size() > 8)
                {
                    int fileGrade = getGrade(s[8]);
                    int maxGrade = options[Options::MAX_GRADE].number;
                    if (!maxGrade) maxGrade = Constants::GRADE_BORDERLINE; //Default setting for grade is borderline?
                    if (fileGrade > maxGrade)
                    {
                        file.close();
                        return total_cards;
                    }
                }
            }
            continue;
        case MTGAllCards::READ_METADATA:
            if (s[0] == '[' && s[1] == '/')
                conf_read_mode = MTGAllCards::READ_ANYTHING;
            else if (si) si->processConfLine(s);
            continue;
        case MTGAllCards::READ_CARD:
            if (s[0] == '[' && s[1] == '/')
            {
                conf_read_mode = MTGAllCards::READ_ANYTHING;
                if (tempPrimitive) tempPrimitive = addPrimitive(tempPrimitive, tempCard);
                if (tempCard)
                {
                    if (tempPrimitive) tempCard->setPrimitive(tempPrimitive);
                    addCardToCollection(tempCard, set_id);
                }
                tempCard = NULL;
                tempPrimitive = NULL;
            }
            else
            {
                if (!processConfLine(s, tempCard, tempPrimitive))
                    DebugTrace("MTGDECK: BAD Line: \n[" << lineNumber << "]: " << s );
            }
            continue;
        }
    }
    file.close();
    return total_cards;
}
Ejemplo n.º 8
0
void MainWindow::fillMEPR(){
    quint32 ga1=ui->spinboxGa1->value();
    quint32 ga2=ui->spinboxGa2->value();
    quint32 wiso=ui->spinboxWiso->value();

    // Create model
    model = new QStringListModel(this);

    // Make data
    QStringList List;
    quint32 nr=0;
    if(ui->radioButton1->isChecked()){
        nr=1;
    }
    if(ui->radioButton2->isChecked()){
        nr=2;
    }
    if(ui->radioButton3->isChecked()){
        nr=3;
    }

    if(checkMAllowed(ga1,ga2,wiso) && nr>0){
        quint32 docu=ui->spinboxDocumentation->value();
        quint32 exam=ui->spinboxExamination->value();
        quint32 a = (quint32) ui->labelPointsA->text().toInt();
        QString atmp="";
        QString btmp="";
        QString gtmp="";
        bool passedtmp=false;
        bool passed=false;
        for(int i=0;i<=100;i++){
            quint32 b=0;
            quint32 points=i;
            switch(nr){
            case 1:
                b = round((round((ga1*2.0+i)/3.0)*2.0 + ga2*2.0 + wiso)/5.0);
                break;
            case 2:
                b = round((round((ga2*2.0+i)/3.0)*2.0 + ga1*2.0 + wiso)/5.0);
                break;
            case 3:
                b = round((round((wiso*2.0+i)/3.0) + ga1*2.0 + ga2*2.0)/5.0);
                break;
            default:
                ; // error
            }
            quint32 g = round((a+b)/2.0);
            QString aString = getGrade(a);
            QString bString = getGrade(b);
            QString gString = getGrade(g);
            passed=(checkPassedA(docu,exam) && checkPassedB(ga1,ga2,wiso,nr,points));
            if(atmp.compare(aString)!=0 || btmp.compare(bString)!=0 || gtmp.compare(gString)!=0 || (passed!=passedtmp)){
                QString item;
                if(passed){
                    item = QString("%1: A=%2 B=%3 +G=%4").arg(i,3).arg(aString,-12).arg(bString,-12).arg(gString,-12);
                }
                else{
                    item = QString("%1: A=%2 B=%3 -G=%4").arg(i,3).arg(aString,-12).arg(bString,-12).arg(gString,-12);
                }
                List << item;
                atmp=aString;
                btmp=bString;
                gtmp=gString;
                passedtmp=passed;
            }
        }

    }
    else{
        List.clear();
    }

        // Populate our model
    model->setStringList(List);

    // Glue model and view together
#ifdef Q_OS_OSX
        // OSX---
        QFont newFont("Courier", 12, QFont::Normal, true);
#else
        // Windows Q_OS_WIN
        QFont newFont("Courier", 10, QFont::Normal, true);
#endif
    ui->listViewMEPR->setStyleSheet("background-color:lightgray;");
    ui->listViewMEPR->setFont(newFont);
    ui->listViewMEPR->setModel(model);
}
Ejemplo n.º 9
0
void MainWindow::fillPRFG(){
    // Create model
        model = new QStringListModel(this);

        // Make data
        QStringList List;
        quint32 docu=ui->spinboxDocumentation->value();
        quint32 resultB=(quint32)ui->labelPointsB->text().toInt();
        quint32 ga1 = ui->spinboxGa1->value();
        quint32 ga2 = ui->spinboxGa2->value();
        quint32 wiso = ui->spinboxWiso->value();
        QString atmp="";
        QString btmp="";
        QString gtmp="";
        quint32 b = resultB;
        QString bString = getGrade(b);
        quint32 nr=0;
        quint32 points=0;
        if(ui->radioButton1->isChecked()){
            nr=1;
            points=ui->spinboxGa1E->value();
        }
        if(ui->radioButton2->isChecked()){
            nr=2;
            points=ui->spinboxGa2E->value();
        }
        if(ui->radioButton3->isChecked()){
            nr=3;
            points=ui->spinboxWisoE->value();
        }
        bool passedtmp=false;
        bool passed=false;

        for(int i=0;i<=100;i++){
            quint32 a = round((i+docu)/2.0);
            quint32 g = round((a+resultB)/2.0);
            QString aString = getGrade(a);
            QString gString = getGrade(g);
            passed=(checkPassedA(docu,i) && checkPassedB(ga1,ga2,wiso,nr,points));
            if(atmp.compare(aString)!=0 || btmp.compare(bString)!=0 || gtmp.compare(gString)!=0 || (passed!=passedtmp)){
                QString item;
                if(checkPassedA(docu,i) && checkPassedB(ga1,ga2,wiso,nr,points)){
                    item = QString("%1: A=%2 B=%3 +G=%4").arg(i,3).arg(aString,-12).arg(bString,-12).arg(gString,-12);
                }else
                {
                    item = QString("%1: A=%2 B=%3 -G=%4").arg(i,3).arg(aString,-12).arg(bString,-12).arg(gString,-12);
                }
                List << item;
                atmp=aString;
                btmp=bString;
                gtmp=gString;
                passedtmp = passed;
            }
        }


        // Populate our model
        model->setStringList(List);

        // Glue model and view together
#ifdef Q_OS_OSX
        // OSX---
        QFont newFont("Courier", 12, QFont::Normal, true);
#else
        // Windows Q_OS_WIN
        QFont newFont("Courier", 10, QFont::Normal, true);
#endif
        ui->listViewPRFG->setStyleSheet("background-color:lightgray;");
        ui->listViewPRFG->setFont(newFont);
        ui->listViewPRFG->setModel(model);
}
Ejemplo n.º 10
0
void MainWindow::writeResults(){
    // Part A
    quint32 docu = (quint32) ui->spinboxDocumentation->value();
    quint32 exam  = (quint32) ui->spinboxExamination->value();
    qint32 pointsA = calcA(docu,exam);
    QString gradeA = getGrade(pointsA);
    ui->labelPointsA->setText(QString::number(pointsA).rightJustified(3,' '));
    if(checkPassedA(docu,exam)){
        ui->labelGradeA->setStyleSheet("QLabel { color : green; }");
    }
    else{
        ui->labelGradeA->setStyleSheet("QLabel { color : red; }");
    }
    ui->labelGradeA->setText(getGrade(pointsA).rightJustified(12,' '));

    // Part B
    quint32 nr=0;
    quint32 points=0;
    quint32 ga1 = (quint32) ui->spinboxGa1->value();
    quint32 ga2  = (quint32) ui->spinboxGa2->value();
    quint32 wiso  = (quint32) ui->spinboxWiso->value();
//    quint32 ga1E = (quint32) ui->spinboxGa1E->value();
//    quint32 ga2E  = (quint32) ui->spinboxGa2E->value();
//    quint32 wisoE  = (quint32) ui->spinboxWisoE->value();

    if(checkMAllowed(ga1,ga2,wiso)){    // oral is possible
        if(round((round((ga1*2.0+100.0)/3.0)*2.0+ga2*2.0+wiso)/5.0)>=50 && ga1<50){ // oral in ga1
            ui->radioButton1->setEnabled(true);
            if(ui->radioButton1->isChecked()){ // oral in ga1
                ui->spinboxGa1E->setEnabled(true);
                ui->spinboxGa1E->show();
                nr=1;
                points=ui->spinboxGa1E->value();
            }
            else{
                ui->spinboxGa1E->setValue(0);
                ui->spinboxGa1E->setEnabled(false);
                ui->spinboxGa1E->hide();
            }
        }
        else{
            ui->radioButton1->setAutoExclusive(false);
            ui->radioButton2->setAutoExclusive(false);
            ui->radioButton3->setAutoExclusive(false);
            ui->radioButton1->setChecked(false);
            ui->radioButton1->setAutoExclusive(true);
            ui->radioButton2->setAutoExclusive(true);
            ui->radioButton3->setAutoExclusive(true);
           ui->radioButton1->setEnabled(false);
           ui->spinboxGa1E->setValue(0);
           ui->spinboxGa1E->hide();
        }
        if(round((round((ga2*2.0+100.0)/3.0)*2.0+ga1*2.0+wiso)/5.0)>=50 && ga2<50){ // oral in ga2
            ui->radioButton2->setEnabled(true);
            if(ui->radioButton2->isChecked()){ // oral in ga1
                 ui->spinboxGa2E->setEnabled(true);
                 ui->spinboxGa2E->show();
                 nr=2;
                 points=ui->spinboxGa2E->value();
             }
             else{
                 ui->spinboxGa2E->setValue(0);
                 ui->spinboxGa2E->setEnabled(false);
                 ui->spinboxGa2E->hide();
             }
        }
        else{
            ui->radioButton1->setAutoExclusive(false);
            ui->radioButton2->setAutoExclusive(false);
            ui->radioButton3->setAutoExclusive(false);
            ui->radioButton2->setChecked(false);
            ui->radioButton1->setAutoExclusive(true);
            ui->radioButton2->setAutoExclusive(true);
            ui->radioButton3->setAutoExclusive(true);
            ui->radioButton2->setEnabled(false);
            ui->spinboxGa2E->setValue(0);
            ui->spinboxGa2E->hide();
        }
        if(round((round((wiso*2.0+100.0)/3.0)+ga1*2.0+ga2*2.0)/5.0)>=50 && wiso<50){ // oral in wiso
            ui->radioButton3->setEnabled(true);
            if(ui->radioButton3->isChecked()){ // oral in ga1
                ui->spinboxWisoE->setEnabled(true);
                ui->spinboxWisoE->show();
                nr=3;
                points=ui->spinboxWisoE->value();
            }
            else{
                ui->spinboxWisoE->setValue(0);
                ui->spinboxWisoE->setEnabled(false);
                ui->spinboxWisoE->hide();
            }

        }
        else{
            ui->radioButton1->setAutoExclusive(false);
            ui->radioButton2->setAutoExclusive(false);
            ui->radioButton3->setAutoExclusive(false);
            ui->radioButton3->setChecked(false);
            ui->radioButton1->setAutoExclusive(true);
            ui->radioButton2->setAutoExclusive(true);
            ui->radioButton3->setAutoExclusive(true);
            ui->radioButton3->setChecked(false);
            ui->radioButton3->setEnabled(false);
            ui->spinboxWisoE->setValue(0);
            ui->spinboxWisoE->hide();
        }
    }
    else{   // oral not possible
        ui->radioButton1->setAutoExclusive(false);
        ui->radioButton2->setAutoExclusive(false);
        ui->radioButton3->setAutoExclusive(false);
        ui->radioButton1->setChecked(false);
        ui->radioButton1->setEnabled(false);
        ui->radioButton2->setChecked(false);
        ui->radioButton2->setEnabled(false);
        ui->radioButton3->setChecked(false);
        ui->radioButton3->setEnabled(false);
        ui->radioButton1->setAutoExclusive(true);
        ui->radioButton2->setAutoExclusive(true);
        ui->radioButton3->setAutoExclusive(true);
        ui->spinboxGa1E->setValue(0);
        ui->spinboxGa1E->hide();
        ui->spinboxGa2E->setValue(0);
        ui->spinboxGa2E->hide();
        ui->spinboxWisoE->setValue(0);
        ui->spinboxWisoE->hide();
    }
    if(checkPassedB(ga1,ga2,wiso,nr,points)){
        ui->labelGradeB->setStyleSheet("QLabel { color : green; }");
    }
    else{
        ui->labelGradeB->setStyleSheet("QLabel { color : red; }");
    }

    qint32 pointsB = calcB(ga1,ga2,wiso,nr,points);
    QString gradeB = getGrade(pointsB);
    ui->labelPointsB->setText(QString::number(pointsB).rightJustified(3,' '));

    ui->labelGradeB->setText(getGrade(pointsB).rightJustified(12,' '));


    // Results
    // Part A
    ui->labelResultA->setText(QString::number(pointsA).rightJustified(3,' '));
    if(checkPassedA(docu,exam)){
        ui->labelGradeResultA->setStyleSheet("QLabel { color : green; }");
    }
    else{
        ui->labelGradeResultA->setStyleSheet("QLabel { color : red; }");
    }
    ui->labelGradeResultA->setText(getGrade(pointsA).rightJustified(12,' '));

    // Part B
    ui->labelResultB->setText(QString::number(pointsB).rightJustified(3,' '));
    if(checkPassedB(ga1,ga2,wiso,nr,points)){
        ui->labelGradeResultB->setStyleSheet("QLabel { color : green; }");
    }
    else{
        ui->labelGradeResultB->setStyleSheet("QLabel { color : red; }");
    }
    ui->labelGradeResultB->setText(getGrade(pointsB).rightJustified(12,' '));

    // All
    quint32 pointsAll = calcAll(pointsA,pointsB);
    QString gradeAll = getGrade(pointsAll);
    ui->labelResultAll->setText(QString::number(pointsAll).rightJustified(3,' '));
    if(checkPassedB(ga1,ga2,wiso,nr,points) && checkPassedA(docu,exam)){
        ui->labelGradeResult->setStyleSheet("QLabel { color : green; }");
        hasPassed=true;
    }
    else{
        ui->labelGradeResult->setStyleSheet("QLabel { color : red; }");
        hasPassed=false;
    }
    ui->labelGradeResult->setText(getGrade(pointsAll).rightJustified(12,' '));

    fillPRFG();
    fillMEPR();
    ui->saveFile->setEnabled(true);
}
Ejemplo n.º 11
0
//MTGAllCards
int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primitive)
{
    if ('#' == s[0]) return 1; // a comment shouldn't be treated as an error condition
    size_t del_pos = s.find_first_of('=');
    if (del_pos == string::npos || 0 == del_pos)
        return 0;

    s[del_pos] = '\0';
    const string key = s.substr(0, del_pos);
    const string val = s.substr(del_pos + 1);

    switch (key[0])
    {
    case 'a':
        if (key == "auto")
        {
            if (!primitive) primitive = NEW CardPrimitive();
            primitive->addMagicText(val);
        }
        else if (StartsWith(key, "auto"))
        {
            if (!primitive) primitive = NEW CardPrimitive();
            primitive->addMagicText(val, key.substr(4));
        }
        else if (key == "alias")
        {
            if (!primitive) primitive = NEW CardPrimitive();
            primitive->alias = atoi(val.c_str());
        }
        else if (key == "abilities")
        {
            if (!primitive) primitive = NEW CardPrimitive();
            string value = val;
            //Specific Abilities
            std::transform(value.begin(), value.end(), value.begin(), ::tolower);
            vector<string> values = split(value, ',');
            for (size_t values_i = 0; values_i < values.size(); ++values_i)
            {

                for (int j = Constants::NB_BASIC_ABILITIES - 1; j >= 0; --j)
                {
                    if (values[values_i].find(Constants::MTGBasicAbilities[j]) != string::npos)
                    {
                        primitive->basicAbilities[j] = 1;
                        break;
                    }
                }
            }
        }
        break;

    case 'b': //buyback
        if (!primitive) primitive = NEW CardPrimitive();
        if (ManaCost * cost = primitive->getManaCost())
        {
            string value = val;
            std::transform(value.begin(), value.end(), value.begin(), ::tolower);
            cost->setBuyback(ManaCost::parseManaCost(value));
        }
        break;

    case 'c': //color
        if (!primitive) primitive = NEW CardPrimitive();
        {
            string value = val;
            std::transform(value.begin(), value.end(), value.begin(), ::tolower);
            vector<string> values = split(value, ',');
            int removeAllOthers = 1;
            for (size_t values_i = 0; values_i < values.size(); ++values_i)
            {
                primitive->setColor(values[values_i], removeAllOthers);
                removeAllOthers = 0;
            }
        }
        break;
    case 'd'://dredge
        if (!primitive) primitive = NEW CardPrimitive();
        {
            string value = val;
            std::transform(value.begin(), value.end(), value.begin(), ::tolower);
            vector<string> values = parseBetween(value,"dredge(",")");
            if(values.size())
                primitive->dredgeAmount = atoi(values[1].c_str());

            break;
        }
    case 'f': //flashback//morph
    {
        if (!primitive) primitive = NEW CardPrimitive();
        if(ManaCost * cost = primitive->getManaCost())
        {
            if( s.find("facedown") != string::npos)//morph
            {
                string value = val;
                std::transform(value.begin(), value.end(), value.begin(), ::tolower);
                cost->setMorph(ManaCost::parseManaCost(value));
            }
            else
            {
                string value = val;
                std::transform(value.begin(), value.end(), value.begin(), ::tolower);
                cost->setFlashback(ManaCost::parseManaCost(value));
            }
        }
        break;
    }

    case 'g': //grade
        if (s.size() - del_pos - 1 > 2) currentGrade = getGrade(val[2]);
        break;

    case 'i': //id
        if (!card) card = NEW MTGCard();
        card->setMTGId(atoi(val.c_str()));
        break;

    case 'k': //kicker
        if (!primitive) primitive = NEW CardPrimitive();
        if (ManaCost * cost = primitive->getManaCost())
        {
            string value = val;
            std::transform(value.begin(), value.end(), value.begin(), ::tolower);
            size_t multikick = value.find("multi");
            bool isMultikicker = false;
            if(multikick != string::npos)
            {
                size_t endK = value.find("{",multikick);
                value.erase(multikick, endK - multikick);
                isMultikicker = true;
            }
            cost->setKicker(ManaCost::parseManaCost(value));
            cost->getKicker()->isMulti = isMultikicker;
        }
        break;

    case 'm': //mana
        if (!primitive) primitive = NEW CardPrimitive();
        {
            string value = val;
            std::transform(value.begin(), value.end(), value.begin(), ::tolower);
            primitive->setManaCost(value);
        }
        break;

    case 'n': //name
        if (!primitive) primitive = NEW CardPrimitive();
        primitive->setName(val);
        break;

    case 'o': //othercost/otherrestriction
        if (!primitive) primitive = NEW CardPrimitive();
        if(key[5] == 'r')//otherrestrictions
        {
            string value = val;
            primitive->setOtherRestrictions(value);
        }
        else
        {
            if (ManaCost * cost = primitive->getManaCost())
            {
                string value = val;
                std::transform(value.begin(), value.end(), value.begin(), ::tolower);
                size_t name = value.find("name(");
                string theName = "";
                if(name != string::npos)
                {
                    size_t endName = value.find(")",name);
                    theName = value.substr(name + 5,endName - name - 5);
                    value.erase(name, endName - name + 1);
                }
                cost->setAlternative(ManaCost::parseManaCost(value));
                if(theName.size())
                    cost->getAlternative()->alternativeName.append(theName);
            }
        }
        break;

    case 'p':
        if (key[1] == 'r')
        {   // primitive
            if (!card) card = NEW MTGCard();
            map<string, CardPrimitive*>::iterator it = primitives.find(val);
            if (it != primitives.end()) card->setPrimitive(it->second);
        }
        else
        {   //power
            if (!primitive) primitive = NEW CardPrimitive();
            primitive->setPower(atoi(val.c_str()));
        }
        break;

    case 'r': //retrace/rarity//restrictions
        if(key[2] == 's' && key[3] == 't')//restrictions
        {
            if (!primitive) primitive = NEW CardPrimitive();
            string value = val;
            primitive->setRestrictions(value);
        }
        else if (key[1] == 'e' && key[2] == 't')
        {   //retrace
            if (!primitive) primitive = NEW CardPrimitive();
            if (ManaCost * cost = primitive->getManaCost())
            {
                string value = val;
                std::transform(value.begin(), value.end(), value.begin(), ::tolower);
                cost->setRetrace(ManaCost::parseManaCost(value));
            }
        }
        else if (s.find("rar") != string::npos)
        {   //rarity
            if (!card) card = NEW MTGCard();
            card->setRarity(val[0]);
        }
        break;

    case 's': //subtype, suspend
    {
        if (s.find("suspend") != string::npos)
        {
            size_t time = s.find("suspend(");
            size_t end = s.find(")=");
            int suspendTime = atoi(s.substr(time + 8,end - 2).c_str());
            if (!primitive) primitive = NEW CardPrimitive();
            if (ManaCost * cost = primitive->getManaCost())
            {
                string value = val;
                std::transform(value.begin(), value.end(), value.begin(), ::tolower);
                cost->setSuspend(ManaCost::parseManaCost(value));
                primitive->suspendedTime = suspendTime;
            }

        }
        else
        {
            if (!primitive) primitive = NEW CardPrimitive();
            vector<string> values = split(val.c_str(), ' ');
            for (size_t values_i = 0; values_i < values.size(); ++values_i)
                primitive->setSubtype(values[values_i]);
        }
        break;
    }

    case 't':
        if (!primitive) primitive = NEW CardPrimitive();
        if (key == "target")
        {
            string value = val;
            std::transform(value.begin(), value.end(), value.begin(), ::tolower);
            primitive->spellTargetType = value;
        }
        else if (key == "text")
            primitive->setText(val);
        else if (key == "type")
        {
            vector<string> values = split(val, ' ');
            for (size_t values_i = 0; values_i < values.size(); ++values_i)
                primitive->setType(values[values_i]);
        }
        else if (key == "toughness") primitive->setToughness(atoi(val.c_str()));
        break;

    default:
        if(primitive) {
            DebugTrace( endl << "MTGDECK Parsing Error: " << " [" << primitive->getName() << "]" << s << std::endl);
        } else {
            DebugTrace( endl << "MTGDECK Parsing Generic Error: " << s << std::endl);
        }
        break;
    }

    tempPrimitive = primitive;
    tempCard = card;

    return del_pos;

}