I am wondering if you could suggest some websites that offer free lesson in C++ or Java. I cannot afford going into school and such to learn more. Thanks in advance guys!
mercredi 1 juillet 2015
Is it possible to define a Stan model in terms of an arbitrary posterior function?
Is it possible to define a Stan model in terms of an arbitrary posterior function?
I'm thinking something like MCMCPack's MCMCmetrop1R() functionality where the user defines an arbitrary posterior function. I would be fine with digging into the C++ API to do this if there's a good example of how to go about it.
Running external executable in Qt using QProcess
I'm trying to run an external executable (code below) in Qt as a separate process.
test.c:
#include <stdio.h>
int main () {
FILE *f;
f = fopen("a.txt", "w");
fprintf(f, "1\n");
fclose(f);
return 1;
}
and in Qt I have:
QProcess* process = new QProcess();
QString program = "/Users/myUser/Desktop/a.out";
process->execute(program);
I've read up on the differences between execute(), start(), and startDetached() and to my understanding I want to use execute() because I want the process running the external executable to finish before continuing execution in the main process. However I've tried all three expecting to find a file a.txt containing the text "1" in it, but it doesn't exist. Any help or suggestions as to why it's not working? Thanks!
Transform and accumulate with C++11
Coming from Python I wonder if C++ nowadays has some good functional things there are in Python.
Currently I am trying to figure out how to produce a sum of some elements using indexes instead. For example with Python I would:
a = [ ... ]
b = [ ... ]
sum(map(lambda i: a[i] * 2 - b[i + 1], range(len(a)))
So here I generate a new array where each element is determined by some index arithmetic.
In STL there are transform and accumulate, but they take iterators as arguments. This would be OK if only on each step I needed to change a concrete element. Here I need to use index.
Also with transform I have to specify the array I need to put the results to. Is there a way the resulting array could be generated on the fly and then returned? Something like Python's map does.
Because in such case it's really easier to write a simple for-loop.
i find it difficult to only allow numbers tried different methods and failed can anyone show me how its done
include
void main(void){
You are required to write a c program to find how many numbers are greater than the entered value between 1 and a user entered upper limit. for example, if you enter the value 15 as the upper limit and 7 as your number, then the program must give the output as 8.
The program output must be as shown below.
Enter an upper limit : 15 Enter a number between 1 and 15 : 7 ==> there are 8 numbers greater than 7 Do you want to check more values? (y/n)
if typed Y, clear the screen and prompt user to re-enter the upper limit and a number, and if typed n, end the program.
}
// can anyone help me in completing this? with the correct error messages and allowing only numbers to be input!
indirection requires pointer operand and expected expression errors
I keep getting errors similar to these:
pitstop.cpp:36:23: error: indirection requires pointer operand
('double' invalid)
cost = UNLEADED * gallons;
^ ~~~~~~~
pitstop.cpp:40:14: error: expected expression
cost = SUPER * gallons; ^
#include <iostream>
#include <iomanip>
using namespace std;
#define UNLEADED 3.45;
#define SUPER {UNLEADED + 0.10};
#define PREMIUM {SUPER + 0.10};
/*
Author: Zach Stow
Date:
Homework
Objective:
*/
double cost, gallons;
string gasType, finish, stop;
int main()
{
for(;;)
{
cout <<"Hi, welcome to Pitstop.\n";
cout <<"Enter the type of gas you need:";
cin >> gasType;
cout << endl;
cout <<"Enter the amount of gallons you need:";
cin >> gallons;
cout << endl;
if(gasType == "finish" || gasType == "stop")break;
else if(gasType == "UNLEADED")
{
cost = UNLEADED * gallons;
}
else if(gasType == "SUPER")
{
cost = SUPER * gallons;
}
else if(gasType == "PREMIUM")
{
cost = PREMIUM * gallons;
}
}
cout <<"You need to pay:$" << cost << endl;
return(0);
}
Make template function for nested container
I'm trying to make a generic test function that takes a container such as list, set or vector, and returns nested container: list of lists, set of sets, vector of vectors. Non-generic functions look like this:
vector<vector<string>> test(vector<string>& in_container)
{
vector<vector<string>> out_continer;
// out_continer will be filed using values from in_container
return out_continer;
}
list<list<int>> test(list<int>& in_container)
{
list<list<int>> out_continer;
// out_continer will be filed using values from in_container
return out_continer;
}
set<set<float>> test(set<float>& in_container)
{
set<set<float>> out_continer;
// out_continer will be filed using values from in_container
return out_continer;
}
But I dont know how to make one template test function that would be equivalent to these separate test examples.