LAB 10.3 Using getline() & get() Exercise 1: Write a short program called readata.cpp that defines a character array last which contains 10 characters. Prompt the user to enter their last name using no more than 9 characters. The program should then read the name into last and then output the name back to the screen with an appropriate message. Do not use the getline() or get functions! Exercise 2: Once the program in Exercise 1 is complete, run the program and enter the name Newmanouskous at the prompt. What, if anything, happens? (Note that the results could vary depending on your system). Exercise 3: Re-write the program above using the getline() function (and only allowing 9 characters to be input). As before, use the character array last consisting of 10 elements. Run your new program and enter Newmanouskous at the prompt. What is the output? Exercise 4: Bring in program grades.cpp and grades.txt from the Lab 10 folder. Fill in the code in bold so that the data is properly read from grades.txt. and the desired output to the screen is as follows: The grades.txt file: Adara Starr          94 David Starr          91 Sophia Starr         94 Maria Starr          91 Danielle DeFino      94 Dominic DeFino       98 McKenna DeFino       92 Taylor McIntire      99 Torrie McIntire      91 Emily Garrett        97 Lauren Garrett       92 Marlene Starr        83 Donald DeFino        73 OUTPUT TO SCREEN DATA FILE Adara Starr has a(n) 94 average Adara Starr 94 David Starr has a(n) 91 average David Starr 91 Sophia Starr has a(n) 94 average Sophia Starr 94 Maria Starr has a(n) 91 average Maria Starr 91 Danielle DeFino has a(n) 94 average Danielle DeFino 94 Dominic DeFino has a(n) 98 average Dominic DeFino 98 McKenna DeFino has a(n) 92 average McKenna DeFino 92 Taylor McIntire has a(n) 99 average Taylor McIntire 99 Torrie McIntire has a(n) 91 average Torrie McIntire 91 Emily Garrett has a(n) 97 average Emily Garrett 97 Lauren Garrett has a(n) 92 average Lauren Garrett 92 Marlene Starr has a(n) 83 average Marlene Starr 83 Donald DeFino has a(n) 73 average Donald DeFino 73 The code of grades.cpp is as follows: #include #include using namespace std; // PLACE YOUR NAME HERE const int MAXNAME = 20; int main() { ifstream inData; inData.open("grades.txt"); char name[MAXNAME + 1]; // holds student name float average; // holds student average Lesson 10B 193 inData.get(name,MAXNAME+1); while (inData) { inData >> average; // Fill in the code to print out name and // student average // Fill in the code to complete the while // loop so that the rest of the student // names and average are read in properly } return 0; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

LAB 10.3 Using getline() & get()

Exercise 1: Write a short program called readata.cpp that defines a character
array last which contains 10 characters. Prompt the user to enter their last
name using no more than 9 characters. The program should then read the
name into last and then output the name back to the screen with an
appropriate message. Do not use the getline() or get functions!

Exercise 2: Once the program in Exercise 1 is complete, run the program and
enter the name Newmanouskous at the prompt. What, if anything,
happens? (Note that the results could vary depending on your system).
Exercise 3: Re-write the program above using the getline() function (and
only allowing 9 characters to be input). As before, use the character array
last consisting of 10 elements. Run your new program and enter
Newmanouskous at the prompt. What is the output?
Exercise 4: Bring in program grades.cpp and grades.txt from the Lab 10
folder. Fill in the code in bold so that the data is properly read from
grades.txt. and the desired output to the screen is as follows:

The grades.txt file: Adara Starr          94
David Starr          91
Sophia Starr         94
Maria Starr          91
Danielle DeFino      94
Dominic DeFino       98
McKenna DeFino       92
Taylor McIntire      99
Torrie McIntire      91
Emily Garrett        97
Lauren Garrett       92
Marlene Starr        83
Donald DeFino        73

OUTPUT TO SCREEN DATA FILE
Adara Starr has a(n) 94 average Adara Starr 94
David Starr has a(n) 91 average David Starr 91
Sophia Starr has a(n) 94 average Sophia Starr 94
Maria Starr has a(n) 91 average Maria Starr 91
Danielle DeFino has a(n) 94 average Danielle DeFino 94
Dominic DeFino has a(n) 98 average Dominic DeFino 98
McKenna DeFino has a(n) 92 average McKenna DeFino 92
Taylor McIntire has a(n) 99 average Taylor McIntire 99
Torrie McIntire has a(n) 91 average Torrie McIntire 91
Emily Garrett has a(n) 97 average Emily Garrett 97
Lauren Garrett has a(n) 92 average Lauren Garrett 92
Marlene Starr has a(n) 83 average Marlene Starr 83
Donald DeFino has a(n) 73 average Donald DeFino 73

The code of grades.cpp is as follows:
#include <fstream>
#include <iostream>
using namespace std;
// PLACE YOUR NAME HERE
const int MAXNAME = 20;
int main()
{
ifstream inData;
inData.open("grades.txt");
char name[MAXNAME + 1]; // holds student name
float average; // holds student average
Lesson 10B 193
inData.get(name,MAXNAME+1);
while (inData)
{
inData >> average;
// Fill in the code to print out name and
// student average
// Fill in the code to complete the while
// loop so that the rest of the student
// names and average are read in properly
}
return 0;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Knowledge Booster
Returning value from Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education