C++ :: Function That Accepts Integer And Returns A String?
May 5, 2014
How to go about making a function that accepts an integer and returns a string with any one of 5 strings containing the name of the object. For example object number 3 might be "Pen". Object 4 might be "Paper".
Write a template that accepts an argument and returns its absolute value. The absolute entered by the user, then return the total. The argument sent into the function should be the number of values the function is to read. Test the template in a simple driver program that sends values of various types as arguments and displays the results.
#include <iostream> using namespace std; template <class integertemplate> integertemplate totalint (integertemplate integers) { cout << "How many integer values do you wish to total? "; cin >> integers;
Is it possible to create a function that can both return and display a value. I was trying to make a program that computes and prints terms of the Fibonacci series using a recursive function.
I have an assignment which requires me to do the following:
Required to write a function that finds an integer in an array and returns its corresponding index. The function must be called findNumber. It must have FOUR parameters:
- The first parameter is the array to be searched - The second parameter is the integer to be found within the array - The third parameter is the size of the array - The fourth parameter is an integer that indicates whether the array is sorted. A value of 1 means the array is sorted; a value of zero means the array is not sorted.
Since a function can only return one value(To return the position of a required integer in an array in this instance) I have tried to make use of pointers to try and return a value stating whether the array is sorted or not.This is my code : (It compiles perfectly but it does not produce any outputs)
Code:
#include <stdio.h> #define SIZE 10 size_t findNumber(int *sort, const int array[],int key,size_t size); int main(void){ int a[SIZE]; size_t x;
You pros are once newbies like us. Hoped you might take a little time sharing your expertise. Got freaked out when our teacher gave us this activity, where she haven't taught this to us yet. So this is the activity (LOOPING) :
Write a program that accepts a positive integer. The program should be the same from the given output. Use do while to allow the user to continue or not.
OUTPUT must be:
n = 5 0 1==0 2==1==0 3==2==1==0 4==3==2==1==0 5==4==3==2==1==0
if n = 6 0 1==0 2==1==0 3==2==1==0 4==3==2==1==0 5==4==3==2==1==0 6==5==4==3==2==1==0
I was trying to code a program that accepts your first name and then last name and then displays it through another function. I have checked that the assignments are between similar type of variables and pointers, but I don't seem to get it right.
When first input is taken and then second one, the first one's value changes to same as the second. E.G if first name is L and second name is S and after second input both variables, first and sec, become equal to S. Why?
Write a function that accepts an array of integers and its size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to element 1 of the new array, element 1 of the argument array should be copied to element 2 of the new array, and so forth.
The function should return a pointer to the new array. Use ONLY pointer parameters instead of arrays in both functions; use pointers (not subscripts) to move through elements of both arrays. Before calling the function, display your original array. When the function call is completed, display the new array.
Here is what i got so far:
#include <iostream> using namespace std; int *shifted (int * , int); const int SIZE = 10; int main () { int array_size [30];
write a function accepts two arguments, an array of integers and a number indicating the number of elements in the array. the function should recursively calculate the sum of all the numbers in the array. Demonatrate the use of the functions in a program that asks the users to enter an array of numbers and prints it sum
i had done this but it wont work
#include <iostream> #include <conio.h> #include <iomanip> using namespace std;
I have a function that returns a char*. No problem. But I need to concatenate another array with the results of this function. I'm getting a segmentation error.
Code:
//this next line outputs correctly so I know my function is working fprintf(stdout, "%s ", get_filename(selection)); char* temp;
For a Homework i need to make some kind of Minesweeper but i have one Probleme one of my functions always return teh same and i cannot fin out why here is the code:
bool setzen(int x, int y){ if(feld[x][y]!=3){ return mine=false; }
[Code]....
Thats the Part where Everything happens but the Function "bool setzen" always returns false and i dont know why.
I am writing a program with a function that includes a long loop. I need this function to return a value when each loop is done, to send this value to output, in order to follow the progression. But I don't know how to do it in easy way. The function is like follow:
int goC(){ ... // some local value definition for(int i = 0; i < 1000; i++){ ... // a lot of calculations done here return i; // -> return the value after each loop is done } }
Here it only returns one value, i = 0. Clearly it's wrong.
I'm writing a function that is to return the price of something.. What would be the most appropriate return type for this? Like in Java it would be a double...
I need to create a function that takes as an input a variable number of scalars and returns the biggest one. Just like std::max() does for 2 elements, but I need it for an undefined number of elements, can be 2, or 5, or 10 etc.. How to approach this?
What I need it for: I'm working with a bunch of vectors, maps, etc. and I need to find out which has the most elements. So I was thinking that I should end up with something like
int biggest = max(vector1.size(), vector2.size(), map1.size(), ...);
I have a big problem with a function, I wrote this function in order to get a line from an HTML (Or XML) file, until a specified delimiter (not always or ... It can be everything..)
Here is my code :
public static String GetLineUntilChar( String url , char delimiter , String postData, String referer, String cookie ) { try { Uri uri = new Uri("http://127.0.0.1//site.html"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.ContentType = "application/x-www-form-urlencoded"; if (!String.IsNullOrEmpty(referer)) request.Referer = referer;
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.
Write a function that computes and returns the score for a permutation, i.e. the number of reversals required to make arr[0] == 1. HAVE TO USE FOLLOWING FORMAT:
Code: // POST: Returns the number of reversals needed to make arr[0] == 1 // if the reversal game were played on arr // Note: If arr[0] == 1 initially, then score(arr, n) returns 0 AND this is what i could muster; [code]....