Making a schedule using classes

Hello,

I'm having a bit of trouble with my code, I'm trying to make a 7 day/ 24 hour scheduler. My plan to do do this is to first make a 2d array that is blank. then using the bool add_entry function, place the strings for the course name and location into the array.
My code is a little messy because I'v been trying different things to make it work.
My problem is that I don't know how to make a 7x24 2d array and have it display blank first. Do I define it in the default constructor?
This is what I have right now:

Schedule.cpp
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 <iostream>
#include "Schedule.h"
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip.h>


Schedule::Schedule() {
	// TODO Auto-generated constructor stub
	std::string array[7][24] = {"empty"};
//Place empty string on each cell. Lab 1. use "empty ". Not NULL. Then work on print function to see if it prints out empty.
}



bool Schedule::add_entry(int day, int start_hour, int end_hour, std::string entry_name, std::string entry_location) {
	std::string array();
		for (int day = 0, day <= 7, day++) {
			for( int start_hour = 0, start_hour < 24, start_hour++) {
				
			}
		}

	//std::string array [];

	//day[1,3,5];
return 0;
}

//bool add_entry(int day, int start_hour, int end_hour, std::string entry_name, std::string entry_location) {
//day [DAYS];
//start_hour [HOURS];
//end_hour [HOURS];

//}


void print(int start_hour, int end_hour) {
	for (int row = 0; row < start_hour; row++) {
		for (int col = 0; col < end_hour; col++) {
			std::cout << setw(5) << array [7][24]
		}
	}
}

const Schedule operator +(const Schedule& Cs162 , const Schedule& Mth231) {

}
	//Make 4 cases:
	//One: both cells are empty.
	//tw0: 1 has stuff, 2 has nothing.
	//Three: 1 has nothing, 2 has stuff.
	//Four: Both have stuff.
	//Overload the operator.


//member function to call private array and set. 


Schedule.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#ifndef SCHEDULE_H_
#define SCHEDULE_H_
#include <string>


static class Schedule {
public:
	Schedule();
	bool add_entry(int day, int start_hour, int end_hour, std::string entry_name, std::string entry_location);
	void print(int start_hour, int end_hour);
private:
	std::string array[7][24];

};

const Schedule operator +(const Schedule& Cs162 , const Schedule& Mth231);

#endif /* SCHEDULE_H_ */ 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main ()
{
	//Schedule test1;
	//std::cout << test1.array[0] << test1.array[1];
	//std::cin.get();
	//return 0;
	Schedule Cs162, Engr203, Mth231, Ece272;
	Cs162.add_entry(1, 12, 13, Cs162, Kidd 350);
	Cs162.add_entry(3, 12, 13, Cs162, Kidd 350);
	Cs162.add_entry(5, 12, 13, Cs162, Kidd 350);
	Engr203.add_entry(1, 10, 11, Engr203, Kidd 364);
	Engr203.add_entry(3, 10, 11, Engr203, Kidd 364);
	Engr203.add_entry(15, 10, 11, Engr203, Kidd 364);

};
line 19 of Schedule.cpp is probably going to cause an out of range err

Sure. Constructor is fine.
Just create a double loop to iterate through each element like you have on 19-20 (after fixing the bounds)
Last edited on
What do you mean by fixing the bounds?
Line 11 declares an array of 7elements (by 24)
Then Line 19 attempts to access the 8th element (which does not exist)
Topic archived. No new replies allowed.