Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
done_4007_cem/module_database.h
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
102 lines (99 sloc)
5.39 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//couple of libraries to make the code working in harmony | |
#include <iostream> | |
#include <string> | |
#include <fstream> | |
#include <deque> | |
#include <cstdlib> | |
using namespace std; | |
#include <unistd.h> | |
// | |
int number_of_the_students;// a place for sum of the students | |
struct Module_timetable //we will use struct insterd to class becasues we can seve different types of values in same possion | |
{ | |
/* data */ | |
string Student_name;// name of student | |
string Student_surname;// surname of the student | |
int Student_ID; // Studnet ID | |
string Student_class;// which part of the modole is the student | |
string Student_lecture; // who is teaching the student | |
string student_room;// name the room | |
string Speace;// just make looking better and clear with a speace | |
}; | |
int Data_Of_Timetable() | |
{ | |
Module_timetable module;//to get and safe name of module | |
cout << "May we know the of the module, please?"<< endl; | |
cin >> module.Student_name;//just to save at the fist possion mame of the module and to get from the user | |
cout <<"May we know the number of the students,plase ? "<< endl; | |
cin >> number_of_the_students;// saving the number of the students | |
Module_timetable Students_period[number_of_the_students]; | |
for (int i = 1; i <= number_of_the_students; i++) // asking students details | |
{ | |
cout <<"May we have the name of the student number "<< i << endl; | |
cin >> Students_period[i].Student_name; | |
cout << "May we have the surname of the student number "<< i << endl; | |
cin >> Students_period[i].Student_surname; | |
cout << "May we have the student ID of the student number "<< i << endl; | |
cin >> Students_period[i].Student_ID; | |
cout << "May we know the class of the student number "<< i <<" for example COMPSCI-C is meaning computer science part c "<< endl; | |
cin >> Students_period[i].Student_class; | |
cout <<"May we know who is the lecture teacher for student numeber "<< i<< endl; | |
cin >> Students_period[i].Student_lecture; | |
cout << "may we know in which room is the students number " << i << endl; | |
cin >> Students_period[i].student_room; | |
Students_period[i].Speace; | |
}; | |
cout << "students of the module "<< module.Student_name<< endl; | |
cout << endl;//to make a bit of space | |
for (int n = 1; n <= number_of_the_students; n++) | |
{ | |
// printing in terminal the details | |
cout << "Student name: " << Students_period[n].Student_name << endl; | |
cout << "Student surname:"<<Students_period[n].Student_surname << endl; | |
cout << "Student ID :" <<Students_period[n].Student_ID << endl; | |
cout << "Student class: " << Students_period[n].Student_class << endl; | |
cout << "Student lecture: "<< Students_period[n].Student_lecture<< endl; | |
cout << "Student room: "<<Students_period[n].student_room<< endl; | |
cout << Students_period[n].Speace << endl;// space to make next studne clear | |
} | |
//************************************************************************************************************************************************************/ | |
//below code is for txt file | |
deque<Module_timetable> data_deque; | |
string file_path(module.Student_name +".txt");//make file with the name of the module | |
ofstream send_text_file(file_path, ofstream::app);// commant to sent deatails on txt file | |
for (int b = 1; b <= number_of_the_students;b++ )// usinig for to puss all details togher in the text file | |
{ | |
//senting details at the txt file | |
data_deque.push_back(Module_timetable{Students_period[b].Student_name, | |
Students_period[b].Student_surname, | |
Students_period[b].Student_ID, | |
Students_period[b].Student_class, | |
Students_period[b].Student_lecture, | |
Students_period[b].student_room, | |
Students_period[b].Speace});//details | |
} | |
if (send_text_file) | |
{ | |
for (const Module_timetable & d : data_deque) | |
{ | |
for (int a = 1; a <= number_of_the_students; a++ ) // using this for to sent details in text file | |
{ | |
//printing the details in txt file | |
send_text_file << "Module title: "<< module.Student_surname <<endl; | |
send_text_file << "Details of students"<< endl; | |
send_text_file << "Student name: "<<Students_period[a].Student_name << endl; | |
send_text_file <<"Student surname: "<<Students_period[a].Student_surname<< endl; | |
send_text_file <<"Student ID: "<< Students_period[a].Student_ID << endl; | |
send_text_file <<"Student class: "<< Students_period[a].Student_class << endl; | |
send_text_file <<"Student lecture: "<<Students_period[a].Student_lecture << endl; | |
send_text_file <<"Student room:"<<Students_period[a].student_room << endl; | |
send_text_file <<Students_period[a].Speace << endl; // space to make next studne clear | |
} | |
} | |
send_text_file.close();// close the file | |
} | |
else | |
cout << " Clould not open file:"<< file_path << endl; // error if will happend samothing on file | |
return 0; | |
}; | |
//reference https://stackoverflow.com/questions/50847099/writing-structure-to-a-text-file-in-c |