using C++ language!! please help me out with this homework
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;
}
***********************************************************************************************************************************
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
***********************************************************************************************************************************
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:
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 argument
output is
if not provided or the file name is wrong then the output
using C++ language!! please help me out with this homework In this exercise, you will have...
"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 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: 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 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 { 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 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 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 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 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? #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...