Converting an int array to string values

Hello everyone, I have a program that is almost complete, except that I need to take my integer values from my classLevel[] array and convert it into a string value for display purposes. For example:

original unsorted text file looks like:
BB222222 U 80
DD444444 U 52
CD334455 U 100

Sorted looks like:
DD444444 1
CD334455 3
CC333333 0
The 0 represents Freshman / 1 = Sophomore / 2 = Junior / 3= Senior
I have a switch statement that will convert it but I'm not sure how to take it from an int array to the switch function. I was thinking about using a for loop, but I'm not sure how to go about that. Any help would be greatly appreciated. Thank you.

Here is part of my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  //************************************************************************* 
int main()
{
	//VARIABLES
	int cnt = 0;								// counter
	string studentID;							// validated user input for student ID
	int targetID;								// return numerical value from the called function idSearch 
	string title;								// stored value for the string value of class level
	int numTitle;
	int cnt1;
	// opening the text file CREDIT.txt
	ifstream inCreditData;
	inCreditData.open(IN_CREDIT_FILE.c_str());
	// opening the text file SORTED.txt
	ofstream outCreditData;
	outCreditData.open(OUT_CREDIT_FILE.c_str());
	

	// array's
	string idNum[MAX_ARRAY];
	int classLevel[MAX_ARRAY];

	// display header
	display_header();
	// verification that file exists 
	if (!inCreditData)
	{
		cout << "The input data file does not exist!" << endl;
		cout << "Please verify input file and run the program again!" << endl;
		return 5;
	}
	// calling different functions to compute and display the results   	
	else
	{
		cout << "File opened successfully! Reading file." << endl << endl;
		// function to read data from the text file into the correct array
		readCreditFile(inCreditData, idNum, classLevel, cnt);
		// function to sort the data in the student ID array (idNum[])
		selectSort(classLevel, idNum, cnt);
		// function to store sorted data into another array
		newSorted(outCreditData, idNum, classLevel, cnt);
		// function to display the student ID's 
		displayID(idNum, cnt);
   	    // function to prompt user for student ID and validate the format 
		studentID = userInput();
		
		while (studentID != "X" && studentID != "x")
		{
			// function to search for the student ID
			targetID = idSearch (studentID, idNum, cnt);
			// convert numeric value to string
		    //	?????????												?????
			// function to display the student information 
			displayStudentInfo(studentID, numTitle, targetID);	
			studentID = userInput();	
		}			
	}
	cin.ignore();
//	return EXIT_SUCCESS;
	return 0;
}
//***************************************************************************
string studentTitle(int num)
{
	string name;
	switch (num)
	{
	case 0:
		name = "Freshman";
		break;
	case 1:
		name = "Sophomore";
		break;
	case 2:
		name = "Junior";
		break;
	case 3:
		name = "Senior";
	}

	return name;
}
//***************************************************************************
void displayStudentInfo(string id , int title, int num)
{
	if (num == NOT_FOUND)
		cout << "No student with ID " << id << " was found." << endl;
	else 
		cout << "The student with ID " << id << " is a " << title << "." << endl;
	
	return;
}
Do you mean something like this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

using namespace std;

int main()
{
    string names[4] = {"Freshman","Sophomore","Junior","Senior"};
    int num = 0;
    cout  << "Enter number: ";
    cin   >> num;
    if (num >= 0 && num < 4)
        cout << names[num];
    else
        cout << "invalid number";

    return 0;
}

Topic archived. No new replies allowed.