C :: How To Create Functions With Arrays
Jun 12, 2013
how to create functions with arrays :/
You have to write a single C program that creates a one dimensional array of size MAX(to be declared as a declarative constant using directive #define MAX 10), initializes its elements with a given value using the function InitArray, then populate the array with some random numbers between 1 and MAX inclusive, and finally search the array for certain keys.
The structure for this C program is as follows:
int main() {
//array A to be locally declared here
int
size = MAX;
}
[code]....
View 3 Replies
ADVERTISEMENT
Sep 23, 2014
I have read about it in my book and also on this website but i still have things uncleared....
View 11 Replies
View Related
Nov 4, 2013
i have a program that works, but now I am trying to get function1() to work. What it has to do is bring in the array and populate it with random letters. I don't know much about functions.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define maxrow 20 //defines maxrow as a constant of 20
#define maxcol 30 //defines maxcol as a constant of 30
}
[code]....
View 2 Replies
View Related
May 21, 2014
I'm truing to write a function that gets an array of arrays, and returns an array. I placed the code I'm using below, but I'm getting all kinds of errors. How is the right way to do this?
static void Main(string[] args) {
int[] draw1 = new int[] { 5, 8, 3 };
int[] draw2 = new int[] { 3, 6, 8 };
int[] draw3 = new int[] { 6, 7, 9 };
int[] draw4 = new int[] { 5, 6, 0 };
[Code] .....
View 4 Replies
View Related
Mar 31, 2015
I can write code that can sort arrays with Bubble, Selection and Insertion algorithms but I'm not sure how to have them be called and return a value 3 different times with 3 different sizes. For example, I need it to return 10, 100 and 1000 but I'm stuck.
#include <stdio.h>
void selectionSort (int list[], int last);
int main()
[Code].....
View 14 Replies
View Related
Sep 16, 2014
I am new with C programming and trying to learn how to create functions such as floats. But for some reason when I try to compile this program the compiler will tell me Weight() is not a function.
Code:
#include <stdio.h>
float Weight(float Mass, float g)
{
float Weight = 0;
g = 9.81;
[Code] ....
View 3 Replies
View Related
Apr 12, 2013
I'm trying to code one of the problems but it really is hard to catch errors for a novice like me at first.
I have to Write a single C function for computing the histogram of a list of nonnegative integers into 4 bins.
The main() function first initializes a positive integer array called List of size N, takes 3 inputs from the user A, B, C (assume 0 < A < B < C), and declares a second integer array Bin[4].
The doBinning function should count the number of elements of List in the interval [0, A) and store it in Bin[0], count of [A, B) in Bin[1], count of elements in [B,C) in Bin[2], and the number of elements >= C in Bin[3]
Code:
#include <stdio.h>
#define N 10
#define M 4
int *doBinning (int source[], int dest[], int a, int b, int c);
int main (){
[Code] ....
Somehow I keep getting error from ptr = doBinning(List[], Bins[]. What am I doing wrong? Code might contain some errors.
View 3 Replies
View Related
Jan 17, 2014
the book I learn from gave a task to write a program which gets a matrix , and we have to write a function that switches 2 columns or rows the user inputs .as far as I know a function can not change variables in the main function without using pointers .so , theoretically, can a function described here can be written without using pointers ? as far as I tried - it can not.
View 9 Replies
View Related
Sep 21, 2013
I wrote a fuction in C with the prototype 'void raisePowerOf2(int array[],int pow);'
If someone want to find the value of 2^456 ,just have to invoke this function 456 as the value for pow and int array with 2 elements :1 & -1 as the argument for the array.(There I used -1 to denote the end of the array.)
But it seems that this function doesn't give the exact answer
And I tried this from java also,with the same implementation.It produced the answer precisely .
I tried for hours, but unable to detect reasons why this code blok in C doesn't work properly
This is the code in c
Code:
#include<stdio.h>
void raisePowerOf2(int array[],int pow);
int main(){
int a[2]={1,-1};
raisePowerOf2(a,5);
return 0; }
void raisePowerOf2(int array[],int pow){
[Code]...
This is the code in java....
Code:
public class NewClass4 {
void raisePowerOf2(int array[],int pow){
final int len=array.length;
int store[]=new int[len+1];
int qtnt=0;
for(int i=len-1;i>=0;i--){
store[i+1]=(array[i]*2)%10+qtnt;
qtnt=(array[i]*2)/10;
[Code]...
View 7 Replies
View Related
Oct 23, 2013
i'm facing some problems with the array, as I have my .h and .cpp files so do i declare them as per norm of how we usually declare a function?
pointtwod.h
class PointTwoD {
private:
int xcord,ycord;
float civIndex;
LocationData locationdata;
[Code] ....
when i compile the error message i get was even when i i put in int xord[]; in my PointTwoD.h file:
PointTwoDImp.cpp:99:6: error: prototype for 'void PointTwoD::storedata(int*,int*,float*) does not match any in class 'PointTwoD'
PointTwoD.h:48:8: error: candidate is: void PointTwoD::storedata(int, int, float)
PointTwoDImp.cpp: 135:22: error: 'xord' was not declared in this scope
PointTwoDImp.cpp: 135:27: expected primary-expression before ']' token
PointTwoDImp.cpp: 135:30: error: 'yord' was not declared in this scope
PointTwoDImp.cpp: 135:35: expected primary-expression before ']' token
PointTwoDImp.cpp: 135:38: error: 'civ' was not declared in this scope
PointTwoDImp.cpp: 135:42: expected primary-expression before ']' token
View 1 Replies
View Related
Nov 8, 2013
I want to write a code that gets three values from the user and puts them into three arrays. When the user enters -999, I want to print out a chart showing all the values they put in. This is what I have so far but it wont build. It tells me std::string is requested, but I'm not sure where to put it, and printArrays is declared void. How can I fix this?
#include <iostream>
#include <string>
using namespace std;
const int ARSIZE = 400;
void printArrays (string reportTitle, int levelsArray[], int scoresArray[], int starsArray[], int i);
[Code] ....
View 2 Replies
View Related
Oct 31, 2013
Description: Use functions and structures to simulate storage in a warehouse
*/
#include <cstdlib>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
struct Bin {std::string name; int Quantity;}; //create a structure for "Bin"
[code].....
I keep getting a linker error on every function. what am I doing wrong?
View 2 Replies
View Related
Sep 21, 2013
I wrote a fuction in C with the prototype
'void raisePowerOf2(int array[],int pow);'
If someone want to find the value of 2^456 ,just have to invoke this function 456 as the value for pow and int array with 2 elements :1 & -1 as the argument for the array.(There I used -1 to denote the end of the array.)
But it seems that this function doesn't give the exact answer
And I tried this from java also,with the same implementation.It produced the answer precisely .
I tried for hours, but unable to detect reasons why this code blok in C doesn't work properly .
This is the code in c
#include<stdio.h>
void raisePowerOf2(int array[],int pow);
int main(){
int a[2]={1,-1};
raisePowerOf2(a,5);
return 0;
} void raisePowerOf2(int array[],int pow){
[Code] ....
View 5 Replies
View Related
Mar 1, 2013
I want to create two threads which will be calling even and odd functions where even function should print even number and odd function should print odd number.Can it be possible with condition variable? What is the code in both the cases i.e. two separate function and with condition variable.
View 6 Replies
View Related
Nov 4, 2014
I'm working on a list of functions that can create a unique ID for a computer. Here's what i have so far:
GetAdapterInfo();
RegOpenKeyEx();
GetVolumeInformation():
CoCreateGUID();
Are there any other functions that do this?
View 1 Replies
View Related
Nov 16, 2013
I'm having trouble with passing a character array between functions of the same class. I have a function, buildGraph, that calls function getNextLine. The getNextLine essentially just retrieves the next line of an input file and stores it into a "char line[80]". However when I try to use "line" in my buildGraph function, it has nothing in it.
Here's my code:
Class
#define NUMNODES 10
using namespace std;
#pragma once
class Prog3Graph
[Code] ....
View 4 Replies
View Related
Mar 11, 2014
we were given this code:
// Music Shuffle Program
// This program takes an array of strings and randomly permutes their order.
// This allows us to generate new song shuffles.
#include <iostream>
[Code]....
or are they referring to something else?
View 4 Replies
View Related
Nov 3, 2014
I wanted to do this: Accept a line of input from user and save it to an array1 and copy its contents to other array in a set of arrays and then input another line to array1 and then copy it to next array in the same set and so on.... I know it is confusing but I can put it like that I want to create an array of arrays (Set of arrays). How can I do so?
I wrote a code to input the line in an array and tried to copy it another array of pointers, but pointers are just addresses so the same adress is copied again and again so, all the pointers of the array point to one address only. The code doesn't print anything when I try to print all the lines that were saved.
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAXLEN 1000
#define MAXSIZE 100
int getline(char [], int );
void storage(char line[]);
[Code] .....
View 2 Replies
View Related
Mar 15, 2013
I currently have globally declared arrays, which are accessed by multiple functions. I want to turn the program so that the arrays are no longer globally declared, but are passed to functions by reference.
I have one problem with passing the arrays: I found that, through debugging, I HAVE TO resize the array when I pass it by reference. For instance, I was using int a[10] when it was globally declared, when it is passed by reference with size 10, it does not work, instead it should be higher than 10 (certain number). Why is this happening? I do not get it...
View 6 Replies
View Related
Jun 21, 2013
Passing and returning character and integer arrays with functions using simple programs...use pointers if necessary
View 1 Replies
View Related
Feb 21, 2015
Create a payroll program to store and calculate the payroll for a small company with a maximum of 20 employees.
Program parameters are as follows:
1. Create a menu with the following options (use a do-while loop):
A or a to add employee info
D or d to display employee info
T or t to display total payroll
S or s to display the info of all employees
Z or z to exit program
The information for each employee is: employee number, hours worked, pay rate per hour, tax deduction.
2. Use an array of doubles to store employee information.
3. Menu option A or a: ask the user for the employee information one value at . a time and store it in the array.
Please enter employee number: 2190
Please enter hours worked: 32.50
Please enter pay rate: 9.25
Please enter tax rate deduction: 5.50
4. Option D or d: ask the user for an employee number as integer and display . the information for the corresponding employee (cast the employee number
. in the array to integer and then compare). If employee number does not . match, output a msg. indicating "no such employee". If the employee number . is a match, output all the employee information stored in addition to the . calculated deduction and salary.
Output sample:
Info for employee number: 2190
Hours worked: 32.50
Pay rate: $ 9.25
Tax deduction: 5.50 %
Total pay: $ 284.89
5. Option T or t: calculate and output the sum of the total pay of all
. employees.
6. Option S or s: display the information for all employees in the same
. format as in option B.
7. Option Z or z: exit the program.
#include <stdio.h>
#define MAX [20]
int main(void) {
int i;
for (i=0;i<=20;i++) {
char MenuOption=0;
int EmployeeNumber;
[Code] .....
View 1 Replies
View Related
Nov 7, 2014
I am working on a number of utility functions for two dimensional arrays of integers, or matrices. However I am having a problem with segmentation faults, most likely due to errors in using malloc in functions like copyMatrix.
Code:
matrix_utils.h~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//This function checks if two matrices are equal
int isEqual(int **A, int **B, int n);
//This function returns one row of a matrix
int * getRow(int **A, int i, int n);
//This function returns one column of a matrix
int * getCol(int **A, int j, int n);
[Code] ....
View 2 Replies
View Related
Mar 6, 2015
I have seen functions that declare arrays in the function input even thou the arrays is already declared in main. Why do you do this?
For example:
int ova(int antal, char glosorSv[][MAX], char glosorEn[][MAX])
int main(void)
char glosorSv[][MAX]
char glosorEn[][MAX]
View 2 Replies
View Related
Apr 23, 2014
I cant get with part of it is wrong, i want to sum every row, too.
// Color Number.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<conio.h>
#include<iostream>
[Code].....
View 1 Replies
View Related
Jun 25, 2013
This program needs to display a vertical graph of asterisks showing production for each plant in the company ...
Here is what I have so far:
***********************************
This program will read data and
display a vertical graph showing
productivity for each plant.
Reference Display 7.8 pg. 401-3
***********************************
*/
#include <iostream>
[Code].....
View 1 Replies
View Related
Feb 9, 2014
I'm trying to create a function that uses dynamic allocated arrays instead of vectors because I want to see how they work. Basically, this function asks the user to input how many people they are going to enter followed by their name; then, they enter how many of these people want to register for an ID followed by their phone #.
For example:
"How many customers will you like to enter? " 3 //user inputs 3
Bob Allen //user input
Ellen Michaels //user input
Jane Andrews //user input
[Code].....
View 1 Replies
View Related