Movie Ratting system

 avatar
kaziamir
c_cpp
a year ago
1.5 kB
1
Indexable
Never
#include<bits/stdc++.h>
using namespace std;

typedef struct movie{
    int u_id,m_id, rating;
    string review;
    struct movie *next;
}movie;

movie *top=NULL;

void add(int u, int m, int r, string R){
//void add(int u, int m, int r){
    movie *newNode=(movie *)malloc(sizeof(movie));

    if(newNode==NULL){
        cout<<"Can't Perform!"<<endl;
        return;
    }
    newNode->u_id = u;
    newNode->m_id = m;
    newNode->rating = r;
    newNode->review.assign(R);

    newNode->next = top;
    top = newNode;

}

void dlt(int u, int m){
    movie *temp;
    movie *p=top;
    while(p->u_id!=u && p->m_id!=m){
        p = p->next;
    }
    temp = p->next;
    p->next = p->next->next;
    free(temp);
}

void get(int u, int m){
    movie *p=top;
    while(p->u_id!=u && p->m_id!=m){
        p=p->next;
    }
    //cout<<p->rating<<", "<<p->review<<endl;
    cout<<"Rating for "<<m<<" is: "<<p->rating<<","<<p->review<<endl;
}

void top_k_movies(int k){

}

void display(){
    movie *p=top;
    while(p!=NULL){
        cout<<p->u_id<<", "<<p->m_id<<", "<<p->rating<<", "<<p->review<<endl;
        //cout<<p->u_id<<", "<<p->m_id<<", "<<p->rating<<endl;
        p=p->next;
    }
}
void solution(){
    int n;
    cin>>n;
    int u, m, r;
    string R;
    while(n--){
        cin>>u>>m>>r;
        //cin>>R;
        getline(cin,R);
        add(u, m, r, R);
    }
    display();
    get(1, 101);
    dlt(1, 101);
    display();

}

int main(){
    solution();
    return 0;
}