Question

In this exercise, you will have to create from scratch and utilize a class called Student1430. Student 1430 has 4 private memRequested files main.cpp #include Student1430.h class FileNotFoundException {}; опеw NP using namespace std; 7 8 - int maininfile >> grade; S.setExamGrade(grade, i+1); s.getAverage(); cout << s.getFirstName() << « s.getLastName() << has an avH уоси араассност иус, Od 20 21 AWN public: Student1430(); Student1430(string f, string l, int e[]); void setFirstName(string

using C++ language!! please help me out with this homework

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code is as follows:

main.cpp

#include "Student1430.h"
class FileNotFoundException {};
using namespace std;
int main(int argc, char**argv)
{
string s1, s2;
int grade;
int a = 0;
Student1430 s;
ifstream infile(argv[1]);
// Define the try and cath blocks here
try {
if(!infile)
throw FileNotFoundException();
}
catch (FileNotFoundException f ) {
cout << "File not found.\n";
return -1;
}

  
  
while(!infile.eof())
{
infile >> s1 >> s2;
s.setFirstName(s1);
s.setLastName(s2);
for(int i =0; i<4; i++)
{
infile >> grade;
s.setExamGrade(grade, i+1);
}
cout << s.getFirstName() << " " << s.getLastName() << " has an average of " << s.getAverage();
cout << " and will get a " << s.finalGrade() << endl;
if(s.finalGrade() == "A")
a++;
}
cout << endl << "Total A in class: " << a << endl;
infile.close();
return 0;
}

2 class FileNotFoundException {1}} 3 using namespace std; 4 int main(int argc, char* argv), no van DWN string s1, s2; int gracout << endl << Total A in class: << a << endl; infile.close(); return 0;

***********************************************************************************************************************************

Student1430.h

#ifndef STUDENT1430_H
#define STUDENT1430_H
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Student1430 {
private:
string firstName;
string lastName;
int exams[4];
double average;
void updateAverage();
public:
Student1430();
Student1430(string f, string l, int e[]);
void setFirstName(string f);
void setLastName(string l);
void setExamGrade(int grade, int pos);
string getFirstName();
string getLastName();
double getAverage();
string finalGrade();
};
#endif

2 #define STUDENT1430_H 3 #include <iostream> 4 #include <fstream> #include <string> 6 using namespace std; 7. class Student1

***********************************************************************************************************************************

Student1430.cpp

#include "Student1430.h"

Student1430::Student1430(){
firstName=""; //initiualise to empty string and all to 0
lastName="";
exams[4]={0};
average=0;
}

Student1430::Student1430(string f, string l, int e[]){
firstName=f; //constructor for firstName and lastName
lastName=l;
for(int i=0;i<4;i++){
exams[i] = e[i];
}
updateAverage(); //call the updateAverage
}

void Student1430::updateAverage(){
average = 0; //update the avergae
for(int i=0;i<4;i++){
average+=exams[i];
}
average = average/4;//find sum and find average
}

void Student1430::setFirstName(string f){
firstName = f; //set the firstName
}

void Student1430::setLastName(string l){
lastName = l; //set the lastName
}

void Student1430::setExamGrade(int grade,int pos){
exams[pos-1]=grade; //set the exams grade of exams number
}

string Student1430::getFirstName(){
return firstName; //get firstName
}

string Student1430::getLastName(){
return lastName; //getLastName
}
double Student1430::getAverage(){
updateAverage(); //first updateAverage
return average; //getAverage
}


string Student1430::finalGrade(){ //find grade based on average
if(average>=90)
return "A";
else if(average<90 && average>=80)
return "B";
else if(average<80 && average>=70)
return "C";
else if(average<70 && average>=60)
return "D";
else if(average<60)
return "F";
}

***********************************************************************************************************************************

Screenshot of the code:

1 #include Student1430.h o dovou pw student 1430::Student1430({ firstName=; //initiualise to empty string and all to a la35 void student1430::setExamGrade(int grade, int pos) { 36 exams[pos-1]=grade; //set the exam grade of exam number 37 } 38 39

Sample input file:

stud.txt

Bruce Adams 45 15 45 90
Shashi Tharoor 90 95 95 95
Adam Gilchrist 89 80 70 50

On providing file name as command line argumentTIPUL Command line arguments: stud.txt

output is

Bruce Adams has an average of 48.75 and will get a fi Shashi Tharoor has an average of 93.75 and will get a A Adam Gilchrist

if not provided or the file name is wrong then the output

File not found. ... Program finished with exit code 255 Press ENTER to exit console. I

