C++ :: Find Voltage By Multiplying Resistance And Current Array By Using Function And Pointers
Nov 11, 2013
I am suppose to find voltage by multiplying a resistance array and a current array by using a function and pointers. This is what I have so far:
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <iomanip>
[Code] ....
View 1 Replies
ADVERTISEMENT
Sep 11, 2014
I have code the following but result is not ok.
int main()
{
int i,j,m;
m = 0;
[Code].....
View 3 Replies
View Related
Aug 31, 2014
I'm having issues with pointers and relationship operators in C.
I need to find a max and min value in a void function using pointers. max and min would work if they had values. mul works, because you can just do math operations with pointers.
There are 0 errors and warnings; but max and min are never going to work as is.
Clearly I'm missing something.
#include <stdio.h>
#include <stdlib.h>
void max(int *a, int *b, int *c, int *d, int *result);
void min(int *a, int *b, int *c, int *d, int *result);
void mul(int *a, int *b, int *c, int *d, int *result);
int main()
[Code]...
Your job will be to create a program that uses pointers. Your output must be done in the main function and the calculations MUST be done in the three functions. Therefore you MUST use pointers correctly.
You must declare and implement the following 3 functions. Below are the three prototypes that you must use in this program.
void max(int *a, int *b, int *c, int *d, int *result);
void min(int *a, int *b, int *c, int *d, int *result);
void mul(int *a, int *b, int *c, int *d, int *result);
The functions have the following meaning:
max
finds the max value of a,b,c,d and stores the largest value in result.
min
finds the min value of a,b,c,d and stores the largest value in result.
mul
multiplies a * b * c and divides by d. Stores that value in result.
Below is an example input/output. This input will be read in via the keyboard (use scanf).
input
output (note that user input is shown in bold)
1 2 3 4
Enter the 4 numbers: 1 2 3 4
The max is 4. The min is 1. (a * b * c) / d = 1
100 3 201 103
Enter the 4 numbers: 100 3 201 103
The max is 201. The min is 3. (a * b * c) / d = 585
Your output MUST match exactly the output below for the input from above. Your program must compile, failure to do so will result in 0 points. */
View 9 Replies
View Related
Apr 19, 2014
#include <iostream>
#include <cstdlib>
using namespace std;
[Code]....
I am trying to initialize int x[] = {10, 100, 1000, 10000} into a loop and give me four different numbers for something. I was trying to get creative and just do
myArr[j] = j * 10; with (int j = 1; j < 10000; j++) ,
But that doesn't work. It still gives me an output of 10 11 12... How to make an array punch through a loop and give me
10 Press any key to continue...
100 Press any key to continue...
1000 Press any key to continue...
10000 Press any key to continue....
I'm thinking I must set the for loop to < 10000.1 or < 10001 to output the final value in the array.
View 3 Replies
View Related
Nov 16, 2013
I have an array as such and need to multiply all the values of it by each other and put that as a variable.
//for example
int array1[100]
//assume i have already input the values of each element properly up to, say, element 4
//I need to now multiply all of those values together. I think I need the size of the array to control what it multiplies (I know how to find size) ....
View 4 Replies
View Related
Jan 29, 2015
I basically have some code that lets users register callbacks into a callback table at a specified index. There is one element in this table for each event that can trigger a callback. I basically do something like this:
In a header file
Code:
typedef struct _GMclient
{
GMcommunicator gcomm;
GMclient_callback callback_table[(int)MAX_CALLBACKS];
}GMclient;
typedef int (*GMclient_callback)(GMclient*, void*, void*);
Then I allow them to set the callback with a function that basically ends up doing this (in a .c file that includes the previous mentioned .h file):
Code:
void
GMclient_register_callback(GMclient *client,
GMclient_callback fxn,
int index)
[Code] ....
Then later when I need to invoke that callback, I pull it out of the table
Code: GMclient_callback *fxn = client->callback_table[CMD_INDEX];
However, I get compilation errors:
Code: src/gmanager_client.c:43:6:
error: a label can only be part of a statement and a declaration is not a statement...
View 4 Replies
View Related
Aug 4, 2013
How would I pass let say 2 array pointers to a function X , allocate memory for them in X , fill them with values and get them back in my main function without creating a structure.
example:
Code:
void X(int *a, int*b){
a= malloc ...
b = malloc ...
// fill a and b
return them back to the main function
}
void main(){
[Code]...
View 3 Replies
View Related
Apr 6, 2014
Ive recently got into function pointers, i find that they can be quite handy for making your program very 'dynamic'.
However, the syntax is very confusing for what i want to do
This is what i want to do
I want to hold function pointers inside an array, but this array is dynamically allocated ( malloc, realloc, etc )
This is the current syntax ive come up with, but i dont think it is correct
void ( **drawFunc ) ( void*, SDL_Surface* );
View 2 Replies
View Related
Feb 28, 2014
I'm trying to create an array of pointers to pointers which will point to array of pointers (to strings) I tried
Code:
int i;
char *string[]={
"my name is dave",
"we like to dance together",
"sunny day",
"hello",
[code]...
the app keeps crashing , I don't know how to make the array-elements to point to another array-elements..
View 4 Replies
View Related
Dec 13, 2013
I would like to know if this code is correct.
#include <iostream>
#include <string>
int say_one(const std::string &s) {
std::clog << s << ": One!
[Code] .....
View 7 Replies
View Related
Nov 21, 2014
I have a a group of text files that are used as input into a program. Another very similar program needs the same data in a different input format. I am writing a program that will read in each line of data and parse it. I have successfully written the program in main() such that it will read until the end of file. However, I am trying to re-write the program such that the algorithm is in an external function and will read one line at a time and then pass all of the character strings to the main program. The program will not compile and I am positive it has to do with an incorrect use of arrays in passing the variable "token". I am attaching a copy of the main program and the function.
#include <iostream>
#include <fstream>
#include <cstring>
#include <stdio.h>
void Line_Parse(std::ifstream&,std::ostream&,const char* token);
int main(int argc, const char * argv[]) {
[Code] .....
View 2 Replies
View Related
May 13, 2013
I'm trying to create an array of function pointers and then assign compartilbe functions to them, so I can just call *pf[0](xxx);
The functions are all of the type
void func01(unsigned char*, int, int)
how would I create an array of function pointers and assign the address of the functions to them? So I could call them like
ptrToFunction[i](charBuffer, 10, 20);
I've read a bit on line and I thought I could do it but so far I've failed.
It seems trivial and I feel I'm close but close isn't good enough.
I'd like to assign the fuction addresses like this:
for (int i=0; i<10; i++)
if (i==1)
ptrToFunction[i]=func01;
if (i==2)
ptrToFunction[i]=func02;
etc.
The actual logic is somewhat different than this but this close.
View 4 Replies
View Related
May 12, 2013
The premise of this assignment is to create a menu driven, array of functions calculator. This is the code I have thus far (I haven't finished all of my comments yet, I've been to focused on clearing errors).
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/*prototypes*/
void sum (int a, int b);
void dif (int a, int b);
void pro (int a, int b);
void quo (int a, int b);
void printMenu();
[Code] .....
I am using Visual Studio as a compiler, and I have the following errors:
error C2144: syntax error : 'int' should be preceded by ')'
error C2660: 'sum' : function does not take 0 arguments
error C2059: syntax error : ')'
error C2144: syntax error : 'int' should be preceded by ')'
[Code] .....
I can only assume that I am making simple mistakes.
View 4 Replies
View Related
May 24, 2013
I am having following pointer variable declaration
Code: Static double (*funcs[]) (double) = { sin,cos,tan,asin,acos};
Here funcs is an array of pointers to functions which take double as input and gives double as output with static as storage type am I right.
View 2 Replies
View Related
Oct 26, 2013
I am on a project. I have a laptop and It doesn't have a COM port. So what I would like to do is to get a usb to RS232 cable and write a code so to output voltages on usb and measure it on the RS-232 end. Can I vary the output voltage to my needs?
View 2 Replies
View Related
Mar 6, 2015
I have a Voltage Range from -10V up to +10V, which I transform to a voltage Range 0V to 5V, with the schematic i've attached, so I can use the A/D converter of my ATMEGA32 processor.
Now I'd like to write the value of the Input Voltage (which moves in the Range of -10V to + 10V) on the serial port, but i don't know how i should calculate this factor. At the moment, I can only write the value of the A/D Converter Input on the serial, but this is only 0V to 5V...
View 2 Replies
View Related
Oct 20, 2014
My code seems to find the mode of the array I input sometimes. Sometimes it gives me the wrong number or multiple numbers. It just all depends on what is number is inputted into the array. I don't know what the problem is. I tried looking online and editing many times and can't find the answer. Maybe I'm overlooking something or doing something wrong. Here's my code.
#include <stdio.h>
void readArray(int arr[], int length)
{
printf("Enter data:
");
[Code].....
Maximum: 15
Mode: 2
As you can see the mode is clearly not 2 and I do not know why.
View 8 Replies
View Related
Jun 20, 2012
find the average of 10 numbers to an array using function .the array should be controlled by while loop?
#include <iostream.h>
float sum(float x[],int size);
main() {
float a[10];
int n=10;
[Code] .....
View 2 Replies
View Related
Jun 4, 2012
I have a program (below)
int main() {
int x = 1;
char *y = (char *) &x;
printf("%d
", *y);
}
The output will be either "0" or "1" depending on the architecture of the system.When I executed on my system I got output as "1", now what is the architecture of my system is it 32 bit or 64 bit?
View 8 Replies
View Related
Mar 12, 2014
I am so close to finishing this program. It will find the median of an array of 5 values. I have one last error that I cannot seem to get to go away. Here's the code:
#include <algorithm>
#include <functional>
#include <array>
#include <iostream>
using namespace std;
int main() {
int integer1, integer2, integer3, integer4, integer5;
[Code] .....
The error states: "IntelliSense: no instance of overloaded function "std::nth_element" matches the argument list, argument types are: (std::_Array_iterator, std::_Array_iterator, unsigned int, std::_Array_iterator)
View 1 Replies
View Related
Jul 13, 2014
I am trying to find the distance between two void pointers, so I can follow this distance to a certain pointer in a vector when given only the previous element in that vector.
int distance = (char*) prev - (char*) first;
next = (char*) cv->elems + cv->elemsz + distance;
Basically, prev and first are void pointers. I am trying to cast them into a char, subtract the first element in the vector from the previous one, and then use this distance to determine what the next element in the vector is. However, it is not working. I am not sure how to do this. To complicate matters, prev is a const void *.
View 7 Replies
View Related
Jan 14, 2015
I am trying to use to save the current date and time into a char array using this code:
char current_time(char *date){
time_t result = time(NULL);
date = ctime(&result);
return *date;
}
main{
[Code]...
now when I output the date char array into a txt file I only get gibberish.
View 6 Replies
View Related
Feb 23, 2014
I'm very new to C++ so I've been trying to run through some code examples to begin to learn basic structures and syntax, but I've recently run into a problem using examples from the 7th ed. of Sams Teach Yourself C++. I'm using the code provided within one of the examples that allows you to specify and multiply two variables, but when I compile and run the executable the final output seems to only show the first variable and b/c of this the multiplication operation does not work.
Here is a my example code:
Code:
#include <iostream>
using namespace std;
int main() {
cout << "This program will multiply two numbers" << endl;
[Code] ....
View 3 Replies
View Related
Jun 3, 2013
Trying to multiply to matrixes using the following algorithm,
Code:
ABrec(A,B)
n=A.rows; //n must be multiple of 2
C is a new n*n matrix.
if(n==1)
C[0][0]=A[0][0]*B[0][0];
[Code] ....
but the code doesn't work !!!
View 4 Replies
View Related
May 1, 2014
we have to make a Invoice class which has a function called computeInvoiceAmount() which multiplies the price and the quantitiy which are private member of the class.
double computeInvoiceAmount(){
return quantity * pricePerItem;
}
This is my function, but if i compile it i get the following error:
"Invoice.cpp:53:11: error: "quantity" was not declared in this scope" and "Invoice.cpp:53:22: error: "pricePerItem" was not declared in this scope"
I tried it with the get functions but i get the same error.
Full code is here: [URL]
View 1 Replies
View Related
May 14, 2012
Two different matrices will be read from text files (input1.txt, input2.txt) and they will be stored in two dimensional arrays (matrix1, matrix2) and one dimensional arrays (array1, array2). Our aim is to obtain the matrix multiplication using two dimensional and one dimensional arrays.
You are asked to write the main and the following functions. The definitions of the functions are given in the skeleton code.
int read_file(ifstream& in_file, int &row, int &col, double *array, double **matrix)
int write_file(ofstream& out_file, int row, int col, double **matrix)
void print_matrix(double **matrix, int row, int col)
void print_array(double *array, int row, int col)
void multip(double **matrix1, double **matrix2, double **result, int k, int m, int n)
void multip_array(double *array1, double *array2, double *array_result, int k, int m, int n)
You are going to obtain the input and output files as command line arguments
input1.txt :
3 4
2 3 4 5
1 3 5 4
0 4 4 7
The first element in the first line represents the number of rows (3) and the second element represents the number of columns (4) of the matrix (the result file will have the same format).
likewise;
input2.txt :
4 5
1 2 3 4 5
2 9 43 44 21
32 32 32 43 54
1 3 3 4 5
thats my homework and here is the code i wrote from the sceleton code they gave me :
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int read_file(ifstream& in_file, int &row, int &col,/* double *array,*/ double **matrix)
[Code] ....
I didn't understand the array part but even when i exclude the array part i get the program has stopped working message. My os is windows7 ultimate with mingw installed and i compile the program using g++ command in cmd with the arguments input.txt input2.txt resultt.txt
View 1 Replies
View Related