My question is to write a complete program that will search a file of numbers(numbers.txt) for the smallest and largest numbers and then write the values to the screen using a single pass through the file. File only contains type int and holds at least one int. My questions are am I reading in the first number correctly? Where would I read in the second number to compare to the current max and min?
Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * argv[])
{
FILE *fin;
fin = fopen("numbers.txt", "r");
//check to make sure file opened
if(fin == NULL)
}
User enters sentence "The Smiths have two daughters, three sons, two cats and one dog." (The numbers may change depending on what the user chooses to enter. He told us the range would be from zero to nine.) and we have to convert the written numbers within the sentence into actual decimal numbers and print out the new sentence. Ex. The Smiths have 2 daughters, 3 sons...etc.
I have written the following bit of code which reads the string and finds all the "written numbers" but I am not sure how to proceed from there. I am stuck on how to print out the new sentence with the converted numbers as my professor mentioned something about creating the new string using dynamic memory allocation.
Code: #include <stdio.h>#include <string.h> int main () { char A[100]; int length = 0; int i;
I know how to write the GCD for one, two, three, four, and etc, numbers. But I cannot seem to find a way to write a code that does it for 'n' numbers.
That is, the user inputs a number 'n', which determines the size of a dynamic array. Then they are prompted to input the values for each of the elements in the array that will constitute the numbers the program is to find the GCD for.
This records the array:
for (int count = 0; count < n; count++) { cout <<"Enter the numbers you wish to find the GCD for, for term" << count << ": "; cin >> GCD_n[count]; }
Here is a code for finding GCD of three numbers:
cout << "This program finds the greatest common divisor of three numbers. " << "Enter the first number: "; cin >> a;
[Code] ....
How to proceed coding a program that finds the GCD of 'n' terms.
GCD_n[n] is the array that contains the numbers for which we need to determine the GCD for.
My main problem is with writing a code that tests the elements of the array containing the list of numbers in GCD_n[n], all at the same time, such that:
int n; cout << "This program finds the greatest common divisor of n numbers. " << "What is the total amount of numbers you want to find the GCD for?
Ok so I'm reading the Programming: Principles and Practice using C++ and Im stuck in Drill 4 part 5. It says:
Change the program so that it writes out the "numbers are almost equal" after writing out which is the larger and the smaller if the two numbers differ by less than 1.0/10000000
I'm using an If statement for it... I just need know what the formula is to check 2 numbers that were entered by person if they land within the range specified above. so then I can cout << "numbers are almost equal" << endl;
I have written a program that finds the divisers of non-prime numbers and outputs them. However, the output is only one diviser per line(because of the repetition to find the divbisers), but the instructor wants us to have 5 to 10 divisers per line. How can i write this loop so it will only output the divisers in one line?
A prime number is a number greater than 1 which is only evenly divisible by 1 and itself. For this assignment you will find which numbers from 2 to n (where n is a user-specified number) are prime. Ask the user for a number, n, greater than 2. Keep asking for a number until a number greater than 2 is provided. Assume that the user will only enter numbers (that is, you do not need to check if a user enters text).
Use a loop to iterate on a variable, i, from 2 through n. For each iteration, check all numbers from 2 through i to determine whether the number is prime. If it is prime, print out i and the word "Prime". Use the modulus operator, %, to determine if a number is prime
Example output:
Please enter a number larger than two: -939 Please enter a number larger than two: 2 Please enter a number larger than two: 20 2 Prime 3 Prime 5 Prime 7 Prime 11 Prime 13 Prime 17 Prime 19 Prime
This is what I have so far. I suppose i'm not really understanding how to continue with the second for loop. The first one just prints out a list of numbers from 2 to the number designated by the user. In my case that variable is user_input.
I'm currently working on an assignment that finds all happy numbers for a given range. Such as 1- 10. My current code just isn't cutting it. I have to use a user defined function and return a bool value to main in order to output if the number is happy or if it sad. For some reason, I cannot get it to loop properly. the first number will be displayed correctly, but the second and third are just squares of the first number, instead of being squared by their single digits. I'm dividing by 10 to get the first number of the digit entered, then I'm using mod to get the remainder. One thing I did notice was that the num2 was putting a remainder of 30 for 130, and I'm not too sure what I need to do to change that, without affecting the whole program.
#include <iostream> #include <iomanip> #include <cmath> #include <cctype> #include <string> #include <cstdlib> using namespace std; Program calculates the bill for a user
Write a program that prompts the user to enter a number larger than 2. The program should use the Number class to determine the prime numbers between 2 and the number entered, and display them in the console window.I've been stuck for a while now and just lost in implementing classes and contstructors.
#include <iostream> using namespace std; int main(int argc, char * argv[]) { cout << "Enter a number larger than 2: " << endl; int n; cin >> n;
I was doing a side project from my textbook about finding the mode, which is the number that occurs most often in a sequence of numbers. I racked my brain on this for an embarrassing amount of time and finally came up with this, which I think works but for some reason I still feel like I'm not done.
#include "stdafx.h" #include <iostream> using namespace std; void mode(int *, int); void main() { const int NUMBERS = 15; int list[NUMBERS] = {99,73,56,14,28,42,93,64,51,26,56,16,38,81,98}; mode(list,NUMBERS);
[Code] ....
Console Output:
Final Mode 56 Press any key to continue . . .
There it is, I would have commented more but I couldnt think of the right words to explain everything.
I need validation on what the user inputs. Input should not be an alphabet, empty, and not negative number. This program is for finding the GCD and LCM of multiple numbers.
#include <stdio.h> void bubble_sort(int numbers[], int len) { int i, j; int swapped;
I'm trying to make an array that takes a group of numbers and finds the largest number into a template class.
template<class TYPE> void Integers(TYPE data) { int integers[] = {4, 25, 32, 85, 150, 12, 98, 200}; int i = 0; int Max=integers[0]; for (i=1; i < 8; i++) {
[Code] ....
I'm sure I'm going about it all wrong, but I'm not sure as to get it so that it will accept the arrays input.
I need to find a string(&login=) from physical memory dump file.And i have to print the word or string following it.Is there any C# code for this problem?
Write a program which reads a stream of numbers from a file, and writes only the positive numbers to a second file. The user should be prompted to enter the names of both the input file and output file in main(), and then main() will open both files. Another function named process() must then be called to read all the numbers from the input file and write the positive numbers to the output file. Note that you must pass the open stream variables for each file as arguments to the process() function, and that you need to (always) double check that the files opened successfully before using them.
This is what I have so far but its not working out!
#include <iostream> #include <fstream> #include <stdlib.h> using namespace std; int process(ifstream &inf, ofstream &outf);
This function buildTree that reads an text input (contained in the file named in argv[1]). Then, I am opening the file, reading character by character, if there is a new line ("if (token == ' ')") keep track of this line number and store it in a vector to access it later. Next it breaks it into a sequence of words (using any character other than a digit or an alphabetical symbol as the terminator). This is where I'm getting an error. I am then trying to add each character to a string and then when the token is a digit or an alphabetical symbol, then push the string into a vector so I can access it later. Is my logic right? error when pushing each word into a vector.
BinarySearchTree buildTree (char *argv[]){ ifstream file; vector<char *> V; int line = 0;
I'm a new coder for C++, and I've recently learned java before starting this programming language. I'm attempting to find all prime numbers up to the number a user enters (i.e. User enters 10, System shows "1,2,3,5,7"),
#include <iostream> #include <cstdlib> using namespace std; int main(int argc, char** argv) { int num; cout << "Enter a positive number." << endl;
[Code] ....
I've been looking at my forloop, and I can't seem to pinpoint the problem with it.
I have a specific byte (that is unsigned char) array, that I need to find in a very big file (2GB or so), currently I'm using:
size_t fsFind(FILE* device, byte* data, size_t size) { int SIZE = (1024 > size) ? 1024 : size; byte buffer[SIZE]; int pos = 0; int loc = ftell(device);
[Code] ....
Which seems to find proper result on first use, but on subsequent searches it seems to find invalid positions, is there something I'm doing wrong, or is there a better way?
Problem: I have to find the word "NAND" and then find the numbers inside the brackets because they are the inputs to that NAND gate. I have written a code below but that code can detect the fixed number of inputs. I need a code which can detect any number of inputs (whether 2 inputs or more than two). But i don't understand how do i do that?
My code:
Code: string input_str ("INPUT"), output_str ("OUTPUT"), nand_str("NAND"); while (getline( input_file, line )) { std::size_t guard_found = line.find(guard_str);
Since the calculation I performed gives me -71.77 Volts, I need to match this value to the time that this occurs closest to using my program, and output the time that this occurs at.
Here is my program so far: int main() { std::ifstream inFile; inFile.open("AP.txt"); ofstream results_file ("maxvaluewithinput.txt"); float TimeAtdVMax = 0; float VoltsAtdVmax = 0;
[Code]...
If you're curious, this program isn't for homework. It's part of the independent learning on C++ I'm doing for a Master's Thesis; the program will eventually model the APD90 of a ventricular action potential.
im supposed to create a program that reads in a list of integers from the terminal and writes the negative numbers to one file and the positive numbers to another file.
i got most of it doen but for some reason its not writting the negative numbers. on what im doing wrong?
#include <iostream> #include <fstream> #include <string> using namespace std; int main(){ int pos_num = 0; int neg_num = 0; int positive_numbers = pos_num % 5;