3.5 3.7怎么做用c++语言

img

3.5 3.7初学c++ 怎么做啊 好难啊 帮帮我 不知道怎么办 好难啊 有没有

3.5代码如下

#include <iostream>
using namespace std;

int main()
{
    int today, elapsed;//定义变量类型
    cout << "Please enter an integer representing the day of the week today" << endl;
    cout << "For example,Monday is 1.In particular,Sunday is 0." << endl;
    cout << "Enter today's day : ";//今天周几
    cin >> today;
    cout << "Enter the number of days elapsed since today : ";//距离今天有几天
    cin >> elapsed;

    int day;
    day = (today + elapsed) % 7;//判断未来是周几

    switch (today)//用分支语句判断今天周几
    {
    case 0: cout << "Today is Sunday" << endl;
        break;
    case 1: cout << "Today is Monday" << endl;
        break;
    case 2: cout << "Today is Tuesday" << endl;
        break;
    case 3: cout << "Today is Wednesday" << endl;
        break;
    case 4: cout << "Today is Thursday" << endl;
        break;
    case 5: cout << "Today is Friday" << endl;
        break;
    case 6: cout << "Today is Saturday" << endl;
        break;
    }

    switch (day)//用分支语句判断未来周几
    {
    case 0: cout << "The future day is Sunday" << endl;
        break;
    case 1: cout << "The future day is Monday" << endl;
        break;
    case 2: cout << "The future day is Tuesday" << endl;
        break;
    case 3: cout << "The future day is Wednesday" << endl;
        break;
    case 4: cout << "The future day is Thursday" << endl;
        break;
    case 5: cout << "The future day is Friday" << endl;
        break;
    case 6: cout << "The future day is Saturday" << endl;
        break;
    }

    system("pause");

    return 0;
}

运行结果如下图

img

3.7代码如下

#include<stdio.h>
void swap(int* pt1, int* pt2)  //交换指针指向值
{
    int temp;
    temp = *pt1;
    *pt1 = *pt2;
    *pt2 = temp;
}
void exchange(int* p1, int* p2, int* p3)
{
    if (*p1 > *p2)         //如果p1指针指向的数大于p2,则交换指针指向值
        swap(p1, p2);
    if (*p1 > *p3)          //同上
        swap(p1, p3);
    if (*p2 > *p3)         //同上
        swap(p2, p3);

}

int main()
{
    int a, b, c;                  //定义三个变量
    int* p1, * p2, * p3;       //定义三个指针
    printf("请输入3个整数,整数之间用空格隔开: \n");
    scanf("%d %d %d", &a, &b, &c);    //输入三个数值
    p1 = &a, p2 = &b, p3 = &c;        //把a,b,c三个数的地址赋值给对应指针
    exchange(p1, p2, p3);         //调用函数
    printf("%d,%d,%d\n", a, b, c); //将调换后的值顺序输出
    int wait = 1;
    scanf("%d", &a);
    return 0;
}

运行截图如下图

img

3.5 只需要将指定的天数加上当前星期几,求余7就行了啊
3.7 三个整数比较大小,分别求出最大值和最小值,然后三个数之和减去最大值和最小值就是中间值
稍等写代码
3.7代码:

#include <iostream>
using namespace std;
int minmax(int a,int b,int flag)
{
    if(flag == 1)
    {
        if(a>b)
            return a;
        return b;
    }
    else if(a<b)
        return a;
    return b;
}
int main()
{
   int a,b,c;
   cin>>a>>b>>c;
   int max = minmax(c,minmax(a,b,1),1);
   int min = minmax(c,minmax(a,b,0),0);
   int mid = a+b+c-max-min;
   cout<<min<<" "<<mid<<" "<<max<<endl;
   return 0;
}

3.5 代码

#include <iostream>
using namespace std;
int main()
{
    char week[][20] = {"Sunday",   "Monday", "Tuesday", "Wednesday","Thursday", "Friday", "Saturday"};
     int today, days,fday;
     cout<<"Enter today's day: ";
     cin>>today;
     cout<<"Enter the number of days elapsed since today: ";
     cin>>days;
     fday = (today + days)%7;
     cout<<"Today is "<< week[today] <<" and the future day is "<<week[fday]<<endl;
     return 0;
}

3.5

#include <iostream>

int main() {
  const char *weekdays[] = {"Sunday",   "Monday", "Tuesday", "Wednesday",
                            "Thursday", "Friday", "Saturday"};
  int today, elapsed_days;
  std::cout << "Enter today's day: ";
  std::cin >> today;
  std::cout << "Enter the number of days elapsed since today: ";
  std::cin >> elapsed_days;
  std::cout << "Today is " << weekdays[today] << " and the future day is "
            << weekdays[(today + elapsed_days) % 7] << '\n';
  return 0;
}

3.7

#include <iostream>

int main() {
  int a, b, c;
  std::cout << "Enter three integers: ";
  std::cin >> a >> b >> c;
  if (a > b)
    std::swap(a, b);
  if (a > c)
    std::swap(a, c);
  if (b > c)
    std::swap(b, c);
  std::cout << a << " " << b << " " << c << "\n";
  return 0;
}
//3.5
#include <iostream>
using namespace std;
int sinceToday(int day,int days)
{
    int sum = day + days;
    return sum%7;
}
int main() {
    //1.输入day和days
    //2.使用函数sinceToday(day,days);
    //3.根据返回值判断星期几,建议用switch,0-星期日,1-星期一,2-星期二....
    return 0;
}
//3.7
#include <iostream>
using namespace std;
int main() {
    int a,b,c,tmp;
    printf("请输入3个数字:");
    scanf("%d%d%d",&a,&b,&c);
    if(a<b)//如果a比b小,交换a和b的值,使a存放大的数字
    {
        tmp=a;
        a=b;
        b=tmp;
    }
    if(a<c)//如果a比c小,交换a和c的值,使a存放大的数字
    {
        tmp=a;
        a=c;
        c=tmp;
    }
    if(b<c)//如果b比c小,交换b和c的值,使b存放大的数字
    {
        tmp=b;
        b=c;
        c=tmp;
    }
    printf("按照从大到小的顺序为:%d,%d,%d\n",a,b,c);
    return 0;
}