question from chapter 11, qn 8 modern C programming by king
Write the following function: Code: int *find_largest(int a[], int n); When passed an array a of length n, the function will return a pointer to the array's largest element
Code:
#include <stdio.h>
int *find_largest(int a[], int n)
{
int i, x;
x = 0;
[Code].....
have traced the code line by line and it prints correctly up to line 31. However, when the program exits (line 35) , it goes to some other screen with very complex code and my output disappears.
Just to clarify: If I just run the code as is, there is no output. However, when I trace the code line by line, the output appears, but then disappears as the program exits My input was 1 2 3 4 5 6
I have a program where I roll a die X number of times and need to print how many times it lands on each side. I tried to create an array in the class aDie that increments each time the corresponding number is rolled but when I go to call and print it in the main my out put is 0. I just picked how many times it landed on the side 4 just to see if it works and it doesn't.
#define ADIE_H #include <iostream> #include <vector> #include <cstdlib> #include <ctime> using namespace std; class aDie {
i have been fiddling with pointers but I don't understand how the proper syntax is written when I want to acces an element of an array through a pointer to a pointer...The code is all mostly just random bs for learning purposes. I marked the problem "// THIS LINE"
How would I go about having a pointer to an array element specificity a character in a c-string.Every thing I try will not even build.An array is already a pointer to the first location of the array right?
char *pHead; char *pTail; pHead = sentence[0]; <=== This wont build pHead = &sentence[0]; pHead = sentence[0]*; *pHead = sentence[0]; <===== this builds but is not storing anything
I was instructed to write a binary search function which would return true if an element, inputted by the user, was found in the array, and false if it was not. I'm not sure why, but my function always returns false. My code is as follows.
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; //binary search function bool search (int array[], int item)
I'm trying to write a function that returns a pointer to a dynamically allocated array. Here's my code:
#include <iostream> using namespace std; void IndexArray(int, int); int main(){ int *arr, n;
[Code] ....
When I try running the program, I get the error
"Unable to start program 'D:C++FilesdynamicArraySolReleasedynamicArray.exe'. The system cannot find the file specified."
I'm honestly not sure if the issue is my program, or something with C++. At the moment, I cannot debug any of my programs or else I get the same exact error. I basically need to release everything without debugging it. I last used C++ about a year ago and I'm finally back in school, and so trying to get back into it. I use Microsoft Visual C++ 2010.
I am writing a class Player which has several char arrays as private fields. I am trying to write a method which returns an array as a pointer, but doesn't alter the array in any way, thus the const.
Here is a snippet:
Code: class Player { private: char state[MAX_STATE_CHAR + ONE_VALUE]; int rating; char last[MAX_NAME_CHAR + ONE_VALUE]; char first[MAX_NAME_CHAR + ONE_VALUE]; int groupNumber = NEG_ONE; public: char * GetFirst() const { return first; }
Visual studio is saying that the return type doesn't match.
I am trying to write a function to return the first element of a link list queue. I am not real sure how to implement this. I have include a copy of the struct for my Node & queue.
Write a program that uses two functions; one finds the largest number and second largest number; and second function finds the average. The data, comprising of 20 different temperature values, is available on a file.
myClass is a class I have. Now, in the class, I have a function what_value and I need to get the classes.at(0) from the pointer to it in another function. But the problem is, how can I do it? I'm completely stumped, here's what I thought of:
newClass.*myclass.what_value();
And it I get an error from the compiler. Basically, how can I do this in another function with a pointer:
Here is the part of my code that I need to return two values. I am working on a roulette program and I need to return the choice and the number they are betting on. How can I use a pointer to achieve this?
Code: int makeBet(char choice, int num){
printf(" What type of bet would you like to place? "); printf(" Type n for number. Type e for even/odd. Type d for dozen.
I am trying to return a pointer from a method. Below is a sample of my code.
CSubnode * CTest::GetSubNode() { return m_psubnode;//this is declared in CTest as CSunbnode * m_psubnode } //in another class m_subnode = m_ptest->GetSubNode(); //m_subnode is declared as a pointer
I passed the address of the vector to the function. And then display the address. It is a pretty common operation. But it just won't work. But then we do something simple similar to that of the vector. But it works.
I need understanding the logic behind this function. The function is supposed to "Return a pointer to the character at the index given" . For example, what exactly are we declaring at "(char * const c, int index)"? where does "index" come from or equal to in the body of the function?
Code: 1 2 3 4 5 6 7 8
char * GetValueAtIndex(char * const c, int index) { int i = 0; char *p = c; while (i++ != index) p++; return p; }
I want to find third largest character in ascii as alphanumeritic. The problem is i cannot use arrays. How can I find third largest number ? Have to I compare all chars with each other ?
Write a program that reads in a list of integers into an array with base type of int. Provide the facility to either read this array from the keyboard or from a file, at the user's option. If the user chooses file input the program should request a file name. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is to be a two-column list. The first column is a list of the distinct array elements; the second column is the count of the number of occurrences of each element. The list should be sorted on entries in the first column, largest to smallest.
For example, for the input -12 3 -12 4 1 1 -12 1 -1 1 2 3 4 2 3 -12
the output should be N Count 4 2 3 3 2 2 1 4 -1 1 -12 4
Here's My code So far:
#include <iostream> #include <fstream> using namespace std; const int SIZE = 50;
[Code]....
My Code outputs the numbers From Largest to Smallest according to given array, but I need to make it to output the numbers once(if its repeated)
i'm having trouble trying to make this code works .. the program must repeatedly asks user for the age of a person until user enters -1 ,, once he/she entered -1 the program calculates ( smallest value entered, largest value , and average )excluding -1 from calculation
i've been working on this for a weeks this is the best i could do.i know average must add all the entered values , not only smallest and largest but how can i do that here ?
Code:
#include<stdio.h> int main(void) { int age ; int v; int counter; int l=0; int s=0; int limit; }
I am working on a c++ assignment and I need to display the smallest and largest values of an array called from a .txt file...but I don't know how to display them...