Add a comment
Know the answer?
Add Answer to:
using C++ language!! please help me out with this homework In this exercise, you will have...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • "Function does not take 0 arguments". I keep getting this error for my last line of...

    "Function does not take 0 arguments". I keep getting this error for my last line of code: cout << "First Name: " << employee1.getfirstName() << endl; I do not understand why. I am trying to put the name "Mike" into the firstName string. Why is my constructor not working? In main it should be set to string firstName, string lastName, int salary. Yet nothing is being put into the string. #include<iostream> #include<string> using namespace std; class Employee {    int...

  • The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried t...

    The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...

  • help please Program Requirements You are given 1 file: Lab1Tests.java. You need to complete 1 file:...

    help please Program Requirements You are given 1 file: Lab1Tests.java. You need to complete 1 file: UWECPerson.java uWECPerson.java UWECPerson uwecld: int firstName: String lastName : String +UWECPerson(uwecld: int, firstName : String, lastName: String) +getUwecid): int setUwecld(uwecld: int): void +getFirstName): String +setFirstName(firstName: String): void getLastName): String setLastName(lastName: String): void +toString): String +equals(other: Object): boolean The constructor, accessors, and mutators behave as expected. The equals method returns true only if the parameter is a UWECPerson and all instance variables are equal. The...

  • Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string...

    Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string SSN; The Employee class has ▪ a no-arg constructor (a no-arg contructor is a contructor with an empty parameter list): In this no-arg constructor, use “unknown” to initialize all private attributes. ▪ a constructor with parameters for each of the attributes ▪ getter and setter methods for each of the private attributes ▪ a method getFullName() that returns the last name, followed by a...

  • Here is the code from the previous three steps: #include <iostream> using namespace std; class Student...

    Here is the code from the previous three steps: #include <iostream> using namespace std; class Student { private: //class variables int ID; string firstName,lastName; public: Student(int ID,string firstName,string lastName) //constructor { this->ID=ID; this->firstName=firstName; this->lastName=lastName; } int getID() //getter method { return ID; } virtual string getType() = 0; //pure virtual function virtual void printInfo() //virtual function to print basic details of a student { cout << "Student type: " << getType() << endl; cout << "Student ID: " << ID...

  • A hard c++ problem ◎Write a c++ program”Student.h”include Private data member, string firstName; string lastName; double...

    A hard c++ problem ◎Write a c++ program”Student.h”include Private data member, string firstName; string lastName; double GPA(=(4.0*NumberOfAs+3.0*NumberOfBs+2.0*NumberOfCs+1.0*NumberOfDs)/( As+Bs+Cs+Ds+Fs)); Public data member, void setFirstName(string name); string getFirstName() const; void printFirstName() const; void getLastName(string name); string getLastName() const; void printLastName() const; void computeGPA(int NumberOfAs,int NumberOfBs,int NumberOfCs,int NumberOfDs,int NumberOfFs); double getGPA() const; double printGPA() const; A destructor and an explicit default constructor initializing GPA=0.0 and checking if GPA>=0.0 by try{}catch{}. Add member function, bool operator<(const Student); The comparison in this function based on...

  • In c++ redefine the class personType to take advantage of the new features of object-oriented design...

    In c++ redefine the class personType to take advantage of the new features of object-oriented design that you have learned, such as operator overloading, and then derive the class customerType. personType: #include <string> using namespace std; class personType { public: void print() const; //Function to output the first name and last name //in the form firstName lastName.    void setName(string first, string last); //Function to set firstName and lastName according to the //parameters. //Postcondition: firstName = first; lastName = last...

  • Please implement the following problem in basic C++ code and include detailed comments so that I...

    Please implement the following problem in basic C++ code and include detailed comments so that I am able to understand the processes for the solution. Thanks in advance. // personType.h #include <string> using namespace std; class personType { public: virtual void print() const; void setName(string first, string last); string getFirstName() const; string getLastName() const; personType(string first = "", string last = ""); protected: string firstName; string lastName; }; // personTypeImp.cpp #include <iostream> #include <string> #include "personType.h" using namespace std; void...

  • My main() file does not call to the class created in a .hpp file. It comes...

    My main() file does not call to the class created in a .hpp file. It comes out with the error "undefined reference to "___" const. I want to solve this by only changing the main() .cpp file, not the .hpp file. .cpp file .hpp file Thank you! include <iostream> include <string> tinclude "CourseMember.hpp using namespace std int main0 CourseMember CourseMember(90, "Jeff", "Goldblum"): // initializing the constructor cout<< "Member ID is <<CourseMember.getID) << endl; 1/ calling getID) accessor cout <<"First Name...

  • How could I separate the following code to where I have a gradebook.cpp and gradebook.h file?...

    How could I separate the following code to where I have a gradebook.cpp and gradebook.h file? #include <iostream> #include <stdio.h> #include <string> using namespace std; class Gradebook { public : int homework[5] = {-1, -1, -1, -1, -1}; int quiz[5] = {-1, -1, -1, -1, -1}; int exam[3] = {-1, -1, -1}; string name; int printMenu() { int selection; cout << "-=| MAIN MENU |=-" << endl; cout << "1. Add a student" << endl; cout << "2. Remove a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT