gpt4 book ai didi

c - 如何在C中复制结构的唯一成员

转载 作者:行者123 更新时间:2023-11-30 17:01:49 25 4
gpt4 key购买 nike

我正在做编程作业(C语言),我遇到了一个问题,尽管我很努力也无法解决。

在询问具体问题之前,我想向您展示给出的内容:

In the first plain text file (F1) are stored movies titles with all the data. In the second plain text file (F2) – review of movies,listed in file F1, by ordinary users and movie critics. Each film canbe evaluated by an unlimited number of movie critics and ordinaryusers. One and the same person may be a director in several movies.Also, every critic/user can participate in the evaluation of severalmovies.

· Display on the screen all the critics (movie critics and ordinaryusers), the number of movies they have rated and an average mark. Sortthe critics by the number of marks (from greatest to lowest).

所以我的评论结构如下所示:

struct Review{
char ID[20];
char MovieID[20];
char FamilyName[20];
char Critic;
double Mark;


};

我创建了具有动态内存分配的结构数组。我需要的是通过 FamilyName 识别评论的每个独特作者,计算他们评分的电影数量(因此他们的 FamilyName 在评论中出现的次数)以及他们对所有电影的平均评分。

到目前为止,我正在考虑创建新的 User 结构,其中包含所有 3 名成员的姓氏、评分的电影数量、AverageMark。但我想不出只将唯一值从 Review[] 复制到 User[] 的算法...完成后排序就不成问题了。

谢谢

最佳答案

任务主要是关于数据库设计。使用的示例结构布局如下:

struct Movie {
int ID;
char MovieName[20];
int DirectorId; /* lookup in Person */
};

struct Person {
int Id;
char Surname[20];
char Firstname[20];
/* numbers of reviews, movies directed etc, can be calculated, and should not be stored to disk */
int NumberOfReviews;
int SumMarks; /* AverageMark = SumMarks / NumberOfReviews */
};

struct Review {
int Id;
int MovieId;
int AuthorId; /* Lookup in person */
int Mark;
};

接下来,您需要创建一个数组或链表,创建从磁盘加载数据并打印报告的例程。

关于c - 如何在C中复制结构的唯一成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36815425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com