知道作业要自己作,可是要交了还没作出来,希望得到你们的帮助,泄泄 (VC++) 上次问过一次,一些老凶建议用类,可是,可是,我们还没学类,汗
不要很复杂的东西,我们刚开始学,就是读些数进去,找最大的出来,好像自己定义个什么maxmium() 
The Get-Rich-Quick Weight Loss Center awards a prize annually to the client who has lost the most weight. The record of each client contains the following information: name 
"before" weight in pounds 
"after" weight in pounds 
You are to write a program that finds the client who has lost the most weight this past year, and who will therefore be awarded the prize. Also find the client who has lost the least weight (for the "Booby" prize). You may assume that nobody has actually gained weight, and that there are no ties. Read client data without assuming a fixed number of clients (use a sentinel value to end the input data). Data should contain at least 8 clients. 
THE FOLLOWING INSTRUCTIONS MAY BE HELPFUL IF YOU ARE HAVING TROUBLE WITH THIS ASSIGNMENT. Do your assignment in the following stages: A. HW A - Write a program that will read client data; compute the weight loss for each client; and output the maximum weight lost. B. HW B - Modify program A. In addition to displaying the maximum weight loss over all clients, also output the name of the client who lost the most weight and print a message of congratulations to the winner. Use the class library. C. HW C - Modify program B. Also display the name of the client who lost the least weight, and print an appropriate comforting message.

解决方案 »

  1.   

    int max[100];
    int temp;
    temp=max[0];
    for (int i=0;i<100;i++)
    {   
       if(max[i]>temp)
       temp=max[i];
    }
    cout<<temp;
    大概如此
       
      

  2.   

    假如不用类,可以这样设计:客户记录
    struct ClientRec {
      char Name[20];
      int  oldWeight;  //以前重
      int  curWeight;  //现重
    }采用标准输入逐个读取客户记录,置于 客户记录 数组中,然后比较(curWeight-oldWeight)的大小,进行输出操作。补充说明:
    1。为了节约存贮空间,可把char Name[20]改为字符指针;缺点是需要进行动态分配,初学往往觉得较难;
    2。“客户记录数组”编程比较简洁,适合初学者使用,但固定分配一个非常大的数组消耗内存太大;用指针链表对初学者来讲编程稍难,只好权衡一下了。
      

  3.   

    #include<stdio.h>
    #include<malloc.h>
    typedef struct Client{
    char Name[20];
    int  oldWeight;
    int  newWeight;
    int  lossWeight;
    Client* next;
    }CLIENT;
    typedef struct ClientList{
    CLIENT *maxLosser;
    CLIENT *minLosser;
    CLIENT *List;
    CLIENT *Last;
    }CLIENTLIST;
    CLIENTLIST MyClientList;
     
    void InsertNode(CLIENT* newClient);
    void viewClient(CLIENT* currentClient);
    void main()
    {
    int Status=0;
    CLIENT *newClient;
    MyClientList.Last=NULL;
    MyClientList.List=NULL;
    MyClientList.maxLosser=NULL;
    MyClientList.minLosser=NULL;

    printf("please select your action!\n");
    printf("*1. add\n");
    printf("*0. end\n");
    scanf("%d",&Status);
    while(Status)
    {
    newClient = (CLIENT*)malloc(sizeof(CLIENT));
    printf("please input client name!\n");
    scanf("%s",newClient->Name);
    printf("please input client oldWeight!\n");
    scanf("%d",&newClient->oldWeight);
    printf("please input client newWeight!\n");
    scanf("%d",&newClient->newWeight);
    newClient->lossWeight = newClient->oldWeight - newClient->newWeight;
    newClient->next = NULL;
    InsertNode(newClient);
    printf("please select your action!\n");
    printf("*1. add\n");
    printf("*0. end\n");
    scanf("%d",&Status);
    }
    printf("MaxlosserInformation:\n");
    viewClient(MyClientList.maxLosser);
    printf("MinlosserInformation:\n");
    viewClient(MyClientList.minLosser);
    }
      
    void InsertNode(CLIENT* newClient)
    {
    CLIENTLIST *List=&MyClientList;
    if((List->maxLosser==NULL)||(List->maxLosser->lossWeight<newClient->lossWeight))
    List->maxLosser = newClient;
    if((List->minLosser==NULL)||(List->minLosser->lossWeight>newClient->lossWeight))
    List->minLosser = newClient;
    if(List->List==NULL) List->List = newClient;
    if(List->Last==NULL) List->Last = newClient;
    else 
    {
    List->Last->next = newClient;
    List->Last = newClient;
    }
    }
    void viewClient(CLIENT* currentClient)
    {
    printf("ClientName:\t\t%s\n",currentClient->Name);
    printf("ClientlossWeight:\t%d\n",currentClient->lossWeight);
    }