C :: Make A Separate Function

May 6, 2013

I will post the entire code at the bottom. Its running fine right now but This part in the menu function I need to make as a separate function. My problem is when I make it into a function by itself I have to declare and initialize the grades A,B,C,D,F how can I do that when I can't make them equal 0 because it has to keep track of how many of each letter grade.

Code:

//Count letter grade
if(ave >= 90)
++A;
else if (ave >= 80)
++B;
else if (ave >= 70)
++C;
else if (ave >= 60)
++D;
}

[code]....

View 3 Replies


ADVERTISEMENT

C :: Make A Hash Table Array Of Linked Lists / Separate Chaining Technique

Jul 5, 2013

how to create a hash table array and use linked lists inside the elements.

View 5 Replies View Related

C++ :: Using Template Function Inside Class In Separate Function?

Mar 26, 2014

i want to use a class to print data stored as vector or array with different data types. i also want the print function two take more than one vector or array or combination of both so that they can be written to file as two columns. so i wrote the following class:

right now it has only one member function for printing two vectors. later i'll add additional functions as required.

note: there has to be template functions inside the class
i also want the object to be global so that i need not pass it as an argument to other calling functions

class printdata
{
public:
template<typename T1,typename T2>
void SaveData( vector<T1> &data1,vector<T2> &data2, std::string var)
{

[Code]....

then i want to call this template function in another ordinary function written in a seperate cpp file

these function declarations are put in a header file. so i need know whether i should put the declaration of the template function in the header to use the function in different functions

View 4 Replies View Related

C/C++ :: Using Template Function Inside A Class In Separate Function?

Mar 26, 2014

i want to use a class to print data stored as vector or array with different data types.

i also want the print function two take more than one vector or array or combination of both so that they can be written to file as two columns.so i wrote the following class:

right now it has only one member function for printing two vectors. later i'll add additional functions as required.

note: there has to be template functions inside the class / i also want the object to be global so that i need not pass it as an argument to other calling functions

class printdata {
public:
template<typename T1,typename T2>
void SaveData( vector<T1> &data1,vector<T2> &data2, std::string var){
std::ofstream myfile;
std::string filename;

[code].....

then i want to call this template function in another ordinary function written in a seperate cpp file these function declarations are put in a header file. so i need know whether i should put the declaration of the template function in the header to use the function in different functions.

View 1 Replies View Related

C++ :: Returning Two Separate Variables In A Function?

Dec 12, 2013

How to use a function twice to calculate two different variables. How to have a function compute the city tax, then it uses the function a second time to compute the county tax.

My program compiles, and runs fine, however it only outputs the city tax calculation. It seems it never attempts to calculate the county tax.

One thing: All of the directives I used is what we are limited to, no more, no less. He requires a set format and will dock points of you use anything but those directives and void main().

Here is my code so far:

/* function for city tax calculation */

#include <iostream>
using namespace std;
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
const double city_tax_rate=0.03;

[Code] ....

I am using Visual studio 2010.

View 9 Replies View Related

C++ :: Member Function Undefined In Separate File

Feb 25, 2015

I have three files.

//headerfile NumArrSpecs.h
#ifndef NUMARR_H
#define NUMARR_H

[Code].....

My problem is that the storeElems member function is causing an error saying it is undefined, however there are no errors any where else in the program being reported. I have made several programs involving classes now, all with this three file format and this is the first time that a member function in the main file is being reported as undefined, so I'm not sure what to do.

View 2 Replies View Related

C++ :: Function That Takes Two Input Arguments And Provides Two Separate Results To Caller

Apr 20, 2014

Write a function that takes two input arguments and provides two separate results to the caller, one that is the result of multiplying the two arguments, the other the result of adding them.Since you can directly return only one value from a function, you'll need the second value to be returned through a pointer or reference parameter.

Code:
#include "Code.h"
#include <iostream>
#include <string>

double x, y;

[Code] ....

View 3 Replies View Related

C++ :: Keyboard Function That Is Called In Main Function To Make Shape Move

Jan 19, 2013

Ok so I am working on a game and I'm in the process of developing my Player class. Anyways, what I have is a keyboard function that is called in my main function to make a shape move.

void myKeyboardFunction(unsigned char key, int x, int y) {
switch ( key ) {

[Code].....

But when I try to call it, trying to copy my previous method,

glutKeyboardFunc(Player1.playerControls);

I get an error

error C3867: 'Player::playerControls': function call missing argument list; use '&Player::playerControls' to create a pointer to member

I get an error saying it can't convert parameters. I would just like to understand why the arguments become a problem when I make the function a member of my class, when the first method I used is so easy.

View 2 Replies View Related

C :: How To Make A Sort Function

Feb 28, 2013

Im suppose to make a "poor mans" variation to the Sort function built into unix. The program is suppose to read in a file and sort the contents of the file. So its a variation of the Unix Sort feature. I have remade the readLine function we were provided so that it doesnt use fgets. where to go from here, Not sure on how to make a sort function. Here are the reqirements of the program:

Code:

• Re-implement the readLine() function so that it no longer makes use of fgets(). Instead,
process the input on a given line character-by-character.

• Provide code which will create a data structure similar to argv to hold all of the words to be sorted. Use malloc() to ensure that each entry has just the required number of bytes needed to store the words. The final entry in your array should be the NULL pointer.

• Implement a sort() function which will rearrange the words in sorted order. To swap two words in your array, note that only a pair of pointers need to move. The strings themselves, once established, will never move. Heres what i have:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LINES 1000 /* maximum number of reminders */
#define WORD_LENGTH 10 /* max length of reminder message */

[code]....

View 9 Replies View Related

C++ :: How To Make A Function Non Overloadable

Jul 11, 2014

I would like to know if there is a way to make a function non overloadable. My idea is to keep it private in the class so that it will be impossible to overload the function in a derived class.

But if in the base class (the one that holds the private function) I also have a public or protected function (let's call it plf) to manage the private one (let's call it prf), and in the derived class I create a function with the same name as the private base class function (prf) that calls for the public base class function (plf), I am wondering if there won't be a conflict between both of the same-named (prf) functions?

Assuming the prf function of the derived class is not an overload of the prf function of the base class (because the last one is not visible).

View 5 Replies View Related

C++ :: How To Make A Shape Outside Of Main Function

Sep 8, 2014

I know how to define a shape and attach it to a window as follows:

#include <Simple_window.h>
void cir() { Circle c(Point(100,100),50); }
int main() {
Simple_window win(Point(100,100),600,400, "test");

Rectangle r(Point(100,100),Point(300,200));
win.attach(r);
win.wait_for_botton();
}

But how to define a shape (say a circle by that cir() function which is) outside of the main() function? And how to attach it to be visible on window win?

View 4 Replies View Related

C/C++ :: How To Make A Shape Outside Of Main Function

Sep 8, 2014

I know how to define a shape (here, a rectangle) and attach it to a window in C++ as follows:

#include <Simple_window.h>
void cir() { Circle c(Point(100,100),50); }
int main() {
Simple_window win(Point(100,100),600,400, "test");
Rectangle r(Point(100,100),Point(300,200));
win.attach(r);
win.wait_for_botton();
}

But how to define a shape (say a circle by that cir() function which is) outside of the main() function? And how to attach it on the window win to be visible?

View 4 Replies View Related

C/C++ :: Make A Structure For Date Containing Two Function

Jan 13, 2014

Make a structure for date containing two function one for increment Date() that add to date if day increase month also increase.

2nd for validation for date like day is not greater than 30 or 31.and validate the user input before user entered value.

I have done second. but no idea for first one. Any hint for increment date.

View 4 Replies View Related

C :: How To Make Function Which Gives Back Two Numerical Values

Nov 3, 2014

How make function which gives back two numerical values. I think needs using structure. now i try found my c book.

View 3 Replies View Related

C++ :: Make A Function To Return Placement Number

Mar 25, 2014

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

View 19 Replies View Related

C++ :: Make A Function Integrate To Work With Other Functions Given

Mar 10, 2013

We have to make a function integrate to work with the other functions given. I had it working before but I would only get all -4 as my answers but only the first one should be -4. what should more or less be put in my integrate function?

#include <iostream>
using namespace std;
typedef double (*FUNC)(double, double, double) = (line, square, cube);
double integrate(double FUNC, double a, double b){
for(int i=0; i<a && i<b; i++){
FUNC = a-b;

[code]......

View 2 Replies View Related

C++ :: Make A Function That Checks If Array Is A Permutation

Feb 16, 2014

I need to create a function with the following prototype:

bool isPermutation( const unsigned a[], unsigned elements );

unsigned a[] = {3, 0, 2, 1};
bool P1 = isPermutation( a, 4 );
would set P1 to true because the set of subscripts is {0, 1, 2, 3}, and the values are just a reordering of those values. On the other hand,

unsigned a[] = {3, 0, 2, 3};
bool P2 = isPermutation( a, 4 );
would set P2 to false because the set of subscripts is {0, 1, 2, 3}, but there’s no value that’s equal to 1.

I'm not exactly sure how to do this. I thought about it a couple different ways. I first thought about taking the range (max/min) and then checking to see if the numbers in between are equal from each other, distance-wise.

I then thought that I should just make this basically a sort function (I used bubble-sort), and then to just check if the numbers are equi-distant from each other.

This is my basic bubble-sort. Perhaps it is wrong, but I'm not certain...Perhaps I am making this function harder than it has to be.

unsigned temp = 0;
for (unsigned i = 0; i < elements; i++){
for (unsigned k = 0; k < elements-1; k++){
if (a[k] > a[k+1]){
temp = a[k+1];
a[k+1] = a[k];
a[k] = temp;
}}}

Should I do a sort like this, and then do something where I subtract a[i+1] - a[i], and see if that equals '1'?. I would think that would mean they would have to be equidistant. Even if this is correct, I feel like it could be more efficient.

View 4 Replies View Related

C++ :: Make Visual Studios Step Into A Function?

May 2, 2013

if there is a way to make Visual Studios step into a function while I am debugging.. I am trying to see the value of a certain int and making sure it is what I need it to be.. but whenever I use step into visual studios just skips right over the function and it does all the calculations..

View 4 Replies View Related

C++ :: Make Resize Function For Matrix2 Class?

Aug 29, 2013

class Matrix1
{
Protected:
int ** data;

[Code].....

// How can we write resize function for Matrix2 class; where this function need to use Protected data members of matrix1 class? Only setters are available in Matrix 1 class but there is no getter function in Matrix1 class !

View 1 Replies View Related

C/C++ :: How To Make A Function Prototype That Uses Variables By Reference

Dec 4, 2014

How to how to make a function prototype that uses variables by reference. I'm making a decision based game where two running totals of two variables (ending and morality from decisions made) will decide the game outcome. I only have a few modules put in so far and most of the "story" parts cut down here to save space. I'm also getting an error saying there is more than one instance of overloaded function for the "whatToDo" module.

// ZombieGame.cpp : Defines the entry point for the console application.
//
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
#include <iostream>
using namespace std;
//These are function prototypes to declare the functions being used
void WakeyWakey();
void TwentyMinsLater(int);

[Code] .....

View 2 Replies View Related

C/C++ :: Program To Make CMD Stop Without Using Getch Function

Mar 30, 2013

Program in c++ that if i ran it the cmd window will stop without using getch statement and conio.h header file, or how ?

View 7 Replies View Related

C/C++ :: Make Resize Function For Matrix2 Class?

Aug 29, 2013

How can we write resize function for Matrix2 class; where this function need to use Protected data members of matrix1 class? Only setters are available in Matrix 1 class but there is no getter function in Matrix1 class !

class Matrix1 {  
Protected:
int ** data;

[Code]....

View 3 Replies View Related

Visual C++ :: How To Make A Shape Outside Of Main Function

Sep 9, 2014

I know how to define a shape (here, a rectangle) and attach it to a window in C++ as follows:

Code:
#include <Simple_window.h>
void cir() { Circle c(Point(100,100),50); }
int main() {
Simple_window win(Point(100,100),600,400, "test");

[Code] ....

But how to define a shape (say a circle by that cir() function which is) outside of the main() function that is how to create a circle inside of the cir() function and it returns that circle when I called it in my main() function so that I can attach it on the window win to be visible?

View 14 Replies View Related

C :: Srand Function Make New Numbers Every Time On Calling

Mar 6, 2015

How do i make the srand() function make new numbers every time i call it? Now it seems like it repeats its result over an over again.

Below is a program that should generate random numbers for 3 dices and print these out. But it prints out the same nr over and over.

Code:
#include <stdio.h>
#define MAX 100
int filler(int dice1[MAX], int dice2[MAX], int dice3[MAX]) {
int throws, nr;
printf("Define the number of throws");
scanf("%d", &kast);

[Code] .....

View 6 Replies View Related

C :: How To Make Main Function Only Allowed To Declare Variables And Functions

Mar 6, 2015

So I need to make a main function have no if/for/etc. statements so I need to move it to another function and call it in main. The problem is that it's a command line argument function so I'm confused on how it works. Here's an example:

Code:

#include <stdio.h>
int main(int argc, char* argv[])
{
printf("The program name %s", argv[0]);
if (argc == 2) {
printf("Argument supplied is %s", argv[1]); }
else if (argc > 2) {
printf("Too many arguments");}
else {
printf("One argument");}
}

How can i make this into two functions with main only declaring variables and calling other functions?

View 2 Replies View Related

C++ :: While Loop - Use Non-recursive Function To Make Triangle Number Sum Of All Whole Numbers From 1 To N

Jul 31, 2014

My while loop is the problem. I want to use a non-recursive function to make the triangle number the sum of all whole numbers from 1 to N.

#include "stdafx.h"
#include <iostream>
using namespace std;
int triangle(int t);

[Code] ....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved