i need help with my Date.h & Date.cpp. cant figure out how to display it in my result.cpp & result.h, please use getline if you are able to. Will include all my files to help you run the whole thing. im stuck at this for sometime and couldnt figure it out.
Date.cpp
#include "Date.h"
#include <string>
#include <iostream>
using namespace std;
Date::Date()
{
dates = 0;
monthDates = "No new Month Yet.";
yearDates = 0;
}
Date::Date(unsigned day, string& month, unsigned year)
{
dates = day;
monthDates = month;
yearDates = year;
}
void Date::SetDay(unsigned day)
{
dates = day;
}
unsigned Date::GetDay() const
{
return dates;
}
void Date::SetMonth(const string& month)
{
monthDates = month;
}
void Date::GetMonth(string& month) const
{
month = monthDates;
}
void Date::SetYear(unsigned year)
{
yearDates = year;
}
unsigned Date::GetYear() const
{
return yearDates;
}
istream & operator >> (istream & input,Date & D)
{
}
ostream & operator << (ostream & os, const Date & D)
{
}
Date.h
#ifndef DATE_H
#define DATE_H
#include <string>
#include <iostream>
using namespace std;
class Date
{
public:
Date();
Date(unsigned day, string& month, unsigned year);
void SetDay(unsigned day);
unsigned GetDay() const;
void SetMonth(const string& month);
void GetMonth(string& month) const;
void SetYear(unsigned year);
unsigned GetYear() const;
//friend ostream & operator <<( ostream & os, const Date & D );
//friend istream & operator >>( istream & input, Date & D );
private:
int dates;
string monthDates;
int yearDates;
};
ostream & operator <<( ostream & os, const Date & D );
istream & operator >>( istream & input, Date & D );
#endif // DATE_H
Result.cpp
#include "Result.h"
#include "UNIT.H"
#include "Date.h"
#include<sstream>
Result::Result()
{
this->R_marks = 0;
}
Result::Result(Unit& U, Date& D , float m_marks)
{
R_Unit = U;
R_Date = D;
R_marks = m_marks;
}
void Result::SetUnit(Unit& U)
{
R_Unit = U;
}
void Result::GetUnit(Unit& U) const
{
U = R_Unit;
}
void Result::GetDate(Date& D) const
{
D = R_Date;
}
void Result::SetDate(Date& D)
{
R_Date = D;
}
void Result::SetMarks(float m_marks)
{
R_marks = m_marks;
}
float Result::GetMarks() const
{
return R_marks;
}
unsigned Result::GetCredits() const
{
return R_Unit.GetCredits();
}
void Result::SetCredits(unsigned cred)
{
credits = cred;
}
istream & operator >> (istream & input,Result & Re)
{
input >> Re.R_Unit >> Re.R_marks;
/*
Unit unit;
input >> unit;
Re.SetUnit(unit); */
string strInput;
getline(input, strInput,',');
stringstream ss(strInput);
float x = 0;
ss >> x;
Re.SetMarks(x);
//getline(input,strInput,',');
//stringstream ds(strInput);
return input;
}
ostream & operator << (ostream & os, const Result & Re)
{ //Unit unit;
//unit = Re.GetUnit();
//os << Re.GetUnit() << " Marks: " << Re.GetMarks() << '\n';
//os << Re.R_Unit << " Marks: " << Re.R_marks<< '\n';
os << Re.R_Unit << " Marks: " << Re.GetMarks() << '\n';
//os << Re.R_Unit << " Dates: " << Re.GetDate() << Re.<<'\n';
return os;
}
Result.h
#ifndef RESULT_H
#define RESULT_H
//This is a C++ string library
#include <string.h>
#include <string>
#include "Unit.H"
#include "Date.h"
using namespace std;
class Result
{
public:
Result();
Result(Unit& U, Date& D , float m_marks);
unsigned GetCredits() const;
void SetCredits(unsigned cred);
float GetMarks() const ; //{return R_marks;}
void SetMarks(float m_marks); //{R_marks = m_marks;}
void GetUnit(Unit& U) const; //{U = R_Unit;}
void SetUnit(Unit& U); //{R_Unit = U;}
void GetDate(Date& D) const;
void SetDate(Date& D);
friend ostream & operator <<( ostream & os, const Result & Re );
friend istream & operator >>( istream & input, Result & Re );
private:
Unit R_Unit;
Date R_Date;
float R_marks;
int credits;
};
//ostream & operator <<( ostream & os, const Result & Re );
//istream & operator >>( istream & input, Result & Re );
#endif // RESULT_H
Unit.cpp
#include "Unit.h"
#include <sstream>
#include <string>
#include <iostream>
#include <fstream>
Unit::Unit()
{
//name[0] = '\0';
//unitID[0] = '\0';
unitID = "No Unit ID Yet.";
unitName = "No Unit Name yet.";
credits = 0;
}
Unit::Unit(string& ID, string& nam, unsigned cred)
{
unitName = nam;
unitID = ID;
credits = cred;
}
void Unit::GetUnitID(string& unitsID) const
{
unitsID = unitID;
}
void Unit::SetUnitID(const string& unitsID)
{
unitID = unitsID;
}
void Unit::GetUnitName(string& unitsName) const
{
unitsName = unitName;
}
void Unit::SetUnitName(const string& unitsName)
{
unitName = unitsName;
}
unsigned Unit::GetCredits() const
{
return credits;
}
void Unit::SetCredits(unsigned cred)
{
credits = cred;
}
istream & operator >>( istream & input, Unit & U)
{
//input >> U.unitID >> U.name >> U.credits;
string strInput;
getline(input,strInput, ',');
U.SetUnitID(strInput);
getline(input, strInput, ',');
U.SetUnitName(strInput);
getline(input, strInput, ',');
stringstream ss(strInput);
int x = 0;
ss >> x;
U.SetCredits(x);
return input;
}
ostream & operator <<( ostream & os, const Unit & U )
{
string uName;
string uID;
U.GetUnitName(uName);
U.GetUnitID(uID);
os << " Unit: " << uName << '\n'
<< " Unit ID: " << uID << '\n'
<< " Credits: " << U.GetCredits() << '\n';
return os;
}
Unit.h
#ifndef UNIT_H
#define UNIT_H
#include <iostream>
#include <string>
#include <string.h> // C string library
using namespace std;
const unsigned UnitNameSize = 100;
const unsigned UnitIDsize = 10;
class Unit {
public:
Unit();
//Unit( const char * ID, char * nam, unsigned cred );
Unit(string& ID, string& nam, unsigned cred);
Unit(const Unit & other);
unsigned GetCredits() const;
// Get the number of credits.
void SetCredits( unsigned cred );
// Set the number of credits.
void GetUnitName(string& unitsName) const;
void SetUnitName(const string& unitsName);
void GetUnitID(string& unitsID) const;
void SetUnitID(const string& unitsID);
//friend ostream & operator <<( ostream & os, const Unit & U );
//friend istream & operator >>( istream & input, Unit & U );
private:
//char name[UnitNameSize]; // course name, C style string. not a C++ string object
string unitName;
string unitID;
// char unitID[UnitIDsize];
int credits; // number of credits
};
ostream & operator <<( ostream & os, const Unit & U );
istream & operator >>( istream & input, Unit & U );
#endif
Main.cpp
#include <iostream>
#include <fstream>
#include "Unit.h" // Course class declaration
#include "regist.h" // Registration class declaration
using namespace std;
int main()
{
ifstream infile( "Resultsinput.txt" );
if( !infile ) return -1;
Registration R;
infile >> R;
ofstream ofile( "Resultsoutput.txt" );
// Use a debugger and track down the calls made "behind the scene"
ofile << R
<< "Number of Units = " << R.GetCount() << '\n'
<< "Total credits = " << R.GetCredits()<< '\n';
return 0;
}
Regist.h
// REGIST.H - Registration class definition
// author KRI
// modified smr
#ifndef REGIST_H
#define REGIST_H
#include <iostream>
#include "Result.h"
using namespace std;
const unsigned MaxResultsUnit = 100;
class Registration {
public:
Registration();
unsigned GetCredits() const;
unsigned GetCount() const;
friend ostream & operator <<( ostream & os,
const Registration & R);
friend istream & operator >>( istream & input,
Registration & R );
private:
long studentId; // student ID number
unsigned semester; // semester year, number
unsigned count; // number of courses
Result Results[MaxResultsUnit]; // array of courses
};
inline unsigned Registration::GetCount() const
{
return count;
}
#endif
Regist.cpp
#include "regist.h"
Registration::Registration()
{
count = 0;
}
unsigned Registration::GetCredits() const
{
unsigned sum = 0;
for(unsigned i = 0; i < count; i++)
sum += Results[i].GetCredits();
return sum;
}
istream & operator >>( istream & input, Registration & R )
{
input >> R.studentId >> R.semester >> R.count;
for(unsigned i = 0; i < R.count; i++)
input >> R.Results[i]; // track down which >> operator is called. Hint: look at what is being input.
return input;
}
ostream & operator <<( ostream & os, const Registration & R )
{
os << "Student ID: " << R.studentId << '\n'
<< "Semester: " << R.semester << '\n';
for(unsigned i = 0; i < R.count; i++)
os << R.Results[i] << '\n';
return os;
}
Resultsinput.txt
123456789 1 2 ICT283,Data Structure And Abstractions,3,90,1,2,2019 ICT287,Computer Graphics,3,97, 1,1,2018
Aucun commentaire:
Enregistrer un commentaire