C++ :: Assign Value To Interval
Oct 2, 2014
This is my code , i should Assign value val to interval [keyBegin, keyEnd).
#include <assert.h>
#include <map>
#include <limits>
void assign( K const& keyBegin, K const& keyEnd, const V& val ) {
if(!(keyBegin<keyEnd))
[Code] .....
View 7 Replies
ADVERTISEMENT
Feb 11, 2015
I'm having some trouble finishing my code, it's meant to give the number of twin primes between an interval e.g. 1 to 1000000 and the answer should be 8169 but all I can get it to is 8168
#include <stdio.h>
int prime (int num) {
int div;
if (num == 2) return 1;
if (num % 2 == 0) return 0;
div = 3;
while (div*div <= num) {
[code]....
View 6 Replies
View Related
May 28, 2013
I have a certain piece of code that I want to run every 2 minutes. One of my ideas is to get the time and modules that with whatever number represents 2 minutes. Would this work?
View 4 Replies
View Related
Oct 30, 2013
I've been trying to get the numbers for hours now but i can seem to get it right. Here's the problem below:
During the initial period, when the heater is not yet functioning at peak efficiency the heating will increase the temperature inside the building at a rate given by the following equations. During the initial period when the air conditioner is not yet functioning at peak efficacy the air conditioner will decrease the temperature inside the building at a rate given by the same equations.
Interval = (Time since turning on / 2.0 ) - 3.0
Factor multiplying Temperature change per minute = exp( Interval) / ( 1 + exp(Interval) )
These equations can also be used after the heating or air conditioner reaches peak efficiency. These equations converge to 1, so after the heating or air conditioner reach peak efficiency these equations will always give a value of 1.
the value of these equations needs to be multiplied by the RATE TEMPERATURE CHANGES. The RATE TEMPERATURE CHANGES is EITHER the change in temperature inside the building in degrees Celsius per minute caused by heat being extracted by the air conditioning OR the change in temperature inside the building in degrees Celsius per minute caused by the heat being generated by the heating .Temperature change in degrees per minute = Factor multiplying Temperature change per minute * RATE TEMPERATURE CHANGES
Temperature at end of this interval = Temperature at the start of the interval + temperature change due to heat escaping during the this interval + temperature change due to heat generated by the heating system during this interval + temperature change due to heat removed by the cooling system during this interval
i have a:
...rate of -.05 for heat escape w/o cooling or heating
...rate of 0.10 for heat escape w/ cooling
...rate of 0.125 for heat increase w/ heating
...Starting temp=38.00
...Time interval 3.50
I can't seem to find the temp at the ending interval? What i tried doing:
Code:
#include<iostream>
#include<cmath>
using namespace std;
int main () {
double intervals=0.00;
double tempPerMin=0.00;
[Code] ....
The temperature at the end of the interval is suppose to be 37.81 but i can't get the answer. I'm pretty sure this is a logical error from the equations i used but i can't seem to find it.
View 3 Replies
View Related
Feb 6, 2013
How can I generate a pseudo-random real number from interval [0,1] ?
Can it be generalized to any interval? Like [0,a], where 'a' is a parameter?
I tried searching for it, I only found rand(), srand(), random(1), and randomize. None of it actually seems to work for me..
Later I actually succeeded with something like
srand( (unsigned)time( NULL ) );
printf( " %6d
", rand() );
but it only produces up to five digits integers and I cannot divide by 99999 to get it into [0,1].
View 11 Replies
View Related
Apr 23, 2014
how can i make a program which allows a user to enter an input for a time interval for example i ask a question and sets the input to be entered within 10 seconds...
View 4 Replies
View Related
Mar 27, 2013
I'm trying to write a code which will generate numbers for a binomial coefficient from a number interval [2-10], i think it should look like this:
n=2
r=2
n=2
r=3
n=2
r=4
n=2
r=5
.
.
.
n=10
r=10
-The program should stop here.
This is badly written, but it still has the basic idea in it.
#include <iostream>
using namespace std;
int main () {
int n=2;
int r=1;
[Code] ....
View 1 Replies
View Related
Jun 18, 2013
I have array of pointers and when i tried to assign values dynamically all array items have the same value which is last value.
char* list[];
int DynamicDemo(void)
{
[Code].....
View 2 Replies
View Related
Apr 21, 2013
I am having some difficulties knowing how to assign city to the list.
Code:
class DestinationList
{
private:
int num;
// number of objects in the list
Destination list[MAX_CITIES];
// array of destinations
public:
[Code]...
View 14 Replies
View Related
Jan 24, 2013
How can we assign a pointer to a function? const char* function_name(), here what exactly does the pointer point to?
View 4 Replies
View Related
May 26, 2013
Im starting with C. Like I said in the title, how do I assign the value from a function to a variable? I mean I have this function:
Code:
int EnteroAleatorio(){
rand();
return rand();
}
and I would like to assign the value of EnteroAleatorio to a variable in my main function, but when I try to do it and compile, I got the next error: non-lvalue in assignment
View 1 Replies
View Related
Jan 15, 2015
Why would you ever assign a pointer to an existing array?Take this link for example. URL....I understand that pointers use dynamic memory allocation so they are much more flexible then a built in array, but if you already have an existing array, don't you already have static memory allocation for that array? Why bother assigning a pointer? Regardless of the pointer, doesn't the program still allocate static memory to the array anyway?
View 3 Replies
View Related
Apr 24, 2015
I have a silverlight app that uses TextBox XAML controls.
In the c++ code-behind, IXRTextBoxPtr types are associated with these textboxes using "FindName" like this:
FindName(L"ColNum3", &m_pColNum3);
(where ColNum3 corresponds with the XAML CODE like this: )
Then, the code assigns the pointer like this:
std::wstring wsTransfer; // gets the wstring from imput
const WCHAR * wpszInput;
wpszInput = wsTransfer.c_str();
m_pColNum3->SetText(wpszInput);
but the display does not show the text data.
What am I missing? What steps am I missing to have this text modification display on the screen?
View 6 Replies
View Related
Dec 3, 2012
Below assignation? It is a bit confusing.
myString = ""myInteger"is";
View 1 Replies
View Related
Apr 26, 2012
I am making a game Pong, and have been struggling with the collision aspect between the baal hitting off the paddle. I have created a Class, to draw a rectangle, to work with collision however I dont know how to assign the rectangle to the images of the ball and paddle.
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <vector>
#include <cmath>
#include "gwin.h"
const int NUMBEROFBALLS = 1;
[Code] .....
View 1 Replies
View Related
Oct 29, 2013
If I have a one-dimensional array of length 10, vector<int> x, and I want to assign all the elements to value 5, then I can do the following:
Code:
vector<int> x(10);
x.assign(10, 5);
(I can also do this in x's constructor, but in my scenario I want to repeatedly assign x's elements in a loop, without having to construct a new vector in memory each time.)
If I now have a two-dimensional vector, vector<vector<int> > y, and I want to assign the first vector to length 20, the second vector to length 10, and each element in the second vector to value 5, then I can do the following:
Code:
vector<vector<int> > y(20, vector<int> (10));
for (int i = 0; i < 20; i++) {
y[i].assign(10, 5);
}
But is it possible to do this without the loop? Can I make the two-dimensional assignment in just one line, in the same way that the one-dimensional assignment was made?
Perhaps it would like something like the following, which is not correct but illustrates what I mean:
Code:
y.assign(20, assign(10, 5));
Another way of doing this would be the following:
Code:
y.assign(20, vector<int> (10, 5));
But wouldn't this cause the memory in the second array to be dynamically allocated each time? I don't want to do this - I want to keep the same memory, but just assign the elements to 5.
View 1 Replies
View Related
May 13, 2013
I'm trying to learn how to assign bit widths manually to numbers. Here's my code below:
Code:
#include <stdio.h>
struct node {
unsigned long x : 53;
[Code].....
And I get the following complaint from the -Wall compilation flag, " warning: format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'long unsigned int:53' " which is talking about anna.z, to be specific.
How do I add field width to printf?
View 3 Replies
View Related
Feb 17, 2015
See the simple code below. The compiler gives message:
assigning to type "char[20]" from type "char *".
I've tried everything else that seems reasonable but none works. How can I assign string Hello to the structure member?
Code:
int main() {
struct strc1
{
char msg1[20];
char msg2[5];
}
talk;
talk.msg1 = "Hello";
}
View 5 Replies
View Related
Mar 22, 2014
I have this code:
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
[code]....
What I want is basically to assign to the *p the pointer of the string so that i could do the following printf(" print string %s",*p); so i dont know how to do that.
View 6 Replies
View Related
May 2, 2013
When I try to assign strings to a double pointer, it only prints out the last string when I try to print everything out, and then it segfaults.
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
main(){
char **test = calloc(3,sizeof(char));
[Code] .....
Am I assigning something the wrong way? Also, I am trying to avoid using array notation in order to practice, at least for the assigning of the strings.
View 11 Replies
View Related
Feb 22, 2014
I have to ask system (linux) for a value and then assign it to the variable.
Example:
unsigned char date[] = system("date");
Of course this is wrong, but illustrated what is my goal.
How to achieve this effect ? I've heard about POSIX but how to include and use it.
View 10 Replies
View Related
Feb 13, 2015
I'm a C beginner trying to assign struct member values to other struct members to create a list.
I've tried dot notation, pointer notation, strcpy, memcpy, memmove and normal assignment.
Nothing has worked.
cust_list.h
View 5 Replies
View Related
Jul 11, 2014
How to assign numbers stored in a buffer memory to a 2D array.
The data type is unsigned 16bit (unsigned short) integers and they are stored in a 16bit/2bytes*1280*1024=2621440 bytes memory. The pointer pBuffer is the starting address of the buffer. Now I initiated an array and then assign the numbers to the array.
Code:
unsigned frame[1280][1024];
for (int i=0;i<1024;i++){
for(int j=0;j<1280;j++){
frame[i][j]=(*(unsigned short*)pBuffer+1024*i+j);
printf("%u ", frame[i][j]);
}
printf("
");
}
Because I know the number in the memory, I know after running the code that the result gives me nonsense.
I tried frame[i][j]=(*(unsigned short*)pBuffer+1024*2*i+2*j);
Since I think the pointer needs to move 2 bytes at a time, but it still gives me nonsensical array back.
Am I using the wrong expression to assign the values?
View 3 Replies
View Related
Jan 31, 2015
Assign value of pow(2,800) to char array or string ....
View 1 Replies
View Related
Jun 17, 2013
typedef tr1::unordered_map <string, pin *> pin_cmp;
pin_cmp _pin_cmp;
_Pins[_num_pins] = new pin (pin_id, _num_pins, s, n, d);
_pin_cmp[_Pins[_num_pins]->get_name ()] = _Pins[_num_pins]; //performance profiling
What actually the code doing?
_pin_cmp[_Pins[_num_pins]->get_name ()] = _Pins[_num_pins]; //performance profiling
I am not familiar with unordered_map which still can use with array[].I am confuse unordered_map just need key and value why will have array[]?
View 1 Replies
View Related
Jul 17, 2013
this is the first time to ask my question on Cplusplus. my qustion is i got this message when i trying to run this code:
object.h
#ifndef __NCTUNS_nslobject_h__
#define __NCTUNS_nslobject_h__
#include <stdio.h>
[Code].....
so, my problem is when the compiler starts compiling it stops on this code :
NslObject::newKeyPair (RSA::GenerateKeyPair(keyLength));
and the appeared message is :
Error:
object.cc: In function ‘void Set_KeyPair()’:
object.cc:53: error: no match for call to ‘(KeyPair) (KeyPair&)’
so, how could i assign a generated keypair class value to NslObject::newKeyPair.
View 2 Replies
View Related