小编0x4*_*16e的帖子

如何计算圆周长的点?

如何在各种语言中实现以下功能?

(x,y)在给定输入值的情况下计算圆周上的点:

  • 半径
  • 角度
  • Origin(可选参数,如果语言支持)

algorithm math trigonometry

215
推荐指数
4
解决办法
26万
查看次数

类继承的 C++ 问题

我有一些变量和函数的基类以及多个子类。我想尽可能减少子类中所需的代码量。

我的代码示例:

#include <iostream>

class base{
public:
   int a = 10;
   int b;
   void print()
   {
      std::cout << a <<std::endl;
   }
};

class child: public base
{
   public:
      int a;
};

int main()
{
    child ch;
    ch.a = 20;
    ch.print();

}
Run Code Online (Sandbox Code Playgroud)

由于打印了结果编号 10,这意味着使用了基类变量a,但我需要使用子类变量(如果存在)。所以这个例子的预期输出是 20。

c++

4
推荐指数
1
解决办法
73
查看次数

如何在c ++中输出以毫秒为单位的时间?

#include <iostream>
#include <chrono>
#include <time.h>
#include <stdio.h>

using namespace std;
using namesapce chrono;

int main() {
  int f;
  time_t start, end;
  time (&start);
  cin >> f;
  time (&end);
  double dif = difftime (end, start);
  printf ("Elapsed time is %.2lf seconds.", dif );
}
Run Code Online (Sandbox Code Playgroud)

大家好,我目前正在进行C++任务,基本上我需要在10秒内让用户输入内容.我设法找出如何计算秒的时间,但我需要它是毫秒,因为我必须找出10秒以上的毫秒数.我不熟悉C++,并且非常感谢任何可能有助于引导我朝着正确方向前进的建议.非常感谢

c++ time clock c++11 c++-chrono

2
推荐指数
2
解决办法
593
查看次数

当int超出char范围时,C中的Int到char转换规则

请参阅以下C代码.

#include <stdio.h>

int main(void)
{
    char c1 = 3000;
    char c2 = 250;
    printf("%d\n",c1);
    printf("%d\n",c2);
}
Run Code Online (Sandbox Code Playgroud)

上面代码的输出是

-72

-6
Run Code Online (Sandbox Code Playgroud)

请解释此处应用的整数到字符转换规则,因为3000和250都在char范围之外(-128到127).

c

2
推荐指数
1
解决办法
133
查看次数

如何修复“操作符不匹配[]”错误(C ++)

所以我得到了这个数组: int arr[] = {60,70,30,15,17,80,16,75,90,85,40,75};

我必须在数组的总和小于500的同时“拟合”尽可能多的元素(基本上删除最大的元素,直到总和小于500)。

这是我尝试过的:

#include <iostream>
#include <algorithm>
#include <list>

using namespace std;

int largestOfArray(int number[]);

int main()
{
    int sum = 0;
    int i = 0;
    int arr[] = {60,70,30,15,17,80,16,75,90,85,40,75};
    list<int> ar(arr,arr+12);

    for (i = 0; i < 12;i++) 
        sum += arr[i];

    while (sum > 500)
        ar.remove(largestOfArray(arr[12]));

    for (i = 0; i < 12;i++)
        sum += arr[i];

    for (i = 0;i < 12; i++)
        cout << arr[i];

    cout << sum;
    return 0;
}

int largestOfArray(int number[12]){ …
Run Code Online (Sandbox Code Playgroud)

c++

2
推荐指数
1
解决办法
332
查看次数

如何删除传递给函数`foo(new Object())`的对象?

我整天都在寻找这个.所以,C++如果你有这个代码:

#include <iostream>                                                                                                       

struct a {
    int x, y;
    a (int aa = 0, int bb = 0) : x{aa}, y{bb} {
    }
};

void printit (a*);
int main (void) {
    printit (new a {1,3});
    return 0;
}

void printit (a *aa) {
    std::cout << aa->x << " - " << aa->y;
}
Run Code Online (Sandbox Code Playgroud)

如果给我printit ()函数(意味着我无法访问printit()代码)并且printit()不删除对象,有没有办法可以删除我创建的对象?

printit (new a {1,3}); // <--- this object
Run Code Online (Sandbox Code Playgroud)

为了澄清,我的问题是如何在没有附加变量的情况下执行上述操作,并确保已创建的对象已被删除.

c++ oop pointers memory-management

0
推荐指数
1
解决办法
111
查看次数

标签 统计

c++ ×4

algorithm ×1

c ×1

c++-chrono ×1

c++11 ×1

clock ×1

math ×1

memory-management ×1

oop ×1

pointers ×1

time ×1

trigonometry ×1