Answered step by step
Verified Expert Solution
Question
1 Approved Answer
LAB 1 0 . 3 Using getline ( ) & get ( ) Exercise 1 : Write a short program called readata.cpp that defines a
LAB Using getline & get
Exercise : Write a short program called readata.cpp that defines a character
array last which contains characters. Prompt the user to enter their last
name using no more than 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 : Once the program in Exercise 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 : Rewrite the program above using the getline function and
only allowing characters to be input As before, use the character array
last consisting of elements. Run your new program and enter
Newmanouskous at the prompt. What is the output?
Exercise : Bring in program grades.cpp and grades.txt from the Lab
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 DATAFILE
Adara Starr has an average Adara Starr
David Starr has an average David Starr
Sophia Starr has an average Sophia Starr
Maria Starr has an average Maria Starr
Danielle DeFino has an average Danielle DeFino
Dominic DeFino has an average Dominic DeFino
McKenna DeFino has an average McKenna DeFino
Taylor McIntire has an average Taylor McIntire
Torrie McIntire has an average Torrie McIntire
Emily Garrett has an average Emily Garrett
Lauren Garrett has an average Lauren Garrett
Marlene Starr has an average Marlene Starr
Donald DeFino has an average Donald DeFino
The code of grades.cpp is as follows:
#include
#include
using namespace std;
PLACE YOUR NAME HERE
const int MAXNAME ;
int main
ifstream inData;
inData.opengradestxt;
char nameMAXNAME ; holds student name
float average; holds student average
Lesson B
inData.getnameMAXNAME;
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 ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started