The file numbers InFile_yourLastName.txt stores one string and 5 decimal numbers in one line. For example: James Smith 76.23 62.55. 90.12 74.23 78.25
The following C++ program is not correct that am first opens the file numbersInFile_yourLastName.txt. Read the name and five numbers.
Sample code:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main()
{
string firstName[30], lastName[30], mark1[30], mark2[30],
mark3[30], mark4[30], mark5[30];
ifstream myfile ("numbersInFile_yourLastName.txt");
ofstream out("data_yourName.txt");
int id = 0;
if(!myfile)
{
cout<<"Error opening output
file"<<endl;
return 0;
}
int count = 0;
while(!myfile.eof())
{
getline(myfile,firstName[id], ' ');
getline(myfile,lastName[id],' ');
getline(myfile,mark1[id],' ');
getline(myfile,mark2[id],' ');
getline(myfile,mark3[id],' ');
getline(myfile,mark4[id],' ');
getline(myfile,mark5[id],'\n');
id++;count++;
}
int inc; float m1, m2, m3, m4, m5, avg;
if (count>0){
for(inc=0; inc<count; inc++)
{
stringstream
geek1(mark1[inc]);
geek1 >> m1;
stringstream
geek2(mark2[inc]);
geek2 >> m2;
stringstream
geek3(mark3[inc]);
geek3 >> m3;
stringstream
geek4(mark4[inc]);
geek4 >> m4;
stringstream
geek5(mark5[inc]);
geek5 >> m5;
avg =
(m1+m2+m3+m4+m5)/5;
out <<" Name=
"<<firstName[inc]<<" "<<lastName[inc]
<<endl;
out <<" Average=
"<<setprecision(4)<<avg<< endl;
}
}
myfile.close();
out.close();
return 0;
}
sample numbersInFile_yourLastName.txt file:
James Smith 76.23 62.55 90.12 74.23 78.25
Sample output file
Name= James Smith
Average= 76.28
The file numbers InFile_yourLastName.txt stores one string and 5 decimal numbers in one line. For example:...
Write a simple telephone directory program in C++ that looks up phone numbers in a file containing a list of names and phone numbers. The user should be prompted to enter a first name and last name, and the program then outputs the corresponding number, or indicates that the name isn't in the directory. After each lookup, the program should ask the user whether they want to look up another number, and then either repeat the process or exit the...
Use the file processing example program shown at the bottom. Modify the program to enter the grades, and count number of grades. Also get total and average grade. Use the following data for grades: 79, 99, 85, 97, 88, 95, 100, 87, 94 EXAMPLE OUTPUT Total: 9 grades Total grade sum: 824 Average grade: 92 Letter grade: A / Using Break, and Continue #include "stdafx.h" #include using namespace std; int main() { int i = 0; for (int x =...
C++ Homework Help: The text file that it wants you to download is this: Name: Peter Parker CSCI-261: 95 CSCI-262: 90.625 CSCI-442: 91.20 Name: Mary Smith CSCI-442: 65.0 CSCI-562: 79.1234 CSCI-580: 70.24 Name: Pat Brown CSCI-562: 95 CSCI-565: 88.0 CSCI-580: 91.20 Name: Linda Williams CSCI-262: 65.0 CSCI-306: 67.719 CSCI-562: 70.200 Name: John Miller CSCI-261: 95.281 CSCI-306: 90.625 CSCI-565: 91.20 Name: Patricia Johnson CSCI-306: 65.012 CSCI-442: 84.76 CSCI-580: 70 Name: Brian Hall CSCI-261: 65.0 CSCI-306: 84.712 CSCI-442: 75.24 Name: Sandra Nelson...
I wrote code in C++ that takes a text file containing information on different football players and their combine results, stores those players as a vector of objects of the class, and prints out those objects. Finally, I wrote a function that calculates the average weight of the players. MAIN.CPP: #include "Combine.h" #include using namespace std; // main is a global function // main is a global function int main() { // This is a line comment //cout << "Hello,...
C++ Write a function parseScores which takes a single input argument, a file name, as a string. Your function should read each line from the given filename, parse and process the data, and print the required information. Your function should return the number of student entries read from the file. Empty lines do not count as entries, and should be ignored. If the input file cannot be opened, return -1 and do not print anything. Your function should be named...
IN C++ PLEASE -------Add code to sort the bowlers. You have to sort their parallel data also. Print the sorted bowlers and all their info . You can use a bubble sort or a shell sort. Make sure to adjust your code depending on whether or not you put data starting in row zero or row one. Sort by Average across, lowest to highest. The highest average should then be on the last row.. When you sort the average, you...
Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a student's name (on one line). Then, for each course the student took last semester, the file has 2 data lines. The course name is on the first line. The second line has the student's grade average (0 to 100) and the number of credits for the course Sample data: Jon P. Washington, Jr. Computer Science I 81 4 PreCalculus 75 3 Biology I 88...
Hi there, I am working on a binary search tree code in c++. The program must store and update students' academic records, each node includes the student name, credits attempted, credits earned and GPA. I have made some progress with the code and written most of the functions in the .cpp file (already did the .h file) but i am struggling with what to put in the main and how to put an update part in the insert function. I...
can someone please comment through this code to explain me specifically how the variables and arrays are working? I am just learning arrays code is below assignment C++ Programming from Problem Analysis to Program Design by D. S. Malik, 8th ed. Programming Exercise 12 on page 607 Lab9_data.txt Jason, Samantha, Ravi, Sheila, and Ankit are preparing for an upcoming marathon. Each day of the week, they run a certain number of miles and write them into a notebook. At the...
The purpose of this assignment is to develop solutions that perform File IO and objects. Problem specifications are shown below with my changes in blue. 1. File Previewer Write a program that asks the user for the name of a text file. The program should display the first 10 lines of the file on the screen. If the file has fewer than 10 lines, the entire file should be displayed along with a message indicating the entire file has been...