task Problem set Methode

Pages: 12
Hi I have problems implementing a method set :


I have implemented it in the CCalendarEntry.cpp but getting errors . Please Help:



Here are the codes:
In the header there are description in german. You can translate it with google


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

#ifndef MYCODE_CJULIANDATE_H_
#define MYCODE_CJULIANDATE_H_

#include <string>
#include<iostream>
using namespace std;


/**
 * Diese Klasse repr�sentiert ein Julianisches Datum ohne Uhrzeit.
 */
class CJulianDate {
private:
	long m_days;

	/**
	 * Formatiert die �bergebene Tagesnummer (1-31) wie folgt: Ist die Zahl
	 * einstellig, wird ein Leerzeichen vorangestellt (3 --> " 3"). Stimmt
	 * die Zahl mit dem Tag des von diesem Objekt repr�sentierten
	 * gregorianischen Datums �berein, wird das Ergebnis mit eckigen
	 * Klammern umgeben ("10" --> "[10]"), sonst werden am Anfang und
	 * am Ende je ein Leerzeichen erg�nzt ("10" --> " 10 ").
	 */
	std::string formatDayNumber (short day) const;

public:
	/**
	 * Erzeugt ein neues Objekt mit dem angegebenen Julianischen Datum.
	 */
	CJulianDate(long date = 0);

	/**
	 * Erzeugt ein neues Objekt, dessen Wert aus dem angegebene Gregorianische Datum
	 * berechnet wird.
	 *
	 * - year: das Jahr
	 * - month: der Monat (Januar = 1)
	 * - day: der Tag (erster Tag eines Monats: 1)
	 */
	CJulianDate(int year, short month, short day);

	/**
	 * Liefert das Julianische Datum (Tage seit dem 1. Januar -4712 (4713 v. Chr)).
	 */
	long getJulianDate() const;

	/**
	 * �bernimmt das angegebene Julianische Datum.
	 */
	void setJulianDate(long date);

	/**
	 * Liefert den aktuallen Wert als Gregorianisches Datum.
	 *
	 * - year: das Jahr
	 * - month: der Monat (Januar = 1)
	 * - day: der Tag (erster Tag eines Monats: 1)
	 */
	void toGregorianDate(int& year, short& month, short& day) const;

	/**
	 * Konvertiert und �bernimmt das angegebene Gregorianische Datum.
	 *
	 * - year: das Jahr
	 * - month: der Monat (Januar = 1)
	 * - day: der Tag (erster Tag eines Monats: 1)
	 */
	void fromGregorianDate(int year, short month, short day);

	/**
	 * Liefert den Wochentag zu dem aktuellen Datum (Montag = 1).
	 */
	int dayOfWeek() const;

	/**
	 * Liefert den Namen des Wochentags zu dem aktuellen Datum (Montag = 1).
	 */
	std::string dayOfWeekAsName() const;

	/**
	 * Addiert die angegebene Anzahl Tage zu diesem Julianischen Datum hinzu.
	 */
	CJulianDate& operator+= (long days) {
		m_days += days;
		return *this;
	}

	/**
	 * Vergleicht zwei Julianische Daten und liefert true, wenn das als
	 * linker Operand angegebene Datum vor dem als rechter Operand
	 * angegebenen liegt.
	 */
	void prettyprintmonth();
	long operator- (const CJulianDate other);
	bool operator< (const CJulianDate& rhs) const;
	friend ostream& operator<<(ostream& lop,const CJulianDate& rhs );

};
ostream& operator<<(ostream& lop,const CJulianDate& rhs );

#endif /* MYCODE_CJULIANDATE_H_ */



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

#include "CJulianDate.h"
#include <cstdio>

//===============================================
// Erg�nzen Sie Ihren Code am Ende dieser Datei!
//===============================================

CJulianDate::CJulianDate(long date) {
	m_days = date;
}

CJulianDate::CJulianDate(int year, short month, short day) {
	fromGregorianDate(year, month, day);
}

long CJulianDate::getJulianDate() const {
	return m_days;
}

void CJulianDate::setJulianDate(long date) {
	m_days = date;
}

