
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;
}

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 6 images

- Write in Python Write a function named max that accepts two float values as arguments and returns the value that is the greater of the two. For example, if 7.2 and 12.1 are passed as arguments to the function, the function should return 12.1. Use the function in a program that prompts the user to enter two float values. The program should display the value that is the greater of the two.arrow_forwardWhat's Hiding Amongst the Crowd? Language - Java Script A word is on the loose and now has tried to hide amongst a crowd of tall letters! Help write a function to detect what the word is, knowing the following rules: The wanted word is in lowercase. The crowd of letters is all in uppercase. Note that the word will be spread out amongst the random letters, but their letters remain in the same order. ● Examples detectWord("UcUNFYGaFYFYGtNUH") → "cat" detectWord("bEEFGBuFBRrHgUHINFYaYr") → "burglar" detectWord("YFem HUFBbezFBYZF BYLleGBYEFGBMENTment") → "embezzlement"arrow_forwardPlease tell me where I get wrong.arrow_forward
- # dates and times with lubridateinstall.packages("nycflights13") library(tidyverse)library(lubridate)library(nycflights13) Qustion: Create a function called date_quarter that accepts any vector of dates as its input and then returns the corresponding quarter for each date Examples: “2019-01-01” should return “Q1” “2011-05-23” should return “Q2” “1978-09-30” should return “Q3” Etc. Use the flight's data set from the nycflights13 package to test your function by creating a new column called quarter using mutate()arrow_forwardWrite a C++ program that will input temperatures for consecutive days. The program will store these values into an array and call a function that will return the average of the temperatures. It will also call a function that will return the highest temperature and a function that will return the lowest temperature. The user will input the number of temperatures to be read. There will be no more than 25 temperatures. For Full Credit You must have a comment block header at the top of your program. See the Standards document in Course Content You must use a constant to represent the maximum number of temperature readings You must use the correct data types for your constants and variables You must use an array of the correct data type You must validate your input. Check for number of invalid number of readings (> max, < 1, etc) and display appropriate error message. You must use one or more if/else branches for your decisions You must use a loop to read in the temperatures…arrow_forwardDon't send AI generated answer or plagiarised answer. If I see these things I'll give you multiple downvotes and will report immediately.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





