小编tem*_*def的帖子

C++返回值显示-858993460

我是c +的新手,并试图创建一个汽车类程序,要求用户一年和汽车制造.然后程序采取速度,始终从0开始,加速5mph 5次,并以5英里/小时制动5次.我必须使用头文件和2个cpp文件创建程序.速度的返回值不正确,并显示为:

输入汽车年份:2000输入汽车品牌:雪佛兰起始速度为-858993460

目前的速度是:-858993455英里每小时.

目前的速度是:-858993450英里每小时.

目前的速度是:-858993445英里每小时.

目前的速度是:-858993440英里每小时.

目前的速度是:-858993435英里每小时.

目前的速度是:-858993440英里每小时.

目前的速度是:-858993445英里每小时.

目前的速度是:-858993450英里每小时.

目前的速度是:-858993455英里每小时.

目前的速度是:-858993460英里每小时.

按任意键继续 ...

任何人都可以帮我弄清楚我做错了什么?到目前为止,我已经附上了我的内容.任何帮助是极大的赞赏.谢谢

#define CAR_H
#include <string>
using namespace std;

class Car 
{
   private:
        int yearModel;
        string make;
        int speed;

    public:
        Car(int, string);
    void accelerate();
        void brake();
       int getSpeed ();

};

#include <iostream>
#include "Car.h"
using namespace std;

Car::Car(int carYearModel, string carMake)
{
    int yearModel = carYearModel;
    string make = carMake;
int speed = 0;
}

void Car::accelerate()
{
    speed += 5;
}

void Car::brake()
{ …
Run Code Online (Sandbox Code Playgroud)

c++ return-value

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

后缀在后缀数组中排序的重要性是什么?

我知道后缀数组本身的定义是它是一个字符串所有后缀的排序数组.但我试图了解这种排序操作的重要性在这里?假设我们创建了一个包含字符串所有后缀的数组,并选择不对其进行排序并继续构建LCP数组,当我们尝试解决诸如Longest Palindromic子字符串之类的常见问题时,我们在这种情况下会松动什么呢?最长的重复子串?

sorting string algorithm suffix-array data-structures

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

将独立集减少为派系?

证明给定图 G 和数字 k,有某种方法可以将其转换为图 H,使得 G 具有大小至少为 k 的独立集合,当且仅当 H 具有大小至少为 k 的团伙时。

graph np

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

在不旋转的情况下保持 AVL 树平衡

B树与AVL树一样是自平衡树。在这里我们可以看到如何使用左右旋转来保持 AVL 树平衡。

这里是一个解释 B 树插入的链接。如果我没记错的话,这种插入技术不涉及任何旋转来保持树平衡。因此它看起来更简单。

问题:是否有任何类似的(或任何其他不使用旋转的技术)来保持 avl 树平衡?

algorithm b-tree avl-tree data-structures tree-balancing

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

C中可存储10,000,000的最小数据类型是什么?

我试图通过一个用C编写的简单控制台应用程序来庆祝StackOverflow上的10,000,000个问题,但我不想浪费任何内存.在内存中存储数字10,000,000的最有效方法是什么?

c memory

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

HEAP CORRUPTION DETECTED:私有阵列

所以我不得不用一个Point类创建一个程序,它需要多少维度,然后我在类中设置了一个带有如此多坐标的funktion,并且这样做我必须创建一个动态数组,因为它的大小不是'固定的.

class Punkt
{
private:
    char n;
    int d;
    double* k = new double[d];
public:
    Punkt(int);
    void Name(char);
    void Initialisieren();
    ~Punkt();
};
Run Code Online (Sandbox Code Playgroud)

这是定义这些函数的地方:

Punkt::Punkt(int dimension)
{
    d = dimension;
}

void Punkt::Name(char name)
{
    n = name;
}

void Punkt::Initialisieren()
{
    for (int i = 0; i < d; i++) {
        cout << "Geben sie bitte die " << i + 1 << ". Koordinate von " << n << " ein: ";
        cin >> k[i];
        cout << endl;
    } …
Run Code Online (Sandbox Code Playgroud)

c++ arrays destructor heap-corruption

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

确定插入排序中执行的移位次数?

我正在尝试解决这个问题http://www.mycodeschool.com/work-outs/sorting/7 问题是在插入排序中找不到任何变化。

我已经编写了代码,但无法弄清楚我在逻辑上哪里出错了

http://ideone.com/GGjZjw

#include<iostream>
#include<cstdio>
#include<cmath>
// Include headers as needed

using namespace std;

int main()
{
// Write your code here
int T,count,n,*a;
// int imin;
cin >> T;
int value,hole;

while(T--)
{
    cin >> n;
    count=0;
    a=new int[n];
    //reading the input array
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }

    // considering the 0th element to be already sorted and
    // remaining list unsorted
    for(int i=1;i<n;i++)
    {
        value=a[i];
        hole=i;
        // shifting 
        while(hole>0&&a[hole-1]>value)
        {
            // …
Run Code Online (Sandbox Code Playgroud)

c++ arrays sorting insertion-sort

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

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

重构 - 简化java中的嵌套for循环

我需要弄清楚如何改进以下代码:

      for (DirCategory c1 : categories1) {
            c1.setCount(dirEntryService.getDirEntryCategoryCount(c1));
            log.debug("c1: "+c1.getCount()+" - "+c1.getName());
            dirCategoryService.persist(c1);

            List<DirCategory> categories2 = c1.getChildren();
            for (DirCategory c2 : categories2) {
                c2.setCount(dirEntryService.getDirEntryCategoryCount(c2));
                log.debug("  c2: "+c2.getCount()+" - "+c2.getName());
                dirCategoryService.persist(c2);

                List<DirCategory> categories3 = c2.getChildren();
                for (DirCategory c3 : categories3) {
                    c3.setCount(dirEntryService.getDirEntryCategoryCount(c3));
                    log.debug("    c3: "+c3.getCount()+" - "+c3.getName());
                    dirCategoryService.persist(c3);

                    List<DirCategory> categories4 = c3.getChildren();
                    for (DirCategory c4 : categories4) {
                        c4.setCount(dirEntryService.getDirEntryCategoryCount(c4));
                        log.debug("      c4: "+c4.getCount()+" - "+c4.getName());
                        dirCategoryService.persist(c4);

                        List<DirCategory> categories5 = c4.getChildren();
                        for (DirCategory c5 : categories5) {
                            c5.setCount(dirEntryService.getDirEntryCategoryCount(c5));
                            log.debug("        c5: "+c5.getCount()+" - "+c5.getName()); …
Run Code Online (Sandbox Code Playgroud)

java recursion refactoring for-loop

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

C++从vector <algorithm>和<functional>中删除字符串

对于学校作业,我需要通过使用来删除矢量中的紫色,这就是我想出的:

bool IsEqual(string s, string s2)
{
    if (s == s2)
    {
        return true;
    }
}

int main() {
    vector<string> coulours2 = { "red", "green", "blue", "orange", "purple", "orange", "black", "green" };
    vector<string>::iterator newEnd;
    newEnd = remove_if(coulours2.begin(), coulours2.end(), bind2nd(IsEqual, "purple"));
    colours2.erase(newEnd);
    cin.get();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是我遇到了很多错误,我认为我使用的是bind2nd错误.我该如何正确使用它?

c++ string functional-programming

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