I am trying to write a function that will count the number of distinct values in an array of N size and return that number. For example array a[n] = {1, 2, 3, 1, 2, 3, 1}. My code won't look exactly like this because I am using an array that can be modified by user input. it is part of a bigger program that will also has a function for finding the Equilibrium Index for that same array. This is what my Code looks like:
void findDistinctValues() {
int t = 0;
int j = 0;
int disValue = 0;
for( i = 0; i < arraySize; i++) {
[Code] .....
This function works but the problem is it returns 16, or the number of times that the number being compared does not equal the one it is being compared to. how do I get it to only return the number of distinct values? The data set mentioned above is what I am using for input data so it should only have 3 values.
I'm trying to calculate the number of distinct values entered into an array. If i enter the followings "3,4,5,6,7,7,6,e (anything that's not a number)" . I get a total of 7 but in reality it should be a 5.
Code:
#include <stdio.h> //---------function to find the distinct values---- int find_distinct(int list[], int size) { int i, j,size2, distinct = 0; for(i = 0; i < size; i++)
now using sba or Set Based Algorithm I have to pair it out and towards the end find the size of the resulting set
#include <iostream> #include <set> int main()
[Code]......
this is the code just reads the edges that's 3... that is when we input the code. But what if its in a file? how do I read from there and show the paired count and the time taken?
Also I have the file that works and reads any txt file..but how do i get the code from it?
[URL]
this is the file..you have to run it as ./edgecount for it to work
#include <windows.h> int main() { int i; int y=6; int x=9; gotoxy(x,y); //gotoxy(x,y) must be the coordinate that the number lies in.
[Code] ...
How to make this program that the output is a number that counts up to infinite (or we say just like a timer but there's no minute just all whole number counting up ) using for loop ? and when the number changes it also change in color ! and the color of a number is according to the color attribute of console output.
I am unsure how to write a function which modifies the content of the 1D character array and counts the number of the vowels. the following is the array that i have.
I have recently hit a stump with C++ and have been getting pretty frustrated with this assignment. I just can't seem to find out how to start the assignment. Basically for the first part of the assignment, I need to find the number of characters in this .txt file my teacher provided for me. The only exception is that I can only count the actual letters themselves, not spaces or punctuation. How would I go about doing this? I have read about functions like isalpha but can't figure out on how to fit them into code to do the first part of this assignment.
it looks like a popular method for determining the total lines in a file is to read the entire file character by character in search of ' '. I have a file with 5 lines, but for some reason this code isn't finding any instances of ' '. Is this possible? Is there a better way to get the number of lines in a file?
The file looks like this:
Code: NAME: John FRIEND 1: Steve FRIEND 2: Andrea FRIEND 3: Ken OCCUPATION: Programmer
I'm a basic C++ programmer, and I am stuck on this problem. You work for a company that collects a set of numbers. The numbers are located in a data file named "./Data_File". The data file contains two columns. how do you count a certain number on the left column.
I'm trying to write a program and I'm stuck. In order to continue on I simply need to know if there is a way of counting how many times the remainder of some number n when divided by some number x is 0.
For example
int lockers, i; cin>>lockers; //how can I count the amount of occurrences where lockers%i==0 while i<=lockers
A bit hard for me to articulate so let me know if it's unclear.
I was trying to make a function that would return how many lines are in a certain file. I was looking at [URL] which talks about how to count how many characters are in a text file. I just want the number of lines with in a file.
I'm trying to copy a file into another file and copy the number of characters copied but my while loop doesn't even enter into a loop indicating the file is already at the EOF file character. I've confirmed this by placing the printf() statement inside the while loop, which doesn't print anything and by keeping it out of the while loop and changing the chars_copied to something like 9, it prints 9 for number of chars_copied. I don't understand why the file is already at the EOF character, I've tried this with a few more files, it's the same result.
Code: #include <stdio.h> int main(void){ FILE *input_file, *output_file; int c, chars_copied=0;
if((input_file=fopen("C:workmarks.txt", "r"))==NULL) perror("input file open failed");
How can i count total number of each topic separately? For example total number of topic 1 between all nodes. To begin enter 10 and 7 to initial node number and number of topic.
I've been struggling with this for a while, I have to write a function that accepts a word (in my case the word is "the") and file pointer, and counts the number of times the given word appears (case insensitive) within the file associated with the pointer. This means the two words "the" and "THE" should both be counted.
Here is my code:
int WordCount :: countWords(string wrd) { int counter=0; string temp = ""; while (getline(*file,temp)) { for (int i = 0; i < temp.length();i++) {
[Code] ....
This is what I have come up with, but I get an incorrect value. It was suggested to us to consider using the strcpy() or strstr() functions, but I don't know how to use them.
Ok, so I am writing this program with 10 different functions, and one of those functions needs to count how many times 0 appears in a text file. I've done this before, but I am so stumped right now. Should I get the numbers from the 2d array I have, or should I just use the text file here? Here is what I have right now:
int toursMissed(int scores[][COLS]){ int counter; for(counter=0;counter<=96;counter++){ if(scores==0){ counter++; return counter; } }
I have to write a function that accepts a word (in my case the word is "the") and file pointer, and counts the number of times the given word appears (case insensitive) within the file associated with the pointer. This means the two words "the" and "THE" should both be counted.
Here is my code:
int WordCount :: countWords(string wrd) { string temp; int counter; while (!file->eof()) { *file >> temp; if (temp == wrd)
So I'm trying to count the number of lines in a text file that is inputted by the user. Also the code doesn't sum up the last number of the text file (exmp it calculates and print only 14 from 15 numbers). I'm a beginner in c++ programing.
I'm creating a program to read information about class schedules at my school, reformat the information, and allow the user to search for specific semesters. There are eight fields of information. I'm reading the info from a text file using eight parallel arrays, but I'm having trouble declaring the arrays. I can run this code in one compiler (Dev-C++) with no problems, but I get errors when trying to compile it using Visual Studio stating that arrays must be declared with a constant value. I have a loop to run through the text file, with a counter to increment with each subsequent line, then I create a constant int equal to the counter, and declare the arrays of size equal to the constant int. Here's the section of code in question:
// Counting the number of lines in the text file inFileForLines.open("CIS225HW1DA.txt"); string countLine; int numberOfLines = 0; //Discarding the first line of the text file containing only column headings getline(inFileForLines, countLine);
write a c++ program that reads an unknown number of integer values and then print count, sum and average of odd values, even values, positive values, negative values!!
If I want to check if all the variables are pairwise distinct, i.e. they're all different. Here's a code I wrote to do this:
if (s!=e&&s!=n&&s!=d&&s!=m&&s!=o&&s!=r&&s!=y&&e!=n&&e!=d) if (e!=m&&e!=o&&e!=r&&e!=y&&n!=d&&n!=m&&n!=o&&n!=r&&n!=y) if (d!=m&&d!=o&&d!=r&&d!=y&&m!=o&&m!=r&&m!=y&&o!=r&&o!=y&&r!=y)
Is there perhaps some function that would let me do this in a lot shorter way, i.e. something like this (that would act the same way my other code does): if (different(s,m,d,e,o,n,y))
What is the best way you can think of? Without having all those variables in an array. Otherwise it wouldn't be so hard to create a function.
The assignment is apparently pretty classic: given a starting state and a goal state, show the optimal path to solve a 3x3 sliding puzzle.
I have the code in place.Where I'm experiencing major issues is in maintaining two distinct linked lists. One should contain the frontier of the A-star algorithm and the other records the optimal path. In execution, however, it seems that only one list is in local memory in any one function. Therefore, when my function recurses, the lists begin to get confused and the whole algorithm veers off course.
Here is my structure definition in list.h:
typedef struct node { int value; int state[3][3]; struct node *next; } Node; typedef struct list { int count; Node *first; } List;
Here is my List_create function in list.c (do I need malloc here?):
int main(void) { List open; List closed; List_create(&open); List_create(&closed);
Here's the general flow of the program, without posting a wall of code: both lists are passed to another function in main.c, expand(), with this line:
expand(current, gState, &open, &closed);
The lists are later passed from expand() to another main.c function, generateOptions(), in this line:
generateOptions(&array, goalState, open, closed);
generateOptions() returns back to expand(), which recurses on itself with the first item in the open list and continues the expansion:
expand(open->first, goalState, open, closed);
Strangely, the open list prints out correctly before generateOptions() returns to expand(), and the closed list prints out correctly after generateOptions() returns to expand(). But when I try to print the open list in expand(), I'm instead given the closed list. Like I said at the outset, it appears that only one list exists at a time!
I'm taking a C++ computer science course right now, and one of the questions on my latest assignment is this:
"A partition of an integer n is a way of writing n as a sum of positive integers. For example, for n=7, a partition is 1+1+5. Write a program that finds all the partitions of an integer n using r integers. For example, all the partitions of n=7 using r=3 integers are 1+1+5, 1+2+4, 1+3+3, 2+2+3."
I've been struggling with this problem for a couple days now, and how to do it. I understand I need a recursive function to grab variables, and probably an array or vector to store them, but where to begin.
I've been reading documents on partition generating and the concept still eludes me, and any other questions on here or other programming sites using partitions don't seem to have a constraint on them.