void CJulianDate::toGregorianDate(int& year, short & month, short & day) const {
	long i, j, k, l, n;

	l = m_days + 68569;
	n = 4 * l / 146097;
	l = l - (146097 * n + 3) / 4;
	i = 4000 * (l + 1) / 1461001;
	l = l - 1461 * i / 4 + 31;
	j = 80 * l / 2447;
	k = l - 2447 * j / 80;
	l = j / 11;
	j = j + 2 - 12 * l;
	i = 100 * (n - 49) + i + l;

	year = i;
	month = j;
	day = k;
}

void CJulianDate::fromGregorianDate(int year, short month, short day) {
	m_days = day - 32075 + 1461 * (year + 4800 + (month - 14) / 12) / 4
			+ 367 * (month - 2 - (month - 14) / 12 * 12) / 12
			- 3 * ((year + 4900 + (month - 14) / 12) / 100) / 4;
}

int CJulianDate::dayOfWeek() const {
	return (m_days % 7) + 1;
}

std::string CJulianDate::dayOfWeekAsName() const {
	switch (dayOfWeek()) {
	case 1:
		return "Montag";
	case 2:
		return "Dienstag";
	case 3:
		return "Mittwoch";
	case 4:
		return "Donnerstag";
	case 5:
		return "Freitag";
	case 6:
		return "Samstag";
	case 7:
		return "Sonntag";
	default:
		return "(Fehler)";
	}
}

std::string CJulianDate::formatDayNumber(short day) const {
	char buffer[5];
	int year;
	short month;
	short refDay;

	toGregorianDate(year, month, refDay);
	sprintf(buffer, day == refDay ? "[%2d]" : " %2d ", day);
	return std::string(buffer);
}

bool CJulianDate::operator <(const CJulianDate& rhs) const {
	return m_days < rhs.m_days;
}

//=====================================================
// Erg�nzen Sie Ihren Code unterhalb dieses Kommentars
//=====================================================


ostream& operator<<(ostream& lop,const CJulianDate& rhs ){
	int year;
	short month;
    short day;
    rhs.getJulianDate();


    rhs.toGregorianDate(year,month,day);

    //cout << year << " " <<  month << " " << day << endl;

	lop <<"Semesterbeginn:" <<  rhs.dayOfWeekAsName() << "," << day << "," << month << "," << year;
	return lop;


}
long CJulianDate::operator- (const CJulianDate other){

 m_days = this->m_days -other.m_days;
}

void CJulianDate::prettyprintmonth(){

	CJulianDate current(this->getJulianDate());
	int year;
	short month;
	short day;

	current.toGregorianDate(year,month,day);

	current.fromGregorianDate(year, month, 1);

	short printmonth = month;

	current += -(current.dayOfWeek() - 1);

	current.toGregorianDate(year, month, day);

	cout << "y:" << year << " m:" << month << " d:" << day;

	if(month < printmonth){
		cout << "" << "" << "" << "" << endl;


	}
	else{


		current.formatDayNumber( day);
	}

	if(current.dayOfWeekAsName() == "Sonntag"){

		cout << "" <<endl;
	}
	else {

		current.setJulianDate(current.getJulianDate()+1);

		current = current.dayOfWeek()+1;
		current.toGregorianDate(year,month,day);


	}

	if( month<= printmonth){


	cout << "" << "" << "" << "" << endl;


			}
			else{
				current.formatDayNumber(day);
			}


			}



Now CCalendarEntry

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

#ifndef MYCODE_CCALENDARENTRY_H_
#define MYCODE_CCALENDARENTRY_H_

#include <string>
#include "CJulianDate.h"
#include<iostream>
using namespace std;

class CCalendarEntry {
private:
	CJulianDate m_date;
	std::string m_location;
	std::string m_description;

public:


	/**
	 * Setzt die Werte der Attribute f�r den Termin.
	 *
	 * Da der gregorianische Kalender erst am 15.10.1582 in Kraft trat, erfolgt
	 * eine Plausibilit�tspr�fung (Zusicherung). Liegt das �bergebene Datum vor
	 * dem 15.10.1582 werden die Daten nicht �bernommen (die Attribute bleiben
	 * unver�ndert) und es wird "false" zur�ckgegeben.
	 *
	 * - date: das Datum
	 * - location: der Ort
	 * - description: die Beschreibung
	 *
	 * R�ckgabewert: true, wenn die Daten �bernommen wurden.
	 */
	bool set(const CJulianDate& date, const std::string& location,
			const std::string& description);

	/**
	 * Liefert das Datum, zu dem der Termin stattfindet.
	 */
	const CJulianDate& getDate() const;

