Create a C++ program that accepts a number representing a class and then display
ID: 3763216 • Letter: C
Question
Create a C++ program that accepts a number representing a class and then displays the name of the class. Your program should continue to prompt for a class number and display the name of the class until a sentinel value is entered. Your program should use an array to store the class names and reference the array when displaying the class names.
Class Number Class Name
1 Smart Aleck 101
2 Napping 205
3 Yogi Bear Yoga 110
4 Yogi Bear Yoga 108
5 Moshing 330
2. Create a pseudocode for your program.
Explanation / Answer
#include <iostream>
using namespace std;
int main() {
string arr[5] = {"Smart Aleck 101", "Napping 205", "Yogi Bear Yoga 110", "Yogi Bear Yoga 108", "Moshing 330"};
while (true) {
cout<<"Enter class number to get the class names else -1 to exit: ";
int c;
cin>>c;
if (c == -1) {
cout<<"Good bye!!";
return 0;
}
cout<<"Class name is: "<<arr[c-1]<<" ";
}
cout<<" ";
return 0;
}
---------------------
store data in array
while loop infinite :
c <- get input from user and -1 to exit
if c is -1 then exit
print class name with array at c position
end while loop