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_setA.txt"
- /* The maximum name length and number of people and movies */
- #define MAX_NAME_LENGTH 200
- #define MAX_PEOPLE 700
- #define MAX_MOVIES 200
- void Algorithm1(char Name[MAX_NAME_LENGTH]);
- void Data(void);
- /* 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;
- int main(void)
- {
- char Name[MAX_NAME_LENGTH];
- int j,MaxAverage,count,sum,average,maxIndex;
- Data();
- printf("Algorithm 1\n");
- printf("Calculate recommendautions for:");
- scanf("%s",Name);
- Algorithm1(Name);
- printf("Recommended movie: %s\n",movies[j]);
- printf("Average rating: %d\n",MaxAverage);
- return 0;
- }
- /*int getpersonID(char *person) {
- int i;
- for (i=0;i<numberOfPeople;i++){
- if(strcmp(people[numberOfPeople],person)==0){
- return i;
- }
- }
- }
- int getmovieName(char *movie_name){
- int j;
- for(j=0;j<numberOfMovies;j++){
- if(strcmp(movies[numberOfMovies],movie_name)==0){
- return j;
- }
- }
- }*/
- 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,count,sum,average,MaxAverage,maxIndex;
- for(i=0;i<numberOfPeople;i++){
- for(j=0;j<numberOfMovies;j++){
- if (ratings[i][j]!=0){
- sum+=ratings[i][j];
- count++;
- }
- }
- average=sum/count;}
- for(j=0;j<count;j++){
- if(MaxAverage<average){
- MaxAverage=average;
- }
- maxIndex=j;
- }
- }
Add Comment
Please, Sign In to add comment