	/**
	 * Liefert den Ort, an dem der Termin stattfindet.
	 */
	const std::string& getLocation() const;

	/**
	 * Liefert die Beschreibung des Termins.
	 */
	const std::string& getDescription() const;

	/**
	 * Gibt den Termin wie folgt auf der Konsole aus:
	 *
	 * Zeit: <Attribut m_date im gregorianischen Format>
	 * Ort: <Attribut m_location>
	 * Beschreibung: <Attribut m_description>
	 */
	void print() const;
};

#endif /* MYCODE_CCALENDARENTRY_H_ */




My set Method:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

#include "CCalendarEntry.h"

bool CCalendarEntry::set(const CJulianDate& date, const std::string& location,
			const std::string& description){
	if(this.getJulianDate() > date){

		return false;
	}

	if(this.getJulianDate() <= date){
		m_date = date;
		m_location = location;
		m_description = description;
        return true;
	}



}

const CJulianDate& CCalendarEntry::getDate()const{

	return m_date;
}



Is my Idea right with the if Method ? It shows error?
screenshot of error:
https://www.pic-upload.de/view-35571757/Bildschirmfoto2018-07-03um11.34.34.png.html

The print Methode should print out this:
https://www.pic-upload.de/view-35571760/Bildschirmfoto2018-07-03um11.35.53.png.html

I used getJulianDate in the if Statement because it has the gregorian date or should I use another methode?
The task was too long thats why two posting:
/ **
* Sets the values ​​of the attributes for the appointment.
*
* Since the Gregorian calendar only came into force on 15.10.1552, it takes place
* a plausibility check (assurance). Is the given date before
* the 15.10.1582 the data are not taken over (the attributes remain
* unchanged) and it returns "false".
*
* - date: the date
* - location: the place
* - description: the description
*
* Return value: true if the data was accepted.
* /
bool set (const CJulianDate & date, const std :: string & location,
const std :: string & description);
"this.getJulianDate()" can't work because:
"this" is a pointer, so you'd need "this->", not "this." Also, using "this" in is uncalled for here, you could just call the function directly.
CCalendarEntry has no member "getJulianDate", so none of the above would have worked anyway.
I think you probably wanted:
1
2
3
4
5
6
7
8
9
bool CCalendarEntry::set(const CJulianDate& date, const std::string& location, const std::string& description)
{
	if (date < m_date)
	{
		return false;
	}

...
}


notice I used "<" you haven't defined operator> for CJulianDate also, you'll need operator<=

your CJulianDate::operator- looks like you're trying to do operator-=, in any case you need to return a value.
https://www.pic-upload.de/view-35571760/Bildschirmfoto2018-07-03um11.35.53.png.html

Is my code now right?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "CCalendarEntry.h"

bool CCalendarEntry::set(const CJulianDate& date, const std::string& location,
			const std::string& description){





	if(date < m_date){

		return false;
	}






	if( m_date < date){
		m_date = date;
		m_location = location;
		m_description = description;
        return true;
	}



}

const CJulianDate& CCalendarEntry::getDate()const{

	return m_date;
}



	const string& CCalendarEntry::getLocation()const{

		return m_location;
	}


	const string& CCalendarEntry::getDescription()const{

		return m_description;
	}

	void CCalendarEntry::print() const{

		cout << "Zeit:" << this->dayOfWeekAsName()<<"," << m_date << endl;

		cout << "Ort:" << m_location << endl;
		cout << "Beschreibung:" << m_description << endl;

	}



But now I have errors with my print method here this->dayOfWeekAsName()?

I also need the name of the day like in the link shown at the end .
Can you help?
https://www.pic-upload.de/view-35572962/Bildschirmfoto2018-07-03um17.09.27.png.html
This should be obvious. dayOfWeekAsName() is a member of CJulianDate , not CCalendarEntry.

You know, it would be helpful if you could tell us the error messages here, rather than making us go through links to websites that pop up dialogs that most of us won't even understand.
yeah sorry . I have solved now the problem already and have a problem with testing:
Test the CCalendarEntry class by typing in main.cpp
Create an object gitExam of type CCalendarEntry,
• set the values ​​of the object to "14.02.1017" (time), "D17 / XX" (location) and "GIT-Exam" (set description) and check that you get false as the return value,
• set the values ​​of the object to "14.02.2017" (time), "D17 / XX" (location) and "GIT-Exam" (set description) and check that you get true as the return value,
• print the object with print.

