mirror of https://github.com/PatrickLipka/tt.git
				
				
				
			ProjectList class and test added
This commit is contained in:
		
							parent
							
								
									a2ba8123f4
								
							
						
					
					
						commit
						1f5778e190
					
				|  | @ -19,3 +19,15 @@ void Project::remove_task(int id){ | ||||||
|     Project::active_task = std::max(id-1,0); |     Project::active_task = std::max(id-1,0); | ||||||
|     Project::num_tasks--; |     Project::num_tasks--; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | void ProjectList::add_project(Project proj){ | ||||||
|  |     ProjectList::projects.push_back(proj); | ||||||
|  |     ProjectList::active_project = ProjectList::num_projects; | ||||||
|  |     ProjectList::num_projects++; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void ProjectList::remove_project(int id){ | ||||||
|  |     ProjectList::projects.erase(projects.begin()+id); | ||||||
|  |     ProjectList::active_project = std::max(id-1,0); | ||||||
|  |     ProjectList::num_projects--; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -16,5 +16,13 @@ class Project{ | ||||||
|         int active_task; |         int active_task; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | class ProjectList{ | ||||||
|  |     public: | ||||||
|  |         int num_projects; | ||||||
|  |         std::vector<Project> projects; | ||||||
|  |         void add_project(Project proj); | ||||||
|  |         void remove_project(int id); | ||||||
|  |         int active_project; | ||||||
|  | }; | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | @ -1,4 +1,5 @@ | ||||||
| #include <iostream> | #include <iostream> | ||||||
|  | #include <vector> | ||||||
| #include "task.h" | #include "task.h" | ||||||
| #include "project.h" | #include "project.h" | ||||||
| 
 | 
 | ||||||
|  | @ -15,5 +16,12 @@ int main(){ | ||||||
|     std::cout << "Removing Task 0 from Project" << std::endl; |     std::cout << "Removing Task 0 from Project" << std::endl; | ||||||
|     proj.remove_task(0); |     proj.remove_task(0); | ||||||
|     std::cout << "Number of tasks in project: " << proj.num_tasks << std::endl; |     std::cout << "Number of tasks in project: " << proj.num_tasks << std::endl; | ||||||
|  |      | ||||||
|  |     ProjectList proj_list; | ||||||
|  |     proj_list.add_project(proj); | ||||||
|  |     std::cout << "Project List no of projects: " << proj_list.num_projects << " Name of active proj: " << proj_list.projects[proj_list.active_project].name << std::endl; | ||||||
|  |      | ||||||
|  |     proj_list.remove_project(0); | ||||||
|  |     std::cout << "Project List no of projects: " << proj_list.num_projects << std::endl; | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue