#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 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; }
#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 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; }
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter16: Searching, Sorting And Vector Type
Section: Chapter Questions
Problem 20PE
Related questions
Question
#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
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; }
![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:
OUTPUT TO SCREEN
DATA FILE
has a(n) 94 average
has a(n) 91 average
has a(n) 94 average
has a(n) 91 average
has a(n) 94 average
has a(n) 98 average
has a(n) 92 average
has a(n) 99 average
has a(n) 91 average
has a(n) 97 average
has a(n) 92 average
has a(n) 83 average
has a(n) 73 average
Adara Starr
Adara Starr
94
David Starr
David Starr
91
Sophia Starr
Maria Starr
Sophia Starr
94
Maria Star
91
Danielle DeFino
Danielle DeFino
94
Dominic DeFino
Dominic DeFino
98
McKenna DeFino
McKenna DeFino
92
Taylor McIntire
Torrie McIntire
Taylor McIntire
Torrie McIntire
99
91
Emily Garrett
Emily Garrett
97
Lauren Garrett
Lauren Garrett
92
Marlene Starr
Marlene Starr
83
Donald DeFino
Donald DeFino
73](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5ed0dfb3-9b48-444a-9e07-d3aac88220ce%2Fd7e4cf8c-e7f5-4759-8bf1-8a9dd682b465%2Fk02hjp_processed.png&w=3840&q=75)
Transcribed Image Text: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:
OUTPUT TO SCREEN
DATA FILE
has a(n) 94 average
has a(n) 91 average
has a(n) 94 average
has a(n) 91 average
has a(n) 94 average
has a(n) 98 average
has a(n) 92 average
has a(n) 99 average
has a(n) 91 average
has a(n) 97 average
has a(n) 92 average
has a(n) 83 average
has a(n) 73 average
Adara Starr
Adara Starr
94
David Starr
David Starr
91
Sophia Starr
Maria Starr
Sophia Starr
94
Maria Star
91
Danielle DeFino
Danielle DeFino
94
Dominic DeFino
Dominic DeFino
98
McKenna DeFino
McKenna DeFino
92
Taylor McIntire
Torrie McIntire
Taylor McIntire
Torrie McIntire
99
91
Emily Garrett
Emily Garrett
97
Lauren Garrett
Lauren Garrett
92
Marlene Starr
Marlene Starr
83
Donald DeFino
Donald DeFino
73
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
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.Recommended textbooks for you
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning