Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 code of grades.cpp is as follows:

___________________________________________________________________

#include

#include

using namespace std;

// PLACE YOUR NAME HERE

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

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Eric Redmond ,Jim Wilson

1st Edition

1934356921, 978-1934356920

More Books

Students also viewed these Databases questions

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago