我是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) 我知道后缀数组本身的定义是它是一个字符串所有后缀的排序数组.但我试图了解这种排序操作的重要性在这里?假设我们创建了一个包含字符串所有后缀的数组,并选择不对其进行排序并继续构建LCP数组,当我们尝试解决诸如Longest Palindromic子字符串之类的常见问题时,我们在这种情况下会松动什么呢?最长的重复子串?
证明给定图 G 和数字 k,有某种方法可以将其转换为图 H,使得 G 具有大小至少为 k 的独立集合,当且仅当 H 具有大小至少为 k 的团伙时。
我试图通过一个用C编写的简单控制台应用程序来庆祝StackOverflow上的10,000,000个问题,但我不想浪费任何内存.在内存中存储数字10,000,000的最有效方法是什么?
所以我不得不用一个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) 我正在尝试解决这个问题http://www.mycodeschool.com/work-outs/sorting/7 问题是在插入排序中找不到任何变化。
我已经编写了代码,但无法弄清楚我在逻辑上哪里出错了
#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) 我需要弄清楚如何改进以下代码:
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) 对于学校作业,我需要通过使用来删除矢量中的紫色,这就是我想出的:
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++ ×5
algorithm ×3
arrays ×2
sorting ×2
string ×2
avl-tree ×1
b-tree ×1
c ×1
destructor ×1
for-loop ×1
graph ×1
java ×1
memory ×1
np ×1
recursion ×1
refactoring ×1
return-value ×1
suffix-array ×1