我想在类参数中使用toString,但由于某种原因存在错误.代码是:
Animal.h
#include "Treatment.h"
#include "jdate.h"
#include <vector>
class Animal{
protected:
int id;
double weight;
int yy;
int mm;
int dd;
double accDose;
char sex;
vector<Treatment*> treatArray;
public:
Animal();
Animal(int newid, double newweight, int yy, int mm, int dd, char newsex, vector<Treatment*> treatArray);
~Animal();
};
Run Code Online (Sandbox Code Playgroud)
Treatment.h
#ifndef TRE_H
#define TRE_H
#include <string>
#include <sstream>
#include "jdate.h"
#include "Animal.h"
#include "Cattle.h"
#include "Sheep.h"
class Treatment{
private:
int id;
jdate dayTreated;
double dose;
public:
Treatment(int id,jdate dayTreated, double dose);
Treatment();
~Treatment();
string …
Run Code Online (Sandbox Code Playgroud) 我一直致力于一个用输入文本计算元音的程序.每次发现元音时,它都会使用此方法递归添加元音计数.但是,每次lastPos
达到负数时,我都会出现一个越界错误.如果lastPos
达到-1,我怎么能停止这个?
static int R_countVowels(String s, int lastPos)
{
switch (s.charAt(lastPos))
{ case 'a': case 'A':
case 'e': case 'E':
case 'i': case 'I':
case 'o': case 'O':
case 'u': case 'U': return (1 + R_countVowels(s, --lastPos));
default: return R_countVowels(s, --lastPos);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将Film类型更改为数据类型,以便更容易订购和保存并加载到文件,我在使用正确的参数匹配函数时遇到问题,使用类型更容易.
type Rating = (String, Int)
--type Film = (String, String, Int, [Rating])
data Film = Film String String Int [Rating]
deriving (Show,Ord,Eq, Read)
testDatabase :: [Film]
testDatabase = []
testFilm = ("Test","Test",2012,[("Test",8),("Test",5)])
saveToFile :: IO ()
saveToFile = do
putStrLn "Enter the output filename: "
name <- getLine
writeFile name (show testDatabase)
putStrLn "Done"
loadFromFile :: IO ()
loadFromFile = do
putStrLn "Enter the input filename: "
name <- getLine
contents <- readFile name
let testDatabase = length contents …
Run Code Online (Sandbox Code Playgroud) 所以我一直在尝试整天做这个功课,我仍然无法弄清楚如何编写一个方法来读取一行数字并将它们保存到一个数组中.这是我尝试但不起作用的
public static int [] readData()
throws java.io.IOException
{
int [] rArray = new int[15];
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String data = br.readLine();
StringTokenizer str = new StringTokenizer(data);
String d = str.nextToken();
int num = Integer.parseInt(d);
for(int i = 0; i < num; i++){
rArray[i] = num;
}
return rArray;
}
Run Code Online (Sandbox Code Playgroud) 我到处都有语法错误,对ADT语法和内存处理的理解不好.我需要一个在next
和中引用自身(其他部分)的结构prev
.我做得对吗?我收到错误......
struct _header * header;
typedef struct _header {
int signiture;
int size;
header_t* next;
header_t* prev;
} header;
Run Code Online (Sandbox Code Playgroud)
我还想用一个头来初始化内存中的前32个字节(这也不顺利......):
//this is to reference the memory block later
static int *free_list_ptr;
void function(u_int32_t size){
memory = (byte*) malloc(size);
header firstHead = malloc(sizeof(_header));
free_list_ptr = firstHead = memory;
firstHead->prev = free_list_ptr;
firstHead->next = free_list_ptr;
}
Run Code Online (Sandbox Code Playgroud) 我和SWT一起工作,我遇到了一些问题.基本上我有一个Text
对象,我希望它的宽度是它所在的组件的宽度.我可以使用,FillLayout
但它下面的按钮也会增长,这不是我想要的.
这是一个屏幕截图来说明问题:
这是我用来重现的测试代码,并尝试解决问题:
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;
public class Test {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
//setup the layout manager
GridLayout layout = new GridLayout(1, false);
layout.horizontalSpacing = 0;
layout.marginHeight = 0;
layout.verticalSpacing = 5;
layout.marginWidth = 0;
layout.marginBottom = 20;
layout.marginTop = 5;
shell.setLayout(layout);
//create the text field
Text inputField = …
Run Code Online (Sandbox Code Playgroud) 我有5个复选框,如果选中第一个复选框,则还应检查其他四个复选框.此外,如果取消选中第一个复选框,则应禁用这些复选框.当我这样做时,所有其他复选框都被启用和取消选中,所以我实现了以下代码:
<div class="total_line">
<label for="name">Beheerder </label>
<%= f.check_box:is_admin, {:onchange => "showHideDiv()"} %>
</div>
<div class="total_line">
<label for="onderwerp">Documenten beheren</label>
<%= f.check_box:document_management %>
</div>
<div class="total_line">
<label for="onderwerp">Nieuws beheren</label>
<%= f.check_box:news_management %>
</div>
<div class="total_line">
<label for="onderwerp">Agenda beheren</label>
<%= f.check_box:agenda_management %>
</div>
<div class="total_line">
<% if photo_book == true %>
<label for="onderwerp">Fotoboek beheren </label>
<%= f.check_box:photobok_admin %>
<% end %>
</div>
<div class="total_line">
<label for="onderwerp">Actief</label>
<%= f.check_box:is_actived %>
</div>
Run Code Online (Sandbox Code Playgroud)
以下是javascript
function showHideDiv() {
var mycheck = document.getElementById('membership_is_admin');
if (mycheck.checked) {
document.getElementById('membership_is_admin').setAttribute("readonly", 1) …
Run Code Online (Sandbox Code Playgroud) 我需要有关haskell中的旋转或旋转矩阵的帮助
我有一个数据类型为RGB的列表:
data RGBdata= RGB Int Int Int
m = [[(RGB 0 255 255),(RGB 255 0 0)],[(RGB 255 255 255),(RGB 255 0 0)]]
Run Code Online (Sandbox Code Playgroud)
更好看我有一个2x2矩阵:
m = [[(RGB 1 2 3),(RGB 4 5 6)],
[(RGB 7 8 9),(RGB 1 5 9)]]
Run Code Online (Sandbox Code Playgroud)
我需要90°旋转,我的意思是:
m = [[(RGB 7 8 9),(RGB 1 2 3)]
[(RGB 1 5 9),(RGB 4 5 6)]]
Run Code Online (Sandbox Code Playgroud)
扩展我的解释,我有2种数据类型:
data RGBdata= RGB Int Int Int
data PBMfile= PBM Int Int [[RGBdata]]
Run Code Online (Sandbox Code Playgroud)
我的功能收到:
spin :: PBMfile -> PBMfile
spin (PBM x y …
Run Code Online (Sandbox Code Playgroud)