C++ :: Exponential Power Function

Nov 13, 2013

Main is supposed to be sending values to the power function.Write a prototype and function for calculating powers of numbers.This version should have an integer return type and take two integer inputs, for the base and the exponent. It should do the following:

• handle negative bases
• return an error on negative exponents (we’re not doing those yet)
• handle zero exponents

Call your function from a nested loop in main(), which calls the function using every combination of negative, zero and positive numbers for both base and exponent. This will test your function without the user having to input all the data.Any code which calls the library pow() function will lose half of the assignment points.

#include <iostream>
using namespace std;
int power (int, int);
int main() {
int size = 10;
int test[size];
int base;

[code].....

View 1 Replies


ADVERTISEMENT

C :: Math Function Using Exponential Growth Formula

Sep 3, 2013

Its a basic math function using the exponential growth formula which is correct but the computer is not outputting the right numbers.

Code:
#include <stdio.h>
#include <math.h>
int main() {
int blanketsquares, num1, num2, blanket,remainder;

[Code] .....

View 6 Replies View Related

C++ :: Creating Recursive Function That Will Print Out A Number To A Power

Apr 9, 2013

I am trying to create a recursive function that i can call on in order to take a user inputed base and exponent and give final answer this is what i have but im completely lost after this i dont even know how to continue. What i have so far

#include <iostream>
using namespace std;
int Exp(int x,int y){
if(base <= 1 || exp == 0) return 1;
if(exp == 1) return base;
int main(){
int number, exp;

[Code] .....

After i set the base situations im not sure how to get the function to make the function take the base to the exponent recursively.

View 3 Replies View Related

C++ :: Compute And Output Power Set

Oct 30, 2013

I am trying to do a compute and output a power set program. The numbers will be input through a file. How to do a power set. Here is my code :

#include <iostream>
#include <fstream>
#include <string>
#include <ostream>
using namespace std;
int main () {
string array[21]; // creates array to hold names

[Code] .....

View 1 Replies View Related

C++ :: Lagrange Interpolation Formula - Substitute Values Into Power

May 7, 2013

I did a function for lagrange interpolation formula. However i`m stuck on how do i substitute values into the power. Here is my code snippet :

for(int i=1;i<getSecretShare+1;i++) {
//calculateValue=getSecret+(10*p)+(2 * pow(p,2));
int storeThreshold=getThreshold;
calculateValue=getSecret+(10*i)+(2 * pow(i,2));
calculateFinalValue=calculateValue % 17 ;
cout<<"the calculated value is "<<calculateFinalValue<<endl;
}

The formula that i want to implement is that a + a1x^1 + a2x^2 + a(t-1) ^t-1

I have gotten the substitution of the x value out. However, i am stuck on how do i calculate the values according to the threshold which the user keys in. For example if the user keys in 3.

It will into account the no. of shares to generate which is for example 5 in this case, then it will then take into account the threshold keyed in , which is 3, i will then calculate using the formula using the no. of shares and also threshold.
if the threshold is 3 and the number of shares to generate is 5. I should have the following:

y(1) = 13 + a1(1)^1 +a2(1)^2
y(2) = 13 + a2(2)^1 +a2(2)^2

the power depends on the threshold which is t-1, 3-1 =2

So I will have to generate two a values based on that and also calculate them according to the power that is dependent on the threshold the first value being to the power of 1 and the 2nd being to the power of 2 if the threshold is 4.

Then I will generate 3 a values and then calculate them :

y(1) = 13 + a1(1)^1 + a2(1)^1 + a3(1)^3

and so on..

View 4 Replies View Related

C :: Detect CPU Power Button Press Event In Console Application

Feb 5, 2015

I am using Windows 7 32bit OS and want to detect the CPU power button press event in my console application developing in C language.

I configured the power button setting to "Do Nothing" which is in "Choose what the power button does" options in Control Panel->Hardware and Sound->Power Options. So now i want to detect this power button press event and do some processing in my application then i will initate shut down from application itself. Looking for windows API details which will detect the power button press event.

View 2 Replies View Related

C++ :: Program To Check If User Presses Power Button On Computer

Jun 19, 2014

How you can make a c++ program that checks to see if the user presses the power button on their computer? And if so, how?

View 1 Replies View Related

C++ :: Equation That Determines The Lowest Possible Cost For Laying Power Line

Apr 9, 2013

I need an equation that determines the lowest possible cost for laying power line.

The variables are as follows:

1. The width of a river
2. The distance a factory is downstream from a station on the other side of the river.
3. The cost for laying line underwater.
4. The cost for laying line on land.

All these variables will be user input each use of program.

View 4 Replies View Related

C++ :: Determine Health Of A Power Transformer - Graphic User Interface?

Nov 27, 2014

I have a program I want to write that determines the health of a power transformer. I know the syntax of all the other code I might have to use but I'm not too sure of how to make it fit into a graphic interface like you see in any other windows program.

View 1 Replies View Related

C# :: How To Manually Control The Temperature Of High Power Leds Using PID Controller

Mar 20, 2015

how to manually control the temperature of High Power Leds using PID controller. I have two GUIs,one reads the temperature from the Led while the second is used to ON/OFF the Leds and at the same time controls the Led brightness using slider control.The GUI that reads the temperature has a PID controller application on it.The output from this controller is what i want to use to increase or decrease the Led brightness which invariable changes the Led temperature.How to go about using this PID controller to control the Led brightness is what i have not been able to grasp well.The slider on the GUI is scaled from 0% to 100%.My thinking is that the output from the controller should be in percentage which will make me to adjust the slider accordingly.My question is that will this type of arrangment produce an output that will efficiently control the Led brightness. how to accomplish that. Attached to this post is a modified code of a tutorial on PID controller which i found on the net. a tutorial on how to develop a graph. i wish to display the Setpoint,Process value and the output value on a graph.

View 2 Replies View Related

C++ :: Program To Find Shortest Path Between Vertices Using Matrix Power Multiplications

Feb 24, 2013

given matrix A find shortest path between vertices using matrix power multiplications untill u get nonzero values,use adjacency matrix

View 1 Replies View Related

C++ :: Syntax Error In Function Call - Type Mismatch In Parameter In Function Sort

Jul 6, 2014

error says "cannot convert 'int*' to 'int' in function main()
and also
type mismatch in parameter in function sort(int,int)

Heres the code:
#include<iostream.h>
#include<conio.h>
void main() {
void sort(int,int);
clrscr();

[Code] .....

View 11 Replies View Related

C :: Function That Will Work For Both Dynamic And Static Implementations Of A Function To Get Transverse Of Matrix

Feb 11, 2013

i need a function that will work for both dynamic and static implementations of a function to get the transverse of a matrix. so far, i have this

Code:

matrix transpose(matrix m)
{
int row, col;
row = m.com_dim;
col= m.row_dim;
}

[code]....

this works well with my static implementation, but when i try it in dynamic it gives me errors. the function has to be the same for both dynamic and static implementation

View 4 Replies View Related

C++ :: Keyboard Function That Is Called In Main Function To Make Shape Move

Jan 19, 2013

Ok so I am working on a game and I'm in the process of developing my Player class. Anyways, what I have is a keyboard function that is called in my main function to make a shape move.

void myKeyboardFunction(unsigned char key, int x, int y) {
switch ( key ) {

[Code].....

But when I try to call it, trying to copy my previous method,

glutKeyboardFunc(Player1.playerControls);

I get an error

error C3867: 'Player::playerControls': function call missing argument list; use '&Player::playerControls' to create a pointer to member

I get an error saying it can't convert parameters. I would just like to understand why the arguments become a problem when I make the function a member of my class, when the first method I used is so easy.

View 2 Replies View Related

Visual C++ :: Error C3867 Function Call Missing Argument List For Calling Thread Function

Mar 19, 2013

I searched the web for error: C3867... and the discussions where murky or obscure.

My code excerpt is:

#pragma once
#include <windows.h>
#include <stdlib.h>
#include <process.h>
void PutUpfrmIO(void *);
namespace WordParsor {

[Code] .....

I get the generic message:

error C3867: 'WordParsor::Form1::PutUpfrmIO': function call missing argument list; use '&WordParsor::Form1::PutUpfrmIO' to create a pointer to memberc:userskingc++wordparsorwordparsorForm1.h... and the suggestion fix generate another error.

One person suggested the gcroot<> object wrapper... but I do not know how to modify/declair the function or its argument type.

View 2 Replies View Related

C :: Reverse Function That Inserts And Prints Binary Function Correctly

Nov 3, 2013

I have written a function that inserts and prints a binary function correctly.

For example a tree like this [URL] ..... would print like this

Code:
node: 10
node: 7
node: 6
node: 8
node: 9

[Code] ....

Here is my print function

Code:
void prt_tree(struct node *tree) {
if (tree == NULL) {
printf("Null Tree
");
return;

[Code] .....

Could I just make some adjustments to my function to reverse it? and if so, how?

View 2 Replies View Related

C++ :: Pass 2 Arrays Into Void Function And Return Values To One Function?

Feb 12, 2014

I'm trying to pass 2 arrays into a void funtion, and return values to one function.

this is the the program I'm working with, after I'm done I have to split it into 3 files, a header, a main, and a separate cpp file for the functions to live in.

#include <iostream>
using namespace std;
void processArrary(int numberCount[], int Numbers[], int intnumberSize, int numberCountSize);
int main() {
int Scores[26] = {76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, 189};
int numberCount[8] = { 0 };

[code]...

The goal of this program is to separate and count the groups of numbers then output the amount of numbers in each group. Near as I can tell, everthing should work, but I'm getting all zeros to be displayed in each group.

View 6 Replies View Related

C :: Main Function Does Not Return Any Values When Calling Other Function?

Jun 9, 2013

The function is supposed to return value from the file in my main, but I am getting empty value. I am trying to get better with pointer. Right now just teaching myself.

right now the only way for this code to show value is when in put the putchar(*ps) inside my readfile function. I would like to readfile to return value and print in the main function.

Code:

#include <stdio.h>
char *readfile(char filename[]);
int main(int argc, char *argv[] ) {

[Code].....

View 4 Replies View Related

C++ :: Calling Base Function From Derived Overloaded Function

Nov 10, 2014

Here is a sample of my question

class Base{
public:
int getNum();
private:
int numToGet;
}
class Derived: public Base {
public:
friend ostream& operator<<(ostream& output, const Derived &B);

[Code]...

View 1 Replies View Related

C++ :: Passing 2 Dimensional Array Through Median Function To One Of 2 Other Function

Aug 20, 2013

I want to use one median function "selectfunction" to choose one of the 2 other functions at random to pass my 2-dim array to the selected function. There is a problem in the median function

#include <iostream>
#define random(x)(rand()%x) // for random number between numbers of 0 and 1
using namespace std;
void proc1 (int iArray[][2]);
void proc2 (int iArray[][2]);
void selectfunction(int iArray[][2]);
int A[4][2] = {{1, 2} , {3, 4} , { 5, 7} , {8, 1} };

[Code]...

View 1 Replies View Related

C++ :: Using Template Function Inside Class In Separate Function?

Mar 26, 2014

i want to use a class to print data stored as vector or array with different data types. i also want the print function two take more than one vector or array or combination of both so that they can be written to file as two columns. so i wrote the following class:

right now it has only one member function for printing two vectors. later i'll add additional functions as required.

note: there has to be template functions inside the class
i also want the object to be global so that i need not pass it as an argument to other calling functions

class printdata
{
public:
template<typename T1,typename T2>
void SaveData( vector<T1> &data1,vector<T2> &data2, std::string var)
{

[Code]....

then i want to call this template function in another ordinary function written in a seperate cpp file

these function declarations are put in a header file. so i need know whether i should put the declaration of the template function in the header to use the function in different functions

View 4 Replies View Related

C++ :: Calling Function By Sending Char Text Of Function Name

Feb 19, 2014

Is this possible?

int myfunc( int a, int b, char * c )
char a = "(int)myfunc()";
char b = "(int,int,char*)"
call(a, b, ...) // Function name and return type, params

I want to do function what registers forward what will get callback if the time is right. Basically then i dont need to edit and add extra functions into source files. I just have to include header and use register forward function. If there is anything close to this it would be perfect!

View 5 Replies View Related

C/C++ :: Using Template Function Inside A Class In Separate Function?

Mar 26, 2014

i want to use a class to print data stored as vector or array with different data types.

i also want the print function two take more than one vector or array or combination of both so that they can be written to file as two columns.so i wrote the following class:

right now it has only one member function for printing two vectors. later i'll add additional functions as required.

note: there has to be template functions inside the class / i also want the object to be global so that i need not pass it as an argument to other calling functions

class printdata {
public:
template<typename T1,typename T2>
void SaveData( vector<T1> &data1,vector<T2> &data2, std::string var){
std::ofstream myfile;
std::string filename;

[code].....

then i want to call this template function in another ordinary function written in a seperate cpp file these function declarations are put in a header file. so i need know whether i should put the declaration of the template function in the header to use the function in different functions.

View 1 Replies View Related

C/C++ :: How To Hook Function From Same Process And Get Address Of Caller Function

Apr 27, 2013

I need to do it to avoid calling a function of my process from injected code.

So would like to hook this function to check whether the call is from the current module or it is from an external module, then I compare the address of the instruction who did the call with the module address range.

View 1 Replies View Related

C++ :: Retrieving File Object From Function Then Pass To Another Function?

Jun 27, 2014

I would like to have 2 functions. (FYI, I haven't even tested these because I don't have a compiler on this PC, so don't know what they'll do. I'm also new to C++, self-teaching.)

My question is, I'm sure that oFile should be type object (of some sort), not int, but I'm not sure how to reference it correctly so that it passes from FileOpen to main to FileClose.

Code:
#include <iostream> //I/O
using namespace std;
#include <fstream> //files
using namespace ios;
int FileOpen(string fileName) {
ifstream oFile (fileName); //attempt to open file

[Code] ....

View 1 Replies View Related

C :: Function Name To Wrap Standard Strncpy Function

Nov 5, 2014

I need a function like strncpy; but, want to be sure the destination ends with a ASCII nul char.

So, I wonder what name is used by others in this case.

I have found strlcpy and it looks like a good name choice. [URL] ....

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved