66.5k views
5 votes
Edhesive assignment 4 student

In this assignment, you will draw a student schedule by using a while loop. You will ask the user for their first and last names, and then a list of their classes and room numbers.

The loop should stop when they enter STOP for their next class.

Print the schedule in the same format as the example below. Remember to use the tab escape character to make it nicely formatted.
Output of the code should be
What is your first name? Ada
What is your last name? Lovelace
Student ID: 3456
*************************************************
* *
* Lovelace, Ada ID: 3456 *
* *
*************************************************
* *
Enter the next class, STOP to end: English 11
Enter the room number: 456
* Block 1: English 11 Room: 456 *
Enter the next class, STOP to end: Government
Enter the room number: 143
* Block 2: Government Room: 143 *
Enter the next class, STOP to end: Art History
Enter the room number: 943
* Block 3: Art History Room: 943 *
Enter the next class, STOP to end: Algebra II
Enter the room number: 571
* Block 4: Algebra II Room: 571 *
Enter the next class, STOP to end: Chemistry
Enter the room number: 467
* Block 5: Chemistry Room: 467 *
Enter the next class, STOP to end: AP Comp Sci
Enter the room number: 510
* Block 6: AP Comp Sci Room: 510 *
Enter the next class, STOP to end: STOP
* *
*************************************************
* *
*************************************************

1 Answer

3 votes

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.

User Ali Asad
by
5.7k points