C++ :: Grade Average Passing In Functions?

Sep 3, 2013

My average is failing but I played and played with it and I still keep crashing.

Code: #include <iostream>
using namespace std;
void getScore(int score[], int NumGrades)
{
cout<<"How many grades do you need to enter?"<<endl;
cin >> NumGrades;
cout<<"Enter the Students Grade(s)"<<endl;
for (int i=0; i<NumGrades; i++) {
cin >> score[i];

[code].....

View 9 Replies


ADVERTISEMENT

C/C++ :: Calculating Grade And Average?

Dec 10, 2014

Write a program to compute average grades for a course. The course records are in a single file and are organized according to the following format: Each line contains a student's first name, then one space, then the student's last name, then one space, then some number of quiz scores that, if they exist, are separated by one space. Each student will have zero to ten scores, and each score is an integer not greater than 100. Your program will read data from this file and write its output to a second file. The data in the output file will be nearly the same as the data in the input file except that you will print the names as last_name, first_name and there will be one additional number at the end of each line: the average of the student's ten quiz scores.

The output file must be formatted such that first and last names appear together in a left justified column that is 20 characters wide where the last name comes first, then a comma and a space and then the first name. Use your read string function to read each name separately and then put them together into a larger correctly formatted string before trying to output them. Each quiz score should be listed in a right justified column that is 4 characters wide, and the average should appear in its own right justified column that is 10 characters wide.

Note that if a student has fewer than 10 scores, the average is still the sum of the quiz scores divided by 10; these students are assumed to have missed one or more of the quizzes. The output file should contain a line (or lines) at the beginning of the file providing appropriate column headings.

This is how much I have so far:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
char* read_string(char* buffer, int max_size, FILE* fp);
int main(int argc, char *argv[]) {
FILE *fp_input, *fp_output;

[code]....

View 7 Replies View Related

C++ :: Add Additional Switch Statement That Allows For Passing Option For A Grade

Nov 21, 2014

Remove the break statements from each of the cases. What is the effect on the execution of the program?
Add an additional switch statement that allows for a Passing option for a grade of D or better. Use the sample run given below to model your output.

Sample Run: What grade did you earn in Programming I ? A YOU PASSED! an A - excellent work!

Rewrite the program LastFirst_lab44.cpp using if and else if statements rather than a switch statement. Did you use a trailing else in your new version? If so, what did it correspond to in the original program with the switch statement?

// This program illustrates the use of the Switch statement.
// The break statement causes all subsequent expressions to be executed as well, also known as "falling through".
// The trailing else statement acts just like the default section if none of the options from before work it gets "defaulted" to it.

#include <iostream>
using namespace std;
int main() {
char grade;
cout << "What grade did you earn in Programming I ?" << endl;

[code]....

how do you add an additional switch statement? i tried multiple times and i'm not sure if i don't understand braces enough but it didnt seem doable. also, I'm not sure what the teacher wants me to submit.

View 1 Replies View Related

C :: Calculate Final Grade By Adding 4 Numbers Minus Lowest Grade And Dividing By 3

Apr 7, 2013

I'm writing a program to calculate a final grade by adding 4 numbers minus the lowest grade and dividing by 3. My knowledge in c is not extensive I thought that a simple assigment operator would do the job but I'm getting a strange large numbers in the execution.

Code:
#include <stdio.h>
#include <stdlib.h>
main(){
int eg, g1, g2, g3, g4, fg, s1, s2, sg;

[Code] ....

View 4 Replies View Related

C++ :: Grading Scale - Determine Letter Grade Based On Numerical Grade

Apr 23, 2014

I have to accept the numerical grade and determine the letter grade that the user will receive. I have to use a grading table to determine the letter grade based on the numerical grade. The Letter Grade table is

A 90-100
B 80-89
C 70-79
D 60-69
F 59 and below

Here is the code

//preprocessor directives
#include <iostream>
#include <string>

//namespace statement
using namespace std;

//function prototypes
void getData (string& course, string& first, string& last, int& grade);

[Code] ......

As you can see, I am currently stuck on the determineGrade one

View 1 Replies View Related

C++ :: Program Should Input Each Student Grade As Integer And Store Grade In Vector

Jun 26, 2013

I get so close, and then it seems my brain shuts down ... I need to write a program that outputs a histogram of student grades for an assignment. The program should input each student's grade as an integer and store the grade in a vector. Grades should be entered until the user enters -1 for a grade. The program should then scan through the vector and compute the histogram. In computing the histogram, the minimum value for a grade is 0, but your program should determine the maximum value entered by the user. Use a dynamic array to store the histogram. Output the histogram to the console. For example, if the input is:

20
30
4
20
30
30
-1

Then the output should be:

Number of 4’s: 1
Number of 20’s: 2
Number of 30’s: 3

I can't quite get my output to look like that:

/* This program will display the histogram of student grades for an assignment */
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <conio.h>

[code]......

View 3 Replies View Related

C :: Convert A Number Grade To A Letter Grade

Feb 24, 2013

i'm having trouble with my c programming assignment. i'm trying to convert a number grade to a letter grade. I'm trying to Write a function (called: numToLetter) that takes as input a number from 0 to 100 and returns a character ( a single character ), based on the following: if the number is between 60 and 70 return Dif the number is greater than 90 return Aif the number is between 70 and 80 return Cif the number is between 0 and 60 return Fif the number is between 80 and 90, return B and i need to use the return statements to call the function like for example:

if (a > 90) return ('A');
elseif (a > 80)
return ('B');
elseif (a > 70)
return ('C'); else
return ('F');

how do if write my code with this function?

View 1 Replies View Related

C++ :: Calculating Average Using Two Different Functions

Mar 16, 2013

When I compile my code with g++ I get the error: constructor, destructure or type conversion missing before sum.

int sum(int,int);
void sum(int,int,int&);
main()
sum (v) // This is the line that the compiler is reporting the error occurs.
answer sum()
int main(){
int a=1;
int b=2;
int sum;

[Code] ....

View 12 Replies View Related

C :: Passing Into Functions

Feb 18, 2013

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.

Code:

#include <stdio.h>#include <stdlib.h>
#include <string.h>
#define MPS 10 //Max Part Size
#define MSS 10 //Max Supplier Size
}

[code]....

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).

View 7 Replies View Related

C :: Passing Arguments To Functions

Feb 4, 2013

Having a little trouble passing arguments to functions.

I wrote this simple program to get the hang of it but I'm quite stuck. I'm sure you will be able to get at what i want the program to do...

Code:
#include <conio.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <windows.h>

void menu(int HP,int Gold,int Armour);

[Code] ....

View 3 Replies View Related

C :: Passing Pointers To Functions

Feb 28, 2015

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.

Code:
FILE *file_check();
void word_search(FILE *);
int
main(void) {
FILE* check= file_check();
// word_search(check);

[Code] ......

View 6 Replies View Related

C :: Passing Variables Among Functions

Mar 6, 2015

I have this code where I am trying to retrieve the contents of the variable dev1 and dev2. for some reason when i compile and run I am getting 0 and 0.

Code:

typedef struct {
uint32_t x;
uint32_t y;
} sample;
void get_sample(sample *one)

[Code].....

View 9 Replies View Related

C :: Passing Arrays Into Functions

Nov 4, 2013

i have a program that works, but now I am trying to get function1() to work. What it has to do is bring in the array and populate it with random letters. I don't know much about functions.

Code:

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define maxrow 20 //defines maxrow as a constant of 20
#define maxcol 30 //defines maxcol as a constant of 30
}

[code]....

View 2 Replies View Related

C++ :: Passing Structs And Functions All In Same

Mar 8, 2013

I think i am getting confused with passing structs and functions all in the same...When I run through the program (it compiles), the functions that add coins do not add, but rather just replace an old value with a new one.

#include <cstdlib>
#include <iostream>
using namespace std;
struct coinbox {

[code].....

View 1 Replies View Related

C++ :: Passing Values To Functions?

Jul 29, 2013

I am trying to get some confirmation about how to pass to functions. If you want to assign default values to certain parameters, and have others defined inside the body of int main(), then the parameters which will have default values go at the end of the list. Is that correct?

i.e. The following code is wrong, because we cannot leave a black in the function call on the third line of the main function. However, if we switch the prototype to void Passing (int a, int c, int b = 1); and the function definition to void Passing (int a , int c, int b) everything will be okay and we can call the function as Passing (a, c).

In brief, we cannot do this EVER:
Passing( a, , c)right?
#include <iostream>
using namespace std;

[Code]......

View 4 Replies View Related

C++ :: Passing Types To Functions

Jan 12, 2013

I've got a game engine with a line-trace collision method which returns the first object it hits. I'd like to be able to pass it a class-type so that it can ignore objects of other types.

consider this pseudo-code:

Entity* TraceEntity( const Vec3f& LineStart, const Vec3f& LineEnd, const Type atype ) {
// check collision on entities, ignore entities of type 'atype'.
// return whatever it finds
}

I'd like to do this without template classes because it will result in a significant bloat in executable size every time I decided to trace for a new entity type (I've really developed a distaste for templates for this reason)

using type_info only checks for an object's deepest subclass, so it won't work for class C : public B : public A if I'm looking for classes of type B.

View 5 Replies View Related

C++ :: Passing Variables Between Functions

Jan 29, 2013

I need passing some variables between functions. Here is the first part of the code which does work.

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct CarType {
string maker;

[Code] ....

Now the book says to take the following program and add a member function to the CarType class which prints the values of all of its data members. Add two more data members which are relevant for cars. Add the use of these data members to the program (to the assignment statements for MyCar, to the operator prompt and input inside the getYourCar function, and to the print function you have created).

Here is my code. Whenever I run it, it takes my assigned variables in MyCar and prints those instead of the one which the user is inputting.

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
using namespace std;
struct CarType {
string maker;

[Code] .....

View 3 Replies View Related

C++ :: Passing Ifstream Object Between Functions

Mar 29, 2013

Code:
void lexer(ifstream& inputfile) {
string line;
getline(inputfile,line);

[Code] ......

I am trying to pass input file between two functions. The code compiles but immediately upon running the program, there is a "bad cast" run time error.

View 9 Replies View Related

C++ :: Passing Ints To Void Functions

Mar 19, 2014

At first i had my int variables in global scope however i cant do the so im trying to pass my variables from my main to the void functions but cant.....

View 1 Replies View Related

C++ :: Passing Structure Arrays To Functions?

Oct 31, 2013

Description: Use functions and structures to simulate storage in a warehouse

*/
#include <cstdlib>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
struct Bin {std::string name; int Quantity;}; //create a structure for "Bin"

[code].....

I keep getting a linker error on every function. what am I doing wrong?

View 2 Replies View Related

C/C++ :: Passing Structure Addresses To Functions

Mar 20, 2014

What this is, is a more recent assignment and my question is if my errors are directly related to passing structure addresses to functions. I've tried several syntax variations at the beginning of my loops such as this one:

while (choice != "Q" || "q")

But the loops will not run since I introduce polar to rectangular and the choice element. My last working code was rectangular to polar and all of it worked fine.

#include<iostream>
#include<cmath>
using namespace std;
//structure declarations
struct polar
{
double distance; //distance from origin
double angle; //direction from origin

[Code] ....

View 14 Replies View Related

C++ :: Ifstream Object Passing To Functions

Feb 29, 2012

I am having an issue with passing an ifstream object to functions. Here is the code:

Code:
#include <fstream>
using namespace std;
void otherfunction (ifstream *ifs) {
...does stuff, like ifs->open(), then reads from the file...
}

int main () {
ifstream ifs();
otherfunction(&ifs);
}

Here is the error message:

Code: error: cannot convert ‘std::ifstream (*)()’ to ‘std::ifstream*’ for argument ‘1’ to ‘void otherfunction(std::ifstream*)’

Why can't I do that? What does "ifstream (*)()" even mean? And I don't want to change the structure of the program. I have reasons for declaring the ifstream object in the main function (because there are actually two functions that need access to the ifstream object -- neither of which is working).

Also, if I change the main function to be this instead:

Code:
int main () {
ifstream ifs();
ifstream *ifsptr = &ifs; //EDIT 2: forgot the ampersand
otherfunction(ifsptr);
}

I get the same error as above. However, if I change the main function to this:

Code:
int main () {
ifstream *ifsptr = new ifstream();
otherfunction(ifsptr);
}

I get all kinds of crazy errors about "undefined symbols for architecture _____". Here is the actual error message from my program (parseArgs is the real name of otherfunction)

Code:
Undefined symbols for architecture x86_64:
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in cchumGBV.o
"std::ios_base::Init::~Init()", referenced from:

[Code] .....

View 12 Replies View Related

C++ :: Passing Vectors To Functions As Arguments By Reference And Value

Mar 12, 2014

I have a program that is working very well when I pass C++ vectors as arguments to my functions by reference, but I get some compilation errors when try to make a modification. I am also posting the entire program and its output below. so that you can see what is going on. I have commented out the line that causes an error.(Some of the indentation that got corrupted when I copied the code to the browser.)

This program basically calculates the coefficients of a least square polynomial and then evaluates this polynomial at artificial data points and verifies that this actually reproduces the original data within reasonable floating point error.

The function that computes the coefficients of the least square polynomial is Code: vector<double> LSPVecValued_GSL( const int, const vector<float> &, const vector<float> &); and as you can see it returns a vector by value, and this vector contains the coefficients of the least square polynomial.

There is also a function that evaluates this polynomial by accepting a vector argument by reference : Code: float evaluate_polynomial(double, vector<double>& ) ; I have also created another version of the evaluation function which accepts the same vector argument by value: Code: float evaluate_polynomial_ByValue(double t, vector<double> vec_a) ; In the program I call the first evaluation function (whose vector argument is passed by reference) by first using an intermediate vector variable containing the coefficients, and then I pass this vector as an argument to the evaluation function, as follows:

Code:
vec_a = LSPVecValued_GSL( deg, vec_x , vec_y);
for(int j=0; j< n ; j=j+20 ) {
cout<<"x["<<j<<"] = " << vec_x[j] << " ,y["<<j<<"] = " << vec_y[j] <<" , p(x["<<j<<"]) ( EVALUATED FROM REFERENCE) = "
<< evaluate_polynomial( vec_x[j], vec_a) << endl; // This version works without error

[Code] .....

As you can see above, I am also able to call the second evaluation function (the one whose vector argument is passed by value) directly by plugging in the function LSPVecValued_GSL"(...)" and this works without error, and this is a one step process, only one line of code is involved.

However, I get a compilation error (line number 12 that I have commented out above) if I try to plug in the function "LSPVecValued_GSL(...)" into the first evaluation function that expects a vector argument by reference. I tried to put a "&" in front ofLSPVecValued_GSL but this did not fix the bug.

What syntax is appropriate to use the first evaluation function (which accepts a vector argument by reference) if I want to plug in the vector-valued function LeastSquarePolynomial_GSL directly in the the first version of the evaluation function which expects a vector argument by reference?

View 14 Replies View Related

C++ :: Passing Both Private And Public Variables-functions?

Mar 6, 2015

How to properly pass both private and public variables/functions from one class to another?

View 3 Replies View Related

C :: Using Typedef Struct And Passing Pointers To Functions

Mar 3, 2013

I am having problems with passing my values through functions.

Here is my code:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void test(int**);
void test2(int**);

[Code]....

View 8 Replies View Related

C++ :: Passing Char Arrays Between Functions Of Same Class

Nov 16, 2013

I'm having trouble with passing a character array between functions of the same class. I have a function, buildGraph, that calls function getNextLine. The getNextLine essentially just retrieves the next line of an input file and stores it into a "char line[80]". However when I try to use "line" in my buildGraph function, it has nothing in it.

Here's my code:

Class
#define NUMNODES 10
using namespace std;
#pragma once
class Prog3Graph

[Code] ....

View 4 Replies View Related







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