I wrote some code and it builds but everytime I run it, It shows the error message in the else statement
NOTE: I have completed the program for your assignment. Please check and let me know if you have any questions. I will acknowledge back with a response within 24 hours. Thanks for your patience.
Program explanation:
1) The program asks user for an input filename which contains
student scores to read
2) The program creates an output file testAverage.txt to store the
average of student scores
3) Before processing the input file the program validates if it
exists.
4) If input file exists the program reads each line in input file
and calculates sum and average of the student scores
5) If input file does not exists it displays error message to the
user and exits.
Code:
sh-4.4$ cat lab7.cpp
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
// declaring variables
string firstName, lastName, fileName;
double test1, test2, test3, test4, average, sum=0.0;
ifstream inputFile;
ofstream outputFile;
// taking input filename from the user
cout <<"Enter the input filename: ";
cin >> fileName;
// opening the input file given
inputFile.open(fileName.c_str());
// creating the output file
outputFile.open("testAverage.txt");
// if inputFile given exists
if(inputFile){
// writing the header part to output file
outputFile << "=====CSE100 Report=====";
outputFile << "\n";
outputFile << "Name" << "\t" << "Test Average"
<< "\n";
// Iterating through each line in input file and taking required
fields
while(inputFile >> firstName >> lastName >> test1
>> test2 >> test3 >> test4){
// initialize sum and average on each line
sum = average = 0.0;
// summing the scores
sum += test1 + test2 + test3 + test4;
// calculating the average
average = sum / 4.0;
// writing the average and other fields to output fields
outputFile << firstName << " " << lastName
<< "\t" << fixed << setprecision(2) <<
average << endl;
}
}
// if inputFile does not exists
else{
cout << "\n Error opening the file";
}
return 0;
}
Code output screenshot:
I wrote some code and it builds but everytime I run it, It shows the error...
What this Lab Is About: Given a UML diagram, learn to design a class Learn how to define constructor, accessor, mutator and toStringOmethods, etc Learn how to create an object and call an instance method. Coding Guidelines for All ments You will be graded on this Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc) Keep identifiers to a reasonably short length. Use upper case for constants. Use title case (first letter is u case)...
Lab #7 CSE110 - Arizona State University Topics • Basic arrays Coding Guidelines • Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). • Keep identifiers to a reasonably short length. • Use upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects). • Use tabs or spaces to indent code within blocks (code surrounded by braces)....
please answer correctly and follow the code structure given [JavaFX/ Exception handing and text I/O] 1. Write a program for the following. NOTE that some of these steps are not dependent on each other. Using methods is mandatory. Make sure to use methods where it makes sense. a. Ask the user for a series of integers entered from the keyboard. Use a sentinel value such as 999 to end the input process. If the entered values are not integers, throw...
Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What This Assignment Is About? Classes (methods and attributes) • Objects Arrays of Primitive Values Arrays of Objects Recursion for and if Statements Selection Sort Use the following Guidelines: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc.) Use upper case for constants. • Use title case (first letter is upper case) for classes. Use lower case with uppercase...
For this lab assignment, you will be writing a few classes that can be used by an educator to grade multiple choice exams. It will give you experience using some Standard Java Classes (Strings, Lists, Maps), which you will need for future projects. The following are the required classes: Student – a Student object has three private instance variables: lastName, a String; firstName, a String; and average, a double. It has accessor methods for lastName and firstName, and an accessor...
The following code uses a Scanner object to read a text file called dogYears.txt. Notice that each line of this file contains a dog's name followed by an age. The program then outputs this data to the console. The output looks like this: Tippy 2 Rex 7 Desdemona 5 1. Your task is to use the Scanner methods that will initialize the variables name1, name2, name3, age1, age2, age3 so that the execution of the three println statements below will...
I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not declared in this scope" in my main.cpp. Here are my codes. main.cpp #include <iostream> #include <string> #include "functions.h" using namespace std; //definition of the main function. //takes arguments from the command-line. int main(int argc, char *argv[]) { //Determine if you have enough arguments. //If not, output a usage message and exit program if (argc<2 || (argc == 2 && argv[1][0] == '-')) { //call...
the source code I have is what i'm supposed to fix for the assignment at the bottom. cars.cpp source code: /* Program Cars.cpp reads records from file and writes them back to another file with the price member increased by 10%. */ #include <fstream> #include <iostream> #include <string> #include "car.h" // car.h header file is included here using namespace std; /* Reads data from a file and using it to populate a Car struct and then return that Car struct...
Please I need help in C language, I am trying to modify the code per the below instructions, but I am getting errors. Can't fgure it out. The attempted code modification and data file is privided below, after the instructions. Thank you. Instructions: 1. First, add a function named printMsg that displays a message, a greeting, or an introduction to the program for the user. Add a statement that calls that function from the main function when your program starts....
***C++ Code*** What this Assignment Is About: -Learn to define and call void & non-void functions -Learn to use reference variables Coding Guidelines for All Labs/Assignments (You will be graded on this) -Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). -Keep identifiers to a reasonably short length. -Use upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables,...