I designed one mfc vc++application in which data received from udp is stored in file as well as in stack.I used stl for stack; it stored elements as per receiving order,but i want to return repetitive number from stack,how to use stack as function parameter & retrieve elements of stack as an array? I write code for push elements in stack given below.
<template< typename T > void pushElements( T &stackRef,int value) {
stackRef.push( value);
}/>
I am still new to stacks and recursion and am trying to implement two functions using recursion to get the maximum element in a stack and copying one stack into the other but it keeps repeating some elements and i dont understand why!!
I try to use "rand" to create 100 string, I'm happy I succeed, but next step i wanna know how to count each number of letters and the frequency it shows.
Here is the code:
#include <stdlib.h> #include <string.h> #include <time.h> #include <iostream> // using namespace std; int main() { const char *c = "abcdefghijklmnopqrstuvwxyz";
The problem says that i have a number n > 0 and the program should determinate the number between 2 and N who has the maximum divisor sum (1 and N wont count as divisor). If i have more numbers with maximum divisor sum, should wrote only first number. Exemple: for N = 100 , will show 96 bcoz he has the maximum divisor sum, which is 155. For the start i tried to show only the maximum divisor sum, not the number who has the maximum divisor sum with this code:
#include<stdio.h> int main() { int n,s=0,i,m; printf("Please introduce the number N > 0:"); scanf("%d", &n); i = 2;
[Code] .....
And it shows me 116, but the correct results is 155. Which is the problem ?
Supposing you have a 3 or more overlapping arrays (arrays having elements in common), and you wish to select 2 or more of the arrays with the maximum number of elements but less overlap as compared to the rest of the overlapping arrays.
Eg. A[4],B[6],C[5]. A+B contains 10 elements but say the overlapping element is 3, meaning it has 7 unique element.
Also B+C=11 elements , but supposing it has 5 overlaps, it would mean it has only 6 unique elements. A+B+C=15. Supposing the overlaps are 11 then it means the unique elements are 4. Ect. So per the example, the best array options with most unique element would be A+B .
It seems as though my program is working great but I'm having problems with my random number generator. It keeps giving me a return value from the computer of scissors (or 3) for the computers random choice. What can I do?
//Purpose of Program: This program is meant to prompt the user to choose between 4 menu options. // Each option will be the users choice of rock, paper, or scissors. // the computer will then randomly generate a number and pit you against the computer.
#include <iostream> #include <cstdlib> #include <ctime> using namespace std;
I have a class called items and stored in a vector as vector<items*> item.now I want to make a function to return the placement # that the item is stored at with a unsigned int. but if I don't find the item is there like a null unsigned int that can be returned.
unsigned int someFunc(vector<items*> item) { unsigned int size = item.size(); for (unsigned int i = 0; i < size; ++i) { if (item[i]->getItemName() == "sword") { return i; } } //i need code here incase the item is not there }
because the item might not be there and i would like to do a line if(unsigned int) do this code
you have been tasked to write a program that takes two complex number and return their sum.However the + operator will not worl with complex numbers and you figure you need to verload the + and the assignment opeartor=.Ypu have come across the program [URL]
implement it and the client code to see it rune for the following complex numbers:
c1=3.0-4i,c2=8+4i
i have 3 files,driver.cpp,Complexnumber.cpp and complexNumber.h
complex.cpp is as follows
#include <iostream> using namespace std; class ComplexNumber { private: double real; double image;
I have a code in here that u will multiply the number of seat and the number of ticket. I think I got the correct return value but it's still not working when i times it it always = 0 ...
#include<iostream> #include<iomanip> #include<string> #include<stdio.h> #include<fstream> int getBill(int seat); int getPos(char seat);
When I worked with Fibonacci it was pretty easy since I just had to decrement the next member for each step. I used the following:
#include <stdio.h> #include <stdlib.h> #define MAX 100 int fib(int n) { static int memorize[MAX] = {1,1}; if(memorize[n]) return memorize[n];
[Code] ....
My main problem is that I have no visual of the current function, as well as the fact that it takes the f(n+3) = f(n+2) + f(n+1) + f(n), whilist I've only got f(n) to begin with.
0. Base Case: If the number is one digit long, we don't want to erase it (by returning 0). Instead, riddle me this: When I have a one-digit number, what happens if I change all the 7's into 8's? Well, if the number is 7, it becomes 8, but otherwise it's unchanged.
1. Recursive Call: If the number is longer, then we strip off the last digit, figure out what the answer for the rest is (the recursive call on n/10), and then put the last digit back on the number when you're done.
Hint: You probably need to store the least digit (the n%10) and check if it's 7 separately.
#include <iostream> using namespace std; int removeFirst(int n) { if(n<10) return 0; return 10*removeFirst(n/10)+n%10;
I am trying to print out the letter frequency of a vector that the user inputs and what number that letter is in the ASCII. I am supposed to say, for example: "w" which is ASCII 119 occurs 2 times. How to do this?
I am new to c++. I am writing a program that reads in a text file and gives a count of how many times each letter appeared in the file. I got it to read the text file and do the letter count. B
X = 102 Y = 126 Z = 165 etc...
THAT IS WORNG
The sample output should be E = 165 T = 126 A = 102 O = 93 etc...
I got it to sort from lowest to highest for the frequency, but cant seem to get the appropriate letter assigned to it.
I have taken a keen interest in writing trading programs. I have some Python background, a little C# but no C++.
The example below was provided in a book on HFT and I would love to see how the results look. I was hoping that I would just compile it and away you go!
That didn't happen. To start with the author listed this as a function, so I converted it to a main program. Still having issues with my path and where to see the output. Here it is..
I'm trying to figure out the word frequency of a user inserted string. I've tried doing it via getline of the struct array and via the getline of the string word but neither either the former crashes or the latter just prints out the whole string.
I have been working on a project that deals with an array of characters and finding there frequencies. I was able to determine the frequencies that where greater than 1, but I need to find the HIGHEST frequency.
Here is my full code:
#include <iostream> using namespace std; void input(char unlisted[80], int& n); void bubblesort(char unlisted[80], char sortedlist[80], int n);
[Code].....
As you can see this will print out all frequencies that are bigger than 1, but I only want the highest frequency. Basically I want to print out all frequencies when count is greater than 1 less than count, but because its in a loop count will always be greater than count-1 so it prints out all frequencies.
the code shows all characters frequency, however i want to find which one has highest frequency for example cprogrammmmming cboard highest frequency: m
char string[100], ch;int c =0, count[26]={0}; printf("Enter a string"); gets(string);