我在32位Ubuntu虚拟机上使用Eclipse来处理项目.在尝试实现结构时或者在尝试运行特定函数时,我遇到了一个大问题.功能就是这个:
int count (matrix m, int v[], int w[], int col) {
int r=0;
int j=0;
while (j < m.length) {
int k=0;
bool aux=true;
while (k < col && aux ){
if (v[k] == 1) {
if(m.i[j][k] != w[k])
aux=false;
}
k++;
}
if(aux) r++;
j++;
}
return r;
}
Run Code Online (Sandbox Code Playgroud)
此函数接收矩阵(在下面定义),带有1和0的向量(用于了解要搜索的列,具有我们要在这些列中搜索的值的向量以及列数(等于向量的长度)当它击中第二个"如果"它给我分段错误(我无法理解它是什么),我可以看到以这种方式定义它是不正确的,但我已经尝试过并且我可以好像找到了一种方法来访问向量中的值.这是我的结构矩阵:
typedef int *ind;
struct matrix {
ind *i;
int length;
};
typedef struct matrix matrix;
Run Code Online (Sandbox Code Playgroud)
在这个结构中,我的矩阵有一个指针和长度(行数); 指针指向一个指针向量(每行一个指针),这些指针中的每一个指向一个矢量,实际上是我的矩阵行.这里我的函数添加并创建一个空矩阵:
matrix emptyS(int n, int col) {
matrix m;
int d=0;
m.length=0; …Run Code Online (Sandbox Code Playgroud) 我有一个用Java创建绘图程序的任务.我设法创造了一些但不完全是我想要的东西.
我的问题是我无法从IDE提供的选项中在IDE(NetBeans 7.0.1)中创建JFrame,并正确调用paint类.
更具体一点的是,我想按一个面板上的按钮(例如Panel1)并在Panel2中绘制同一帧.
这是班级的召唤:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
PaintFlower102 f = new PaintFlower102();
}
Run Code Online (Sandbox Code Playgroud)
课程的一部分:
super("Drag to Paint");
getContentPane().add(new Label ("Click and Drag"),BorderLayout.SOUTH);
// add(new JButton("Brush 20"),BorderLayout.NORTH);
addMouseMotionListener( new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent event) {
xval=event.getX();
yval=event.getY();
repaint();
}
});
setSize(500, 500);
setVisible(true);
setDefaultCloseOperation(PaintFlower102.DISPOSE_ON_CLOSE);
}
public void paint(Graphics g) {
g.fillOval(xval, yval, 10, 10);
}
Run Code Online (Sandbox Code Playgroud)
问题是,如果我不把它extend JFrame放在课堂上这不起作用.如果我这样做,它会创建一个我可以绘制的新框架.
我有以下功课问题:
给定一系列分数,如果阵列中彼此相邻的分数为100,则返回true.数组长度至少为2.
这个问题是否意味着数组中的数字应该可以被100整除?所以如果它在数组中,1也会使程序返回true?
我想用C++制作DVD租赁应用程序.我已经完成了客户类的基础知识,另一个类是持有CustomerDB的客户ID.每个客户都有一个唯一的ID.
我想在进一步执行程序之前测试CustomerDB,但是在编译程序时出现错误.
这是我写的代码:
头文件:
// DVD_App.h - Header File
#include <string>
#include <map>
using namespace std;
enum Status {ACTIVE, INACTIVE};
class Customer {
private:
string id;
string name;
string address;
Status status;
public:
Customer (const string&, const string&, const Status);
string &getId () { return id; }
};
class CustomerDB {
private:
static map<string, int> idList;
public:
static void addNewToIdList (const string &threeLetterOfName) {
if (!doesThreeLettersOfNameExist(threeLetterOfName))
idList.insert(pair<string, int>(threeLetterOfName, 0));
}
static bool doesThreeLettersOfNameExist (const string &threeLetterOfName) {
map<string, int>::iterator i …Run Code Online (Sandbox Code Playgroud) 好吧,我是操作员重载的新手,我必须在面向对象的程序中执行此功能,但我绝对需要帮助.以下是说明:
MyString对象应包含打印字符串的Print()方法
MyString对象应包含一个Length()方法,该方法报告字符串的长度
MyString对象应该包含一个默认构造函数,它将初始字符串设置为"Hello World"的值.
MyString对象应包含一个备用构造函数,允许设置字符串的初始值.
MyString对象应该重载以下运算符:
应重载括号运算符以替换先前分配的Set和Get函数.请注意,两个实例都应在违反字符串数组bounaries时发出exit(1).
赋值运算符(=)将源字符串复制到目标字符串中.请注意,目标的大小需要调整为与源相同.
逻辑比较运算符(==)如果两个字符串的大小和内容相同则返回true.
返回布尔否定为2的否定逻辑比较运算符(!=).
连接运算符(+),用于连接两个字符串
以下方式使用的加法/分配运算符(+ =):String1 + = String2作为String1 = String1 + String2运行
加法(+)和赋值(=)运算符都需要能够进行级联操作.这意味着String3 = String1 + String2,或String1 = String2 = String3应该工作.
这是我在.cpp文件中的代码:
MyString::MyString()
{
char temp[] = "Hello World";
int counter(0);
while(temp[counter] != '\0') {
counter++;
}
Size = counter;
String = new char [Size];
for(int i=0; i < Size; i++)
String[i] = temp[i];
}
MyString::MyString(char *message)
{
int counter(0);
while(message[counter] != '\0') {
counter++;
}
Size = counter;
String = …Run Code Online (Sandbox Code Playgroud) 我有一个条件如下的任务 - 它是关于Java /数据结构.我会尽量简短地提出我的问题,因为回答这些问题会帮助我找到方法(因为我迷路了):
简单的信息检索系统,其中查询包含关键字,并且有一组要搜索的文档.在响应查询时,系统识别包含所有或一些关键字的每个文档(最多n个文档)并按照找到的关键字的降序打印文档名称,即包含所有关键字的文档应出现在顶部列表.
我正在为一个项目工作,我被要求获取一个.txt文件,将数据聚合到不同的对象中,然后根据共享特征对该列表进行排序.我的指示是使程序能够导入多达200行文本.
我已经成功实现了导入.txt文件的程序,给定了一个已定义的数组大小(如果.txt文件有6行,一个包含6个元素的数组),但我需要能够定义最多200个元素.当超出实际元素的数量时,例如6,它会抛出NullPointerException.我似乎无法找到这可能发生的地方,因为我的代码至少在视觉上出现,以处理可能发生的任何实例.这是问题发生的地方:
public Solid[] solids;
public int length;
public Measurer m;
public int h;
public SolidList(int size) {
length = 0;
solids = new Solid[size];
}
public void addSorted(Solid foo, Measurer m) {
int k = 0;
if (length != 0) {
while ((k < length) && foo.greaterThan(solids[k], m))
++k;
for (int j = length; j > k; --j)
solids[j] = solids[j - 1];
}
solids[k] = foo;
++length;
}
Run Code Online (Sandbox Code Playgroud)
具体来说,Eclipse在while循环中遇到NullPointerException addSorted(...).只有当数组确实具有null元素时才会发生这种情况,但我想我无法弄清楚如何阻止该方法尝试访问null元素.
我正在使用命名管道与进程通信.我已经能够使用以下代码.(原始代码在这里:via archive.org)
class ProgramPipeTest
{
public void ThreadSenderStartClient(object obj)
{
// Ensure that we only start the client after the server has created the pipe
ManualResetEvent SyncClientServer = (ManualResetEvent)obj;
using (NamedPipeClientStream pipeStream = new NamedPipeClientStream(".","ToSrvPipe",PipeDirection.Out,PipeOptions.None))
{
// The connect function will indefinately wait for the pipe to become available
// If that is not acceptable specify a maximum waiting time (in ms)
pipeStream.Connect();
Console.WriteLine("[Client] Pipe connection established");
using (StreamWriter sw = new StreamWriter(pipeStream))
{
sw.AutoFlush = true;
string …Run Code Online (Sandbox Code Playgroud) 所以基本上给出了以下代码.
何时action = 2;和mode = 1将i被设置为2?
我正在研究同事代码,它是这样编写的,但我认为中断只会跳过if并继续其余部分case 2.所以基本上if语句是没有意义的.
switch(action){
case 1: i = 1; break;
case 2: if(mode == 1)
{
break;
}
i = 2;
break;
case 3: i = 3; break;
Run Code Online (Sandbox Code Playgroud)
我把它重写为:
case 2: if(mode != 1)
i = 2;
break;
Run Code Online (Sandbox Code Playgroud)
但它不是唯一的地方,有些更复杂.如果我要重构它,我需要一些我正确的信息.