Aspen Starlight 2022-05-31 09:09 采纳率: 100%
浏览 123
已结题

三个小问题,本人0基础真的不会写,有偿求解答

(使用C/C++语言解答,一个程序每个子功能后都用//备注一下是发挥什么功能,谢谢 ! )

问题1

img

问题2

img

问题3

img

  • 写回答

2条回答 默认 最新

  • qfl_sdu 2022-05-31 17:57
    关注

    1:

    #include <iostream>
    using namespace std;
    //type=0表示摄氏转华式
    double calc(double value, int type = 0)
    {
        double f=0, c=0;
        if (type == 0)
        {
            f = (value * 9 / 5) + 32;
            return f;
        }
        else
        {
            c = (value - 32) * 5 / 9;
            return c;
        }
    }
    
    
    int main()
    {
        double v, t;
        cin >> v;
        printf("  摄氏温度:%.15lf\n",v);
        t = calc(v, 0);
        printf("=>华氏温度:%.15lf\n", t);
        t = calc(t, 1);
        printf("=>摄氏温度:%.15lf\n", t);
        return 0;
    }
    
    

    2:

    #include <iostream>
    using namespace std;
    template<typename T>
    void pow(T value, T& pingfang, T& lifang)
    {
        pingfang = value * value;
        lifang = value * value * value;
    }
    
    
    int main()
    {
        double n;
        double pf, lf;
        cout << "请输入1个输,按回车结束:";
        cin >> n;
        pow(n, pf, lf);
        cout << n << "的平方:" << pf << endl;
        cout << n << "的立方:" << lf << endl;
        return 0;
    }
    
    

    3:(数据直接录入了,输入需要查询的科目和学号即可输出,另外,再差某个科目的最低和最高成绩的时候,只保留了一个学生的信息)

    img

    #define _CRT_SECURE_NO_WARNINGS 1
    #include <iostream>
    #include <string>
    using namespace std;
    //定义最大课程数
    #define MAXKC 4
    class Student
    {
    private:
        string mId;
        string mName;
        string mSex;
    public:
        Student() { mId = ""; mName = ""; mSex = ""; }
        void setId(string id) { mId = id; }
        string getId() { return mId; }
        void setName(string n) { mName = n; }
        string getName() { return mName; }
        void setSex(string s) { mSex = s; }
        string getSex() { return mSex; }
    };
    
    class Grade
    {
    private:
        string mName;
        int mScore;
    public:
        Grade() { mName = ""; mScore = 0; }
        void setName(string n) { mName = n; }
        string getName() { return mName; }
        void setScore(int n) { mScore = n; }
        int getScore() { return mScore; }
    };
    
    
    class StudentGrade
    {
    public:
        Student mStu;
        Grade mGrade[MAXKC];
        
        void show()
        {
            cout << "姓名:" << mStu.getName() << endl;
            cout << "性别:" << mStu.getSex() << endl;
            cout << "学号:" << mStu.getId() << endl;
            for (int j = 0; j < MAXKC; j++)
            {
                if (j < MAXKC - 1)
                    cout << mGrade[j].getName() << " " << mGrade[j].getScore() << " ";
                else
                    cout << mGrade[j].getName() << " " << mGrade[j].getScore() << endl;
            }
        }
        /*
    public:
        StudentGrade() { mNmb = 0; }
        void SetStu(Student s) { mStu = s; }
        Student getStu() { return mStu; }*/
        
    };
    
    
    
    int main()
    {
        StudentGrade arr[5];
        //添加学生信息
        arr[0].mStu.setName("Zhang");
        arr[0].mStu.setSex("男");
        arr[0].mStu.setId("001");
        arr[0].mGrade[0].setName("A");
        arr[0].mGrade[0].setScore(65);
        arr[0].mGrade[1].setName("B");
        arr[0].mGrade[1].setScore(70);
        arr[0].mGrade[2].setName("C");
        arr[0].mGrade[2].setScore(53);
        arr[0].mGrade[3].setName("D");
        arr[0].mGrade[3].setScore(80);
        
    
        arr[1].mStu.setName("Cheng");
        arr[1].mStu.setSex("女");
        arr[1].mStu.setId("002");
        arr[1].mGrade[0].setName("A");
        arr[1].mGrade[0].setScore(75);
        arr[1].mGrade[1].setName("B");
        arr[1].mGrade[1].setScore(75);
        arr[1].mGrade[2].setName("C");
        arr[1].mGrade[2].setScore(85);
        arr[1].mGrade[3].setName("D");
        arr[1].mGrade[3].setScore(78);
    
        arr[2].mStu.setName("Li");
        arr[2].mStu.setSex("女");
        arr[2].mStu.setId("003");
        arr[2].mGrade[0].setName("A");
        arr[2].mGrade[0].setScore(68);
        arr[2].mGrade[1].setName("B");
        arr[2].mGrade[1].setScore(45);
        arr[2].mGrade[2].setName("C");
        arr[2].mGrade[2].setScore(95);
        arr[2].mGrade[3].setName("D");
        arr[2].mGrade[3].setScore(72);
    
        arr[3].mStu.setName("Cha");
        arr[3].mStu.setSex("男");
        arr[3].mStu.setId("004");
        arr[3].mGrade[0].setName("A");
        arr[3].mGrade[0].setScore(67);
        arr[3].mGrade[1].setName("B");
        arr[3].mGrade[1].setScore(70);
        arr[3].mGrade[2].setName("C");
        arr[3].mGrade[2].setScore(64);
        arr[3].mGrade[3].setName("D");
        arr[3].mGrade[3].setScore(62);
    
        arr[4].mStu.setName("Xun");
        arr[4].mStu.setSex("男");
        arr[4].mStu.setId("005");
        arr[4].mGrade[0].setName("A");
        arr[4].mGrade[0].setScore(65);
        arr[4].mGrade[1].setName("B");
        arr[4].mGrade[1].setScore(90);
        arr[4].mGrade[2].setName("C");
        arr[4].mGrade[2].setScore(78);
        arr[4].mGrade[3].setName("D");
        arr[4].mGrade[3].setScore(85);
    
        //输出制定科目最高分和最低分的学生信息
        string skm;
        cout << "请输入科目名称,查询该科目的最高和最低的学生课程成绩信息:";
        cin >> skm;
        int max=0, min=0, maxindex = 0, minindex = 0;
        for (int i = 0; i < 5; i++)
        {
            for (int j = 0; j < MAXKC; j++)
            {
                if (arr[i].mGrade[j].getName().compare(skm) == 0)
                {
                    if (max == 0 || arr[i].mGrade[j].getScore() > max)
                    {
                        max = arr[i].mGrade[j].getScore();
                        maxindex = i;
                    }
                    if (min == 0 || arr[i].mGrade[j].getScore() < min)
                    {
                        min = arr[i].mGrade[j].getScore();
                        minindex = i;
                    }
                }
                
            }
        }
        //输出
        cout << skm << "科目分数最高的:";
        arr[maxindex].show();
    
        cout << skm << "科目分数最低的:";
        arr[minindex].show();
    
        //
        string id;
        cout << "请输入学生学号,以查询该学生科目分数的最高和最低分:";
        cin >> id;
        for (int i = 0; i < 5; i++)
        {
            if (arr[i].mStu.getId().compare(id) == 0)
            {
                max = arr[i].mGrade[0].getScore();
                min = arr[i].mGrade[0].getScore();
                maxindex = 0;
                minindex = 0;
                for (int j = 1; j < MAXKC; j++)
                {
                    if (arr[i].mGrade[j].getScore() > max)
                    {
                        max = arr[i].mGrade[j].getScore();
                        maxindex = j;
                    }
                    if (arr[i].mGrade[j].getScore() < min)
                    {
                        min = arr[i].mGrade[j].getScore();
                        minindex = j;
                    }
                }
                //输出
                //cout << "姓名:" << arr[i].mStu.getName() << endl;
                //cout << "性别:" << arr[i].mStu.getSex() << endl;
                //cout << "学号:" << arr[i].mStu.getId() << endl;
                cout << "最高成绩:" << arr[i].mGrade[maxindex].getName() << " " << arr[i].mGrade[maxindex].getScore() << endl;
                cout << "最低成绩:" << arr[i].mGrade[minindex].getName() << " " << arr[i].mGrade[minindex].getScore() << endl;
                break;
            }
        }
    
        return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 6月8日
  • 已采纳回答 5月31日
  • 创建了问题 5月31日

悬赏问题

  • ¥15 35114 SVAC视频验签的问题
  • ¥15 impedancepy
  • ¥15 在虚拟机环境下完成以下,要求截图!
  • ¥15 求往届大挑得奖作品(ppt…)
  • ¥15 如何在vue.config.js中读取到public文件夹下window.APP_CONFIG.API_BASE_URL的值
  • ¥50 浦育平台scratch图形化编程
  • ¥20 求这个的原理图 只要原理图
  • ¥15 vue2项目中,如何配置环境,可以在打完包之后修改请求的服务器地址
  • ¥20 微信的店铺小程序如何修改背景图
  • ¥15 UE5.1局部变量对蓝图不可见