jeudi 31 mars 2016

How to pass char array to other function c++ [on hold]

Im doing a school c++ assignment and can't seem to pass an array to another function. Here is my source code. How do I pass the arrays to the displayinfo function?

#include<iostream>
#include<array>
#include<iomanip>
#include<string>
using namespace std;

void setCourseName(string);
void InputValue();


int main()
{
    InputValue();    
}

void InputValue()
{
    char semester;
    string courseTitle;
    string courseType;
    int credits;
    string lettergrade;
    double gpa;

    array<char, 7> sem1array;
    array<string, 7> sem1coursetitles;
    array<string, 7> sem1courseTypes;
    array<int, 7> sem1credits;
    array<string, 7> sem1lettergrades;


    for (int counter = 0; counter < sem1array.size(); counter++)
    {
        bool valid1 = false;
        bool validCredits = false;
        bool valid3 = false;
        bool valid4 = false;
        while (valid1 == false)
        {
            cout << "Enter Semester Number" << endl;
            cin >> semester;
            if (semester == '1' || semester == '2')
            {
                cout << "valid input" << endl;
                sem1array[counter] = semester;
                valid1 = true;
            }
            else
            {

                cout << "Invalid Input! RE ENTER SEMESTER NUMBER EITHER 1 OR 2!" << endl;
            }
        }
            cout << "Enter Course Title: " << endl;
            cin.ignore();
            getline(cin, courseTitle);
            if(courseTitle.size() <= 25)
                sem1coursetitles[counter] = courseTitle;
            else
            {
                cout << "Course Name Cannot Be More Than 25 Characters; Course name limited to first 25 characters!" << endl;
                courseTitle = courseTitle.substr(0, 25);
                sem1coursetitles[counter] = courseTitle;
            }

        while (valid3 == false)
        {
            cout << "Enter Course Type: Regular, AP, or Honors" << endl;

            getline(cin, courseType);
            if (courseType == "Regular" || courseType == "AP" || courseType == "Honors")
            {
                sem1courseTypes[counter] = courseType;
                valid3 = true;
            }
            else
            {
                cout << "Invalid Input! RE ENTER COURSE TYPE EXACTLY HOW IT APPEARS EITHER Regular, AP, or Honors!" << endl;
            }
        }
        while(validCredits == false)
        {
            cout << "Enter Credits Earned For Course: **Can Either Be 1-4 Credits**" << endl;
            cin >> credits;
            if (credits == 1 || credits == 2 || credits == 3 || credits == 4)
            {
                sem1credits[counter] = credits;
                validCredits = true;
            }
            else
            {
                cout << "Invalid Output! Must Enter Number 1-4 For Credits Earned!" << endl;
            }
        }
        while (valid4 == false)
        {
            cout << "Enter Letter Grade; Capital Letter Followed By A Plus + or Minus - If There Is One!Example: A+, A-, A, B+..." << endl;
            cin.ignore();
            getline(cin, lettergrade);
            if (lettergrade == "A+")
            {
                gpa = 4.0;
                sem1lettergrades[counter] = lettergrade;
                valid4 = true;
            }
            else if (lettergrade == "A")
            {
                gpa = 4.0;
                sem1lettergrades[counter] = lettergrade;
                valid4 = true;
            }
            else if (lettergrade == "A-")
            {
                gpa = 3.7;
                sem1lettergrades[counter] = lettergrade;
                valid4 = true;
            }
            else if (lettergrade == "B+")
            {
                gpa = 3.3;
                sem1lettergrades[counter] = lettergrade;
                valid4 = true;
            }
            else if (lettergrade == "B")
            {
                gpa = 3.0;
                sem1lettergrades[counter] = lettergrade;
                valid4 = true;
            }
            else if (lettergrade == "B-")
            {
                gpa = 2.7;
                sem1lettergrades[counter] = lettergrade;
                valid4 = true;
            }
            else if (lettergrade == "C+")
            {
                gpa = 2.3;
                sem1lettergrades[counter] = lettergrade;
                valid4 = true;
            }
            else if (lettergrade == "C")
            {
                gpa = 2.0;
                sem1lettergrades[counter] = lettergrade;
                valid4 = true;
            }
            else if (lettergrade == "C-")
            {
                gpa = 1.7;
                sem1lettergrades[counter] = lettergrade;
                valid4 = true;
            }
            else if (lettergrade == "D+")
            {
                gpa = 1.3;
                sem1lettergrades[counter] = lettergrade;
                valid4 = true;
            }
            else if (lettergrade == "D")
            {
                gpa = 1.0;
                sem1lettergrades[counter] = lettergrade;
                valid4 = true;
            }
            else if (lettergrade == "F")
            {
                gpa = 0.0;
                sem1lettergrades[counter] = lettergrade;
                valid4 = true;
            }

            else
            {
                cout << "Invalid Input! Please Re-Enter Letter Grade! Example: A+, A-, A, B+..." << endl;
            }
        }
    }

    displayinfo(sem1array);

}
void displayinfo(char b[])
{
    for (int k = 0; k < sem1array.size(); k++)
    {
        cout << "Semester: " << sem1array[k] << "           " << "Course: " << sem1coursetitles[k] << endl;

    }

}

Aucun commentaire:

Enregistrer un commentaire