Guest User

Untitled

a guest
Jan 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. #define INPUT_FILE "input_setA.txt"
  7.  
  8. /* The maximum name length and number of people and movies */
  9. #define MAX_NAME_LENGTH 200
  10. #define MAX_PEOPLE 700
  11. #define MAX_MOVIES 200
  12.  
  13. void Algorithm1(char Name[MAX_NAME_LENGTH]);
  14. void Data(void);
  15. /* The only global variables permitted in this project are below */
  16. char movies[MAX_MOVIES][MAX_NAME_LENGTH] = {0};
  17. char people[MAX_PEOPLE][MAX_NAME_LENGTH] = {0};
  18. int ratings[MAX_PEOPLE][MAX_MOVIES] = {0};
  19. int numberOfMovies = 0;
  20. int numberOfPeople = 0;
  21.  
  22. int main(void)
  23. {
  24. char Name[MAX_NAME_LENGTH];
  25. int j,MaxAverage,count,sum,average,maxIndex;
  26. Data();
  27.  
  28. printf("Algorithm 1\n");
  29. printf("Calculate recommendautions for:");
  30. scanf("%s",Name);
  31. Algorithm1(Name);
  32. printf("Recommended movie: %s\n",movies[j]);
  33.  
  34. printf("Average rating: %d\n",MaxAverage);
  35.  
  36.  
  37.  
  38.  
  39. return 0;
  40. }
  41.  
  42. /*int getpersonID(char *person) {
  43. int i;
  44. for (i=0;i<numberOfPeople;i++){
  45. if(strcmp(people[numberOfPeople],person)==0){
  46. return i;
  47.  
  48. }
  49. }
  50. }
  51.  
  52. int getmovieName(char *movie_name){
  53. int j;
  54. for(j=0;j<numberOfMovies;j++){
  55. if(strcmp(movies[numberOfMovies],movie_name)==0){
  56. return j;
  57. }
  58. }
  59. }*/
  60.  
  61. void Data(void)
  62. {
  63. char person[MAX_NAME_LENGTH];
  64. char movie_name[MAX_NAME_LENGTH];
  65. int rating;
  66. FILE*fp;
  67.  
  68. int GETPERSON(char *person);
  69. int count=0,i=0,repeat,j=0;
  70.  
  71. fp=fopen(INPUT_FILE,"r");
  72.  
  73. if(fp==0){
  74. printf("Can not find the file\n");
  75. exit(EXIT_FAILURE);
  76. }
  77. while (fscanf(fp,"%s %s %d",person,movie_name,&rating)!=EOF){
  78. repeat=0;
  79.  
  80. for (i=0;i<numberOfPeople;i++){
  81. if(strcmp(person,people[i])==0){
  82. repeat=1;
  83. break;
  84. }
  85. }
  86. if(repeat!=1){
  87. strcpy(people[numberOfPeople],person);
  88. numberOfPeople++;
  89. }
  90. repeat=0;
  91. for (j=0;j<numberOfMovies;j++){
  92. if(strcmp(movie_name,movies[j])==0){
  93. repeat=1;
  94. break;
  95. }
  96. }
  97. if(repeat!=1){
  98. strcpy(movies[numberOfMovies],movie_name);
  99. numberOfMovies++;
  100. }
  101. ratings[i][j]=rating;
  102. }
  103. }
  104.  
  105. void Algorithm1(char Name[MAX_NAME_LENGTH])
  106. {
  107. int i,j,count,sum,average,MaxAverage,maxIndex;
  108.  
  109. for(i=0;i<numberOfPeople;i++){
  110. for(j=0;j<numberOfMovies;j++){
  111. if (ratings[i][j]!=0){
  112. sum+=ratings[i][j];
  113. count++;
  114. }
  115. }
  116.  
  117. average=sum/count;}
  118.  
  119. for(j=0;j<count;j++){
  120. if(MaxAverage<average){
  121. MaxAverage=average;
  122. }
  123. maxIndex=j;
  124. }
  125.  
  126. }
Add Comment
Please, Sign In to add comment