Consider the class diagram below figure which illustrates the data model for the supervision of student projects

Question

Consider the class diagram below figure which illustrates the data model for the supervision of student projects. Each student can only have a project and is supervised by a lecture.

Screen output with the input file.

Student : sit Aminah
Project : Cost-Effective Green Fuel
Supervisor : Dr. Ali Bakar
Student : Kamaraul Ariffin
Project : IoT- based Flood Monitoring
Supervisor : Dr. Ali Bakar
Student : Abdul Jabar
Project : Energy saving with IoT
Student : Kamariah Jalil
Project : Camera-based Heat Detection
Student : seman Abdullah
Project : Image-based search Engine
Student : Rozita Abdul
project : programmer Friendly Metaprogramming
Supervisior : prof. Dr. Abu samah Abdullah

 

Summary

Here we have to consider a class diagram where in this interlink question we have to write three different classes which are a link to one another. Three files are in the file we will write the input text which we want to print. Second, we write the main program. The third one is where it will get printed. So that the information that we write on one file will get printed on another file.

Explanation

Here in the given program, we have to write three classes so that we can have a program where classes are related to one another. First class is Lecturer with the data members as name with the string return type. The Next class is the class Project. And the third and the last class here is class Student. Now here for every class, we have getters and setters. In addition to that, we also have Accessors and mutators. Next is our main method, in the main method we have added the information from which we will take the input. Also, all the elements are needed to have an assignment with the lecturer. Once this is all done output will get printed on a different file i.e. the output file.

Code

#include <iostream>
using namespace std;
#include <fstream>
#include <iomanip>
/* to implement the lecturer class in the program */
class Lecturer 
{
    private:
    string name;
    public:
    /* default class constructor */
    Lecturer(){
        name="";
    }
    Lecturer(string n){
        name=n;
    }
    /* accessor */
    string getName(){
        return name;
    }
};
/* to implement the project class */
class Project 
{
    private:
    string title;
    Lecturer supervisor;
    public:
    /* default constructor */
    Project(){
        title="";
    }
    /* accessor */
    string getTitle(){
        return title;
    }
    /* accessor */
    Lecturer getSupervisor(){
        return supervisor;
    }
    /* mutator */
    void setTitle(string t){
        title=t;
    }
    /* mutator */
    void setSupervisor(Lecturer l){
        supervisor=l;
    }
};
/* to implement the student class */
class Student 
{
    private:
    string name;
    Project project;
    Lecturer supervisor;
    public:
    /* default constructor of class*/
    Student(){
        name="";
        Lecturer l("");
        supervisor=l;
    }
    /* accessor */
    string getName(){
        return name;
    }
    /* accessor */
    string getProjectName(){
        return project.getTitle();
    }
    /* accessor */
    string getSupervisor(){
        return supervisor.getName();
    }
    /* mutator */
    void setName(string n){
        name=n;
    }
    /* mutator */
    void setProject(Project p){
        project=p;
    }
    /* mutator */
    void assignSupervisor(Lecturer l){
        supervisor=l;
    }
    void print(){
        cout<<"Student: "<<name<<endl;
        cout<<"Project: "<<project.getTitle()<<endl;
        cout<<"Supervisor: "<<supervisor.getName()<<endl;
    }
};
/* main code */
int main()
{
    ifstream in("input.txt");
    Student s[10];
    Project p[10];
    Lecturer l1("Dr. Ali Bakar");
    Lecturer l2("Prof. Dr. Abu Samah Abdullah");
    int cc=0;
    string k1,k2;
    while(getline(in, k1)){
        s[cc].setName(k1);
        getline(in,k2);
        p[cc].setTitle(k2);
        s[cc].setProject(p[cc]);
        getline(in,k2);
        cc++;
    }
    s[0].assignSupervisor(l1);
    s[1].assignSupervisor(l1);
    s[cc-1].assignSupervisor(l2);
    ofstream of("output.txt");
    for(int i=0;i<cc;i++){
        of<<left;
        of<<setw(15)<<"Student: "<<s[i].getName()<<endl;
        of<<setw(15)<<"Project: "<<s[i].getProjectName()<<endl;
        if(s[i].getSupervisor()!=""){
            of<<setw(15)<<"Supervisor: "<<s[i].getSupervisor()<<endl;
        }
        of<<endl;
    }
}

Output

data model for the supervision

input.txt

data model for the supervision

 

Also read,

Hello, code is giving issues need help figuring it out. I posted the code and project prompt

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *