I'm getting a bit lost in calling functions correctly. The assignment says to, reprogram this assignment using functions and include the additional features identified below -
Design your program so the main function invokes/calls functions to perform the following tasks:
4) sort the arrays in ascending order by student ID number
Here's what I've got thus far and I'm confused cuz I might be calling my function incorrectly.
Code:
#include <stdio.h>
#define MAX_ENTRIES 50
void s_ID (int student_ID[], int test_score[], char char_val[]);
int main (void) {
I'm a newbie to C++ and I've been working on this Delaunay tree in C for some time. I'm ready to port it to C++ which does not mean that the code itself is completed or done.
But I was wondering, how could I design my code to fully utilize C++?
For one, I'm using C++'s built-in stack/queue/vector functions because it's a lot nicer than building my own stacks or queues lol.
So, here's an overview of the code.
The mesh is built of tetrahedrons so I have a "struct tetra" which stores pointers to vertices ("struct particle") and its 4 neighbours. Working in half-plane data, we have:
double a[4], b[4], c[4], d[4];//half-plane data };
I'm fracturing these tetrahedrons by inserting vertices so I can get anywhere from 2 to 4 children per fracture per tetraheron. I'm mapping this history to a quadtree. This looks like :
Code:
struct tree { int level; struct tree *parent; struct tree *children[4]; struct tetra *t; };
What would be the best OO approach to this problem?
I thought about just using this object,
Code: struct mesh { struct tree *root; //pointer to root /* insert all functions to be used by mesh here */ };
But I'm not sure how effectively this would be taking advantage of the OO paradigm.
I realize that implicit int rule was removed in C99 but gcc still takes this approach by default. I wonder why this happens:
bbb = 5; // legal int main(void) { aaa = 10; // illegal auto aaa = 10 // legal
Inside function a specifier is needed. Error message with no specifier used is:
error: ‘aaa’ undeclared (first use in this function)
Is this because of linkage - bbb variable has an external linkage so compiler knows that we are defining a variable here while inside mean() we need to show compiler that aaa is defined right here, it does not come from external functions?
I'm a little confused by my programming assignment this week. I've been working at it Wednesday and I've made progress but I'm still confused as to how I'm supposed to do this. The class I made is called Stack, and it's derived from a template class called StackADT. We also utilize a class called unorderedLinkedList, which is derived from a class called linkedList.
We're supposed to implement all of the virtual functions from stackADT in the Stack class. The Stack data is stored in a an unorderedLinkedList, so what I'm confused by is how to implement a few of the Stack functions because there are no functions in unorderedLinkedList which we could call to manipulate the data.
As you can see from my attached code, I'm really confused by how I'm supposed to implement the pop() and top() functions, and I also think my initializeList() function is wrong. We don't have any similar functions in unorderedLinkedList to call, so I'm at a loss of how i'd access my unorderedLinkedList. My initial thought was to call the similar functions in the class that unorderedLinkedList was derived from, linkedList, but I'm unsure of this is what we're supposed to do, or if theres actually a way to access my unorderedLinkedList without having to use the functions from the base class.
NOTE: We're not allowed to modify stackADT, unorderedLinkedList, and linkedList.
Stack.h
#include "stackADT.h" #include "unorderedLinkedList.h" template<class Type> class Stack: public stackADT<Type>{ template <class T> struct nodeType { T info; nodeType<T> *link;
But now I'm trying to use this to point to a function inside a class so instead of do11, i want to be able to point to Basic.Do11. Somehow this doesnt work and I keep on getting this message:
error: argument of type 'void (Basic::)()' does not match 'void (*)()'
So In my studying of C I am starting to come across more programs with functions in them.This particular program asks for two numbers, and calculates the sum of all the squares of the two numbers and the numbers in between them. I am confused about the get_int() function.
Code:
/* checking.c -- validating input */ #include <stdio.h> #include <stdbool.h> int get_int(void); // validate that input is an integer bool bad_limits(int begin, int end, int low, int high); // validate that range limits are valid double sum_squares(int a, int b); // calculate the sum of the squares of the integers a through b }
[code]....
So in that get_int() function, it's pretty simple if scanf returns 1, otherwise... another while loop call the getchar() function, which is assigned to the variable ch. So say I enter 'a' for the lower limit, this is what happens:
Code: Enter the limits (enter 0 for both limits to quit): lower limit: a
a is not an integer. It seems as if getchar() somehow "got the character" from scanf(). There's no way that getchar() could have been simultaneously reading my input, because that function is not even called until scanf has already not returned 1. So I'm confused how that happened. I was under the impression that getchar() got input from the keyboard, which would lead me to think that I would be prompted to input something again when getchar() is called, before putchar() prints the scanf input. But this is obviously not the case.
Also, I'm curious about that comment beside putchar(ch) that says //dispose of bad input. I recall a long time ago on these forums, someone told me something about how once scanf has read input, that input is like... stuck to scanf.. So does putchar() not only print the input from scanf/getchar, but also unload it from scanf, so to speak?
I am new to c and I have come across a problem when adding other functions to a programme and printing the values. The question I am attempting to solve is :
The following function computes ex by summing the Taylor series expansion to n terms. Write a program to print a table of ex using both this function and the exp() function from the math.h library, for x = 0 to 1 in steps of 0.1. The program should ask the user what value of n to use.
double taylor(double x, int n) { int i; double sum = 1.0; double term = 1.0; for (i=1; i<=n; i++) { /*Or we could have written: */ term = term * x / i; /* term *= x / i; */ sum = sum + term; /* sum += term; */ } return sum; }
My code is
Code:
#include<stdio.h> #include<stdlib.h> #include<math.h> /*Taylor series for e*/
[code]....
code prints out the values for exp, but it gets stuck in the Taylor function and I'm not sure how to solve it.
forget everything from before. It came out of confusion regard the supplier functions. dis_s() and read_s() the part functions work and are not any different really.
when I run the dis_s() function it just prints out garbage until it segments. starts with a bunch of 0 and newlines until it starts printing locations on my computer...... it worked on campus with debian and I only copied it from gmail to my computer so I really don't understand whats up(im on mint).
In my program below, in the getage and get level functions, if an incorrect input is entered, then the correct one is entered after, it still returns the bad input back to main.
Every time screen2() runs it always outputs "Numbers entered were 0 and 0". I want the numbers that were entered in by the user in screen1() to be displayed.
Not quite sure what the problem is here. I have all my functions in my class header file, and I believe I have them declared at the top, but it is telling me that I do not. The project is simply to use set and get functions to display the date.
I have a hpp file with a list of inline finctions like this:
Code: inline int check() { return 1; } inline int check_1() { return 1; }
... What I would like to do is to include them into several unrelated classes. How can I do this. Can I just add the hpp inline functions in headers of my class containing files or not. I mean if they are not defined as class functions how can they be called. I don't understan the logic.
So i wouldn't have to retype it again in the loop, i would just call the function. but it seems whatever i try it doesn't display the text. i've tried making a function with no return time like this " Void Pausemenu(); " but that just goes blank.
Code:
#include <iostream> using namespace std; //This function displays different results based on the users input int menu(int menuchoice); int main()
I am getting an error on lines 31 and 36 about an expected identifier on my program that computes area and circumference. Is something wrong with my external functions outside of main?
I have been struggling with pointers. I am trying to write a program that first asks a user to input a filename. It then checks if the file exists and if it does it passes a pointer to the next function. The next function then asks the user for a specific word to look for and the function will search a text file for the word and do some other operations. My problem is that I do not understand how to use the pointer returned by my first function as an input to another function.
The following code has the first function file_check() and the second function word_search() which I think the way I am declaring it is the problem.
I'm having some problems with a function. The function is supposed to find the two largest values in an array.
Code:
void find_two_largest( const int *a, int n, int *largest, int *second_largest){ largest = a; int temp; second_largest = a; for ( int i = 1; i < n; i++){ if (*(a + i) > *largest){ temp = *largest;
[Code]....
I don't see any mistake with the code of the function, but when I try to call it inside my program it only returns 0 for both largest and second_largest.
Code:
int *find_middle( int *a, int n); void find_two_largest(const int *a, int n, int *largest, int *second_largest); int main() { int n;
[Code]...
Do I have to declare the variables largest and second_largest as normal integer variables and then pass their addresses as arguments to find_largest or is that incorrect?