main :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
////////////////////////////////////////////////////////////////////////////////
// Header-Dateien
#include <iostream>		// Header f�r die Standard-IO-Objekte (z.B. cout, cin)
#include <stdlib.h>
// F�gen Sie hier weitere ben�tigte Header-Dateien der
// Standard-Bibliothek ein z.B.
// #include <string>
#include "CJulianDate.h"
#include"CCalendarEntry.h"
using namespace std;	// Erspart den scope vor Objekte der
						// C++-Standard-Bibliothek zu schreiben
						// z.B. statt "std::cout" kann man "cout" schreiben

// Inkludieren Sie hier die Header-Files Ihrer Klassen, z.B.
// #include "CFraction.h"


// Hauptprogramm
// Dient als Testrahmen, von hier aus werden die Klassen aufgerufen
int main (void)
{
    // TODO: Tragen Sie hier Ihren Namen, die Matrikelnummer und die Rechnernummer ein
	cout << "Name: ..., Matrikelnummer: ..., Rechnernummer: ..." << endl << endl;


  CJulianDate semesterBeginn(2016, 10, 1);
 CJulianDate semesterEnd(31,3,2017);

 //cout << semesterBeginn.getJulianDate() << endl;

 cout << semesterBeginn;


cout << endl;


	//semesterBeginn.prettyprintmonth();

CCalendarEntry gitExam;


gitExam.set("14.02.2017","D17/XX","GIT Klausur");

gitExam.print();



	return 0;
}


Description Resource Path Location Type
make: *** [main.o] Error 1 julian C/C++ Problem
Invalid arguments '
Candidates are:
bool set(const CJulianDate &, const std::__1::basic_string<char,std::__1::char_traits<char>,std::__1::allocator<char>> &, const std::__1::basic_string<char,std::__1::char_traits<char>,std::__1::allocator<char>> &)
' main.cpp /julian line 45 Semantic Error
reference to type 'const CJulianDate' could not bind to an lvalue of type 'const char [11]' main.cpp /julian line 45 C/C++ Problem
No return, in function returning non-void CCalendarEntry.cpp /julian line 10 Code Analysis Problem
passing argument to parameter 'date' here CCalendarEntry.h /julian line 39 C/C++ Problem


Where ist the problem?
Look at that error message:

reference to type 'const CJulianDate' could not bind to an lvalue of type 'const char [11]' main.cpp /julian line 45


Look at the code at that line.

Do those arguments to the constructor look right to you?
Do those arguments to the constructor look right to you?
no

I wanted to test the bool Method of CCalendarEntry and the main mostly tests the constructor automatically.

It is testing the constructor of CJulianDate right ?
CCalendarEntry gitExam;



cout << gitExam.set("14.02.2017","D17/XX","GIT Klausur") << gitExam.print() << endl;


This also not works hmmmm.

Or I am thinking wrong?
cout << gitExam.set("14.02.2017","D17/XX","GIT Klausur") << gitExam.print() << endl;

At risk of repeating myself:

Do those arguments to CCalendarEntry::set() look right to you?
OMG I am getting crazy
cout << gitExam.set(2017.02.14,"D17/XX","GIT Klausur") << gitExam.print() << endl;

The First Parameter is not a string thats why I erased ""
But still not working ?hmmmm
The First Parameter is not a string thats why I erased ""

And now that you've erased the quotes, what is it? What do you think C++ sees it as?

still not working

What does this mean? If you actually bothered to look at the error messages you're getting, you might start figuring out how to fix this stuff yourself.
Last edited on
I am trying but not figuring out
And also, not answering the questions we're asking you.
Description Resource Path Location Type
make: *** [main.o] Error 1 julian C/C++ Problem
Function '.14' could not be resolved main.cpp /julian line 47 Semantic Error
Invalid arguments '
Candidates are:
bool set(const CJulianDate &, const std::__1::basic_string<char,std::__1::char_traits<char>,std::__1::allocator<char>> &, const std::__1::basic_string<char,std::__1::char_traits<char>,std::__1::allocator<char>> &)
' main.cpp /julian line 47 Semantic Error
Invalid overload of 'endl' main.cpp /julian line 47 Semantic Error
invalid suffix '.14' on floating constant main.cpp /julian line 47 C/C++ Problem
No return, in function returning non-void CCalendarEntry.cpp /julian line 10 Code Analysis Problem

