C :: How To Set Up A Function Using Arrays
Apr 16, 2013
how to make the functions for b, c, d. if possible running through on how to would be more beneficial than just giving me the answer.
Global warming. As part of a global warming analysis, a research facility tracks outdoor temperatures at the North Pole once a day, at noon, for a year. At the end of each month, these temperatures are entered into the computer and processed. The operator will enter 28, 29, 30, or 31 data items, depending on the month.
You may use 500 as a sentinel value after the last temperature, since that is lower than absolute 0. Your main program should call the read_temps(), hot_days(), and print_temps() functions described here:
(b) Write a function, read_temps(), that has one parameter, an array called temps, in which to store the temperatures. Read the real data values for one month and store them into the slots of an array. Return the actual number of temperatures read as the result of the function.
(c) Write a function, hot_days(), that has two parameters: the number of temperatures for the current month and an array in which the temperatures are stored. Search through the temperature array and count all the days on which the noon temperature exceeds 32F. Return this count.
(d) Write a function, print_temps(), with the same two parameters plus the count of hot days. Print a neat table of temperatures. At the same time, calculate the average temperature for the month and print it at the end of the table, followed by the number of hot days.
View 1 Replies
ADVERTISEMENT
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
Feb 25, 2015
I am trying to use pointers to arrays in my function.
I can get the pointers to work outside of a function but I just can't figure out how to make them work in my function.jwhittle58, on 25 February 2015 - 06:06 PM, said:
I am trying to use pointers to arrays in my function. I can get the pointers to work outside of a function but I just can't figure out how to make them work in my function.
View 8 Replies
View Related
Oct 23, 2013
I'm just wondering, why you have to set the length of the inner arrays declaring a function. In which moment does the code needs to be sure about the length of the inner arrays accessing an cell?
I came up with this question realizing the elements of the outer array beeing pointers to the first value of each inner array. Therefore I can access e.g. the first first element of the second inner array like this:
**(arr + 1) ...regardless of the length of any array to my mind.
parallel post: [URL]...
View 6 Replies
View Related
Nov 8, 2014
#include <iostream>
#include <cassert>
#include <vector>
using namespace std;
vector<int> flatten(int a[100][200]) {
vector<int> v;
for (int i = 0; i < 100; ++i) {
[Code]...
I made a function for two dimensional arrays with vector, but I don't know how to make the test code for it.
View 4 Replies
View Related
Mar 25, 2015
In this assignment, you are required to write a function called largest square. Your function should take a 2 dimensional array, 2 integers which represent the number of rows and columns in the array, and prints out a 2 X 2 array which represents the largest square in the array. The largest square means the square for which the sum of its elements is the greatest in the array. Submit your function in a file called largestSquare.c
Example: Given the array 1 2 3 4
5 6 7 8
9 10 11 12 the output should be 7 8
11 12
Example 2: Given the array 8 2 6
3 7 3
6 1 1 the output should be 8 2
3 7
The prototype of your function is void largestSquare(int[rows][columns], int rows, int columns).
Am I anywhere close with what I've started?
//
// main.c
// largestsquare
//
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char * argv[]) {
int rows, columns;
[Code] ...
View 5 Replies
View Related
Oct 15, 2014
I'm trying to write a program to test if a string is palindromic using only pointers
Code:
#include <stdio.h>
#include <string.h>
void revstr(char* str)
}
[code]....
I need to change the arrays in the function int palin to pointers.
View 4 Replies
View Related
Feb 19, 2013
There is one question :
Considerint A[10]={ ....................}; // already filled
int B[10]={ ....................}; // already filled
Using PIONTER NOTATION ONLY, write a function that receives two arrays of integers like A and B above. The function should swap the values in A and B. You may NOT use array notation [ ]. Also, you have to use pointers to move among array cells. Note: Both arrays are of the same size, and size should be variable in the function.
View 3 Replies
View Related
May 16, 2013
In this program I am attempting to allow a user to input three different authors and then input three books they have written as well as the price. I am struggling with calling the functions and am not sure what to do.
#include <iostream>
#include <string>
using namespace std;
struct BookInfo{
string bookTitle;
double price;
[Code] ....
View 3 Replies
View Related
Mar 9, 2013
I currently have multiple functions that use globally declared arrays in my code.
I want to turn them so that arrays are no longer globally declared, but instead are passed by references to the function.
And I have a function caller inside main, and other functions are called within the function.
View 3 Replies
View Related
Mar 16, 2013
I am working on incorporating a function in to an already existing piece of code, I have incorporated the function fine as far as I am aware.
The problem I have is that I am trying to pass two int arrays to the function, so that i can manipulate and compare them "the values will be changed the originals cannot be changed"
I am having trouble pulling the information out of the already created array, I am able to pass the pointer reference for the single value which is not exactly what i want "best_prog".
My function is below I have commented the memcpy parts and also the majority of the code isn't there cause it is not needed to see make the copy work.
int edit_distance(int index) {
struct prog *progp = &population[best_prog];
/* The struct of best prog not sure if i need one for the other prog I am trying to compare it with the one below doesn't work as intended.*/
//struct prog *progp = &population[];
int editdistance = 0, ar1 = 0, ar2 = 0, a = 0, b = 0, j = 0, x = 0;
[code].....
View 12 Replies
View Related
Feb 25, 2015
I wrote this code for a homework assignment, everything runs fine but the function void percent_votes (line 66) isn't calculating properly, it outputs 0.00 for each value. I have tried everything I can think of to try and make it work.
Here is the assignment: Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate's name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election.
Here is the code I have written:
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
[Code].....
View 4 Replies
View Related
Mar 17, 2013
I have a matrix that contains zero and nonzero elements. I want to do a function that return 3 arrays.
The first one is for nonzero elements the second array contains the corresponding row numbers of each nonzero element the third array contains the corresponding column numbers of each nonzero element.
View 11 Replies
View Related
Nov 10, 2014
I have a .txt file that I need to input into two parallel arrays. The first array needs to be on dimension and the second needs to be two dimensions.
This is a sample from the .txt file:
Australia62.762.163.359.7
Austria052.853.154.6
Belgium30.430.327.525.3
Canada61.356.257.754.5
Chile026.425.431.1
CzechRepublic038.327.325.2
Denmark65.067.162.355.0
Estonia51.732.929.834.3
Finland55.242.942.143.3
France35.728.330.228.8
Germany56.447.242.646.6
Greece30.326.925.013.1
Hungary032.521.818.6
Iceland068.271.666.0
this is what I have for code so far:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int SIZE = 40;
const int COLUMN = 5;
void getData(ifstream& inf, string n[], double tstData[][COLUMN], int count);
[Code] .....
when I compile and run the code and have it display it does not read the first item into the 1-d array, instead it appears to read the 4th number from the left into the 1-d array and then into the second spot in the 2-d array, then again in its proper place and finally it has this number repeating through the rest of the arrays:
-92559631349317830000000000000000000000000000000000000000000.00 followed by the number 59.7 from the .txt and the long number again.
View 10 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
Dec 23, 2012
I know how to use functions pointers in C and C++ and I know if you have something like
char buf[] = {
0x48, 0xb8, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x48, 0xbf, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0f, 0x05
};
((void (*) (void))buf)();
That this will execute those binary instructions in hexadecimal notation BUT WHY? I don't get why that works since that's an array of data not a function?
View 7 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
Nov 4, 2013
I need to write a function that will merge the content of two sorted arrays of type double values. The function should not assume that both its input parameter arrays are the same length.
Here is my program so far - I know there is alot of errors and mistakes:
Code:
#include<stdio.h>
void merge(int firstArray[],int secondArray[],int size) {
int mergedArray[size],i=0,j=0,k=0;
while(i<size||j<size) {
if(i==size) {
[Code]...
View 2 Replies
View Related
Feb 6, 2014
I define "Comwords" as a string, but apparently it takes the members as chars, then I can't set strings in a structure equal to the chars.
I see to also be having unknown problems with the ComMAL array and loading it values into another element of the same structure.
How to correct this? I was thinking of casting char elements as strings, but could find no reference in my library book regarding how to do that (lots on casting int's a doubles...)
Code:
int _tmain(int argc, _TCHAR* argv[]) {
int comm = 10;
int targ = 5;
int death;
struct AI_WORDS
[Code]....
View 2 Replies
View Related
Jul 1, 2014
Using a for loop, construct two 100 element arrays, x and y, such that element i of x stores the value sin(2*pi*i/100)) and the corresponding element of y stores cos((2*pi*i/100)). Print the values stored in the elements of x and y as you calculate them.
I have attempted to solve it but I'm not sure why the value 0 is only being printed, maybe I haven't assigned sin(2i/100)) and cos((2i/100)) to the arrays properly?
Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main () {
[Code] .....
View 3 Replies
View Related
Dec 17, 2014
int arr[4][5];
for (int(&row)[5] : arr){
for (int &column : row){
} }
Why do we name it row instead column?
int arr[row][column]
Wouldn't this be like
int arr[4][5];
for (int(&column)[5] : arr){
for (int &row: column){
}
It just seems funny to me because we use row[5] which should be 4 if we meant row? Or did I read it wrong in C++ prime !?
View 2 Replies
View Related
Apr 15, 2013
I'm trying to write a function that takes a 32bit address and a data to store at this address.
I'm wanting to take the 32 bit memory address eg 0x12345678 and split it
into 4 x 2 bytes
12, 34, 56, 78
then each of the 4 entries is at most a 256 entry array.eg
FF, FF, FF, FF
So in this example, 0x12 points to 0x34 in the second array, which points to 0x56 in the third array, which finally points to 0x78 in the last array. This last array holds the actual data.
After successfully doing 0x12345678, say I might get a read for 0x1234AABB. So, the first and second pointers already exist, but I then have to create and write to dynamically created arrays.
The arrays need to have all entries set to NULL so that i know whether to follow the pointers to overwrite a previously entered value or create new arrays and pointers.
It all looks good and simple in the pseudo code I've written up but I'm having trouble coding it. I'm currently trying to deal with the first entry case, ie all array elements are NULL, but I'm getting confused with the pointers and creation of new arrays.
void cpu::store(unsigned int mem_add,unsigned int mem_val) {
int first = (mem_address&4278190080)>>24;
int second = (mem_address&16711680)>>16;
int third = (mem_address&65280)>>8;
int fourth= (mem_address&255);
[Code] .....
A1 has been declared as
int* A1[256] ;
View 3 Replies
View Related
Jul 24, 2013
like for example if
Num1[0]=2
Num2[0]=3
this is not working x= Num1[0] + Num2[0];
is there any other way ?
View 11 Replies
View Related
Nov 13, 2013
Basically on this assignment I must write program that inputs two positive integers of at most 100 digits and outputs the sum of the numbers into an array. The two positive numbers must come from different arrays and the sum has to be stored into another array.
View 2 Replies
View Related
Jul 23, 2013
For example if we have
array1[5]= {1,2,3,4,5}
and
array2[5]={2,3,4,0,7)
how do you sum them up as 12345 + 23407 . And when i say sum I mean normal mathematical sum.
here is my code:
int main () {
string str1;
string str2;
[Code].....
View 4 Replies
View Related
Feb 12, 2014
Compiled on turbocpp 4.5.....error is that the final merged array is much bigger with garbage values...
Code:
//cpp program to concatenate 2 arrays
#include<iostream.h>
#include<conio.h>
//the class
class array
[Code] .....
View 6 Replies
View Related