Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #define INPUT_FILE "input.txt"
- /* The maximum name length and number of people and movies */
- #define MAX_NAME_LENGTH 200
- #define MAX_PEOPLE 700
- #define MAX_MOVIES 200
- /* The only global variables permitted in this project are below */
- char movies[MAX_MOVIES][MAX_NAME_LENGTH] = {0};
- char people[MAX_PEOPLE][MAX_NAME_LENGTH] = {0};
- int ratings[MAX_PEOPLE][MAX_MOVIES] = {0};
- int numberOfMovies = 0;
- int numberOfPeople = 0;
- void Data(void);
- void Algorithm1(char Name[MAX_NAME_LENGTH]);
- int main(void) {
- char Name[MAX_NAME_LENGTH];
- printf("Algorithm 1\n");
- printf("Calculate recommendations for:");
- scanf("%s",Name);
- Algorithm1(Name);
- return 0;
- }
- void Data(void)
- {
- char person[MAX_NAME_LENGTH];
- char movie_name[MAX_NAME_LENGTH];
- int rating;
- FILE*fp;
- int GETPERSON(char *person);
- int count=0,i=0,repeat,j=0;
- fp=fopen(INPUT_FILE,"r");
- if(fp==0){
- printf("Can not find the file\n");
- exit(EXIT_FAILURE);
- }
- while (fscanf(fp,"%s %s %d",person,movie_name,&rating)!=EOF){
- repeat=0;
- for (i=0;i<numberOfPeople;i++){
- if(strcmp(person,people[i])==0){
- repeat=1;
- break;
- }
- }
- if(repeat!=1){
- strcpy(people[numberOfPeople],person);
- numberOfPeople++;
- }
- repeat=0;
- for (j=0;j<numberOfMovies;j++){
- if(strcmp(movie_name,movies[j])==0){
- repeat=1;
- break;
- }
- }
- if(repeat!=1){
- strcpy(movies[numberOfMovies],movie_name);
- numberOfMovies++;
- }
- ratings[i][j]=rating;
- }
- }
- void Algorithm1(char Name[MAX_NAME_LENGTH])
- {
- int i,j=0,UPI,maxIndex=0;
- double average, MaxAverage=0,count=0,sum=0;
- UPI=Name[MAX_NAME_LENGTH];
- for(i=0;i<numberOfPeople;i++){
- if(ratings[UPI][j]==0){
- for(j=0;j<numberOfMovies;j++){
- if ((ratings[i][j]!=0)){
- sum+=ratings[i][j];
- count++;
- }
- }
- average=sum/count;
- }
- if(MaxAverage<average){
- MaxAverage=average;
- maxIndex=j;
- }
- }
- printf("Recommended movie: %s\n",movies);
- printf("Average rating:%f\n",MaxAverage);
- }
Add Comment
Please, Sign In to add comment