I really dont know how to fix this problem
Still not answering the questions we're asking you.

And since you're not interested in actually reading what we post, there seems little point me posting anything else.
I have corrected the problem in line 49

But still not working

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

// Header-Dateien
#include <iostream>		// Header f�r die Standard-IO-Objekte (z.B. cout, cin)
#include <stdlib.h>
// F�gen Sie hier weitere ben�tigte Header-Dateien der
// Standard-Bibliothek ein z.B.
// #include <string>
#include "CJulianDate.h"
#include"CCalendarEntry.h"
using namespace std;	// Erspart den scope vor Objekte der
						// C++-Standard-Bibliothek zu schreiben
						// z.B. statt "std::cout" kann man "cout" schreiben

// Inkludieren Sie hier die Header-Files Ihrer Klassen, z.B.
// #include "CFraction.h"


// Hauptprogramm
// Dient als Testrahmen, von hier aus werden die Klassen aufgerufen
int main (void)
{
    // TODO: Tragen Sie hier Ihren Namen, die Matrikelnummer und die Rechnernummer ein
	cout << "Name: ..., Matrikelnummer: ..., Rechnernummer: ..." << endl << endl;


  CJulianDate semesterBeginn(2016, 10, 1);
 CJulianDate semesterEnd(31,3,2017);

 //cout << semesterBeginn.getJulianDate() << endl;

 cout << semesterBeginn;


cout << endl;


	semesterBeginn.prettyprintmonth();








	CCalendarEntry gitExam.set(2017.02.14,"D17/XX","GIT Klausur");

     gitExam.print();





	return 0;
}



https://www.pic-upload.de/view-35573812/Bildschirmfoto2018-07-03um20.02.12.png.html
Last edited on
The first parameter is not a string, it's a "const CJulianDate&". As far as your program goes, 2017.02.14 isn't any kind of object.

You probably meant something like
 
cout << gitExam.set(CJulianDate(2017, 2,14),"D17/XX","GIT Klausur") << gitExam.print() << endl;

Probably.
Probably haha . No I wouldnt have come to this conclusion alone.
In school they didnt really teached us that.

But its still not working?
https://www.pic-upload.de/view-35574067/Bildschirmfoto2018-07-03um20.43.47.png.html
Now I have it almost , but the console is not perfect like in the task wanted .

It shows Semesterbegin:: and two times Dienstag?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>		// Header f�r die Standard-IO-Objekte (z.B. cout, cin)
#include <stdlib.h>
// F�gen Sie hier weitere ben�tigte Header-Dateien der
// Standard-Bibliothek ein z.B.
// #include <string>
#include "CJulianDate.h"
#include"CCalendarEntry.h"
using namespace std;	// Erspart den scope vor Objekte der
						// C++-Standard-Bibliothek zu schreiben
						// z.B. statt "std::cout" kann man "cout" schreiben

// Inkludieren Sie hier die Header-Files Ihrer Klassen, z.B.
// #include "CFraction.h"


// Hauptprogramm
// Dient als Testrahmen, von hier aus werden die Klassen aufgerufen
int main (void)
{
    // TODO: Tragen Sie hier Ihren Namen, die Matrikelnummer und die Rechnernummer ein
	cout << "Name: ..., Matrikelnummer: ..., Rechnernummer: ..." << endl << endl;


//  CJulianDate semesterBeginn(2016, 10, 1);
// CJulianDate semesterEnd(31,3,2017);

 //cout << semesterBeginn.getJulianDate() << endl;

 //cout << semesterBeginn;


//cout << endl;


	//semesterBeginn.prettyprintmonth();


CCalendarEntry gitExam;
gitExam.set(CJulianDate(2017, 2,14),"D17/XX","GIT Klausur");

gitExam.print();





	return 0;
}




Why?

1
2
3
4
5
6
7
8
9
10


	void CCalendarEntry::print() const{

		cout << "Zeit:" << getDate().dayOfWeekAsName()<<"," << m_date << endl;

		cout << "Ort:" << m_location << endl;
		cout << "Beschreibung:" << m_description << endl;

	}


https://www.pic-upload.de/view-35574810/Bildschirmfoto2018-07-03um22.43.37.png.html


It should look so:
https://www.pic-upload.de/view-35574812/Bildschirmfoto2018-07-03um22.38.41.png.html
Pages: 12