Answer:
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <string>
using namespace std;
int
main ()
{
string first_name = "";
string last_name = "";
string student_ID, class_name, roomNumber = "";
cout << "What is your first name? ";
getline (cin, first_name);
cout << endl;
cout << "What is your last name? ";
getline (cin, last_name);
cout << endl;
cout << "What is your student ID? ";
getline (cin, student_ID);
cout << endl;
cout << "*************************************************" << endl;
cout << "\v" << endl;
cout << "\t" << first_name << "," << last_name << " ID " << student_ID <<
endl;
cout << "\v" << endl;
cout << "*************************************************" << endl;
int i = 1;
while (0 == 0)
{
cout << "Enter the next class, STOP to end:";
getline (cin, class_name);
if (class_name == "STOP")
{
return 0;
}
cout << "Enter the room number: ";
getline (cin, roomNumber);
cout << "\t" << "Block " << i << " : " << class_name << " Room: " <<
roomNumber << endl;
i++;
}
return 0;
}
Step-by-step explanation:
First we take initialize input variables for our data. We used string as they are not predefined and can store much more data than char.
We named our variable string first_name for First Name, string last_name for Last Name,string student_ID for student ID, string class_name for class name and string room_number for room number and initialize them to empty string so they don't have any garbage value stored in them.
To use string in cpp we need to include string library. Get input for first name, last name and student id using getline method.
For taking class name and room number input use an infinite loop, to run a loop infinitely set condition 0==0 in a while loop. Take input from user for class name using getline and check if it is equal to "STOP" return 0 to terminate other wise take input for class name and print using cout. For adding vertical tab space use \v delimiter and for horizontal tab space add \t delimiter.