C++ :: Displaying Average For Each Entry

May 3, 2013

I have to display an average for each student that is entered ....

void StudentData::displayAverageScore() {
double totalScore = 0;
double totalEx1 = 0, totalEx2 = 0, totalEx3 = 0, averageScore = 0;
for(int i = 0; i < entries.size(); i++) {
totalEx1 += entries[i].getEx1();// accumulate totals
totalEx2 += entries[i].getEx2();
totalEx3 += entries[i].getEx3();
if(totalScore != 0) averageScore = (totalEx1 + totalEx2 + totalEx3) / 3; // don't divide by 0
cout << "Average Score For Exams: " << setprecision(1) << fixed << averageScore << endl << endl;
}
}

View 7 Replies


ADVERTISEMENT

C++ :: Displaying Maximum / Minimum And Average Temperature

Dec 31, 2014

I am given two month's data (Max, Min, Ave) for every day in that month.

The task is to display all 3 of that data for any selected day in that 2 months.

View 3 Replies View Related

C :: Print Correct Normalized Value / Average And Values Above Average

Nov 14, 2013

I must write a function that has a one dimensional double array and the number of values in the array as its arguments. Normalize the values. I must also print the maximum, minimum, average and numbers of values above the average in the array.

The equation that computes the normalized value from a value x is:

Normalized x= (x-min(array))/(max(array)-min(array))

My code does not print the correct normalized value, average and values above average.

Code:
#include <stdio.h>
int findMax( double array1[], int num_elements) // This function computes the maximum value of the array
{
int i, max=-32000;
for (i=0; i<num_elements; i++)

[Code] .....

View 5 Replies View Related

C++ :: Average Negative / Positive Numbers And Total Average?

Nov 18, 2013

I am trying to average the negative numbers and positive number and of course the total average.

This will read in a list of n values, where n is not known ahead of time. The number of values read into the array will be saved in n.

vector<int> readList() {
std::vector<int> result;
ifstream inFile;
inFile.open("setA.txt");
for (int x; inFile >> x; ) {
result.push_back(x);

[code]....

array is a one-dimensional array of integers and n is the number of elements in that array that contain valid data values. Both of these are input parameters to the function. The function must calculate 1) the average of the n integers in array, storing the result in ave; 2) the average of the positive numbers (> 0), storing the result in avePos, and 3) the average of the negative numbers (< 0), storing the result in aveNeg.

void avgs (std::vector &array, int &ave, int &avePos, int &aveNeg) {
int sum = 0, pos_sum = 0, neg_sum = 0, pos_count = 0, neg_count = 0;
for (auto i : array) {
sum += i;
if (i > 0) { pos_sum += i; ++pos_count; }

[code]....

View 1 Replies View Related

C++ :: Adding Entry To Map?

Feb 5, 2013

I have the following code in sourceFile.cpp. functionA() is first called and inserted entires for key1, key2 and key3. Then functionB() gets called to use the vectors for the 3 keys. I want to free all memory after exiting functionC(). Among the three ways to put an entry into the map for the 3 keys, which is correct / better?

Class ClassA { ... }
ClassA *key1 = new ClassA();
ClassA *key2 = new ClassA();
ClassA *key3 = new ClassA();

[Code]....

View 2 Replies View Related

C/C++ :: How To Create Entry Verification

Nov 21, 2014

I have an assignment to create a program that will display the duplicate numbers that were entered by a user. I have the code finished and I have covered the basic requirements of the assignment. However, during my testing I found that if I enter anything other than a whole number (i.e. char or float) the program will run out and exit. I would like to add a little code to verify that the user has entered a whole number. I cannot seem to get this to work though. I have written other codes that verify if a number is above and below a certain value, I just do not know how to look for a certain type of entry.Here is my code:

int main() {
int number[20];
int duplicateNumber[20];
int i, j, k, counter = 0;
// Get number input from the user
for (i = 0; i < 20; i++) {
printf("Please enter a whole number %d: ", (i + 1));

[Code]...

View 3 Replies View Related

C++ :: Adding Entry Into Array?

Aug 6, 2014

My program is suppose to be as a virtual phone book that allows you to add,search, display names and numbers.

At the beginning you are able to add up to 10 entries and then from there the program goes to a menu where you can add more entries, search etc.

My problem is that I am unable to add an entry into the existing list of names/phone numbers.

Example: At the beginning I add Joe,Albert,Barry. It sorts them into Albert, Barry, Joe (good so far!)

However, if I choose to add another entry (Carl) it becomes Barry,Carl,Joe.

The functions I am using to add entries are: GetEntries (for initial entries) and Addentries for more entries during the main program.

*******************************COPY OF CODE**********************************

#include <iostream>
#include <string>
using namespace std;

[Code].....

View 5 Replies View Related

C++ :: Makefile Only Executing First Entry

Mar 15, 2013

Why this makefile only executes the first entry, compiling only the first program listed?

###########################################################
#
# Simple Makefile for Operating Systems Project 2
#
###########################################################
vowcon:
g++ -o vowcon vowcon.cpp -pthread
osproj2c:
g++ -o osproj2c osproj2c.cpp -pthread
osproj2b:
g++ -o osproj2b osproj2b.cpp -pthread
osproj2a:
gcc -o osproj2a osproj2a.c -pthread
clean:
rm osproj2a osproj2b osproj2c osproj2d vowcon

View 7 Replies View Related

C/C++ :: While Loop To Stop After Third Entry

Jul 6, 2014

Having multiple issue trying to get a while loop to stop after the third entry.

#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
using namespace std;
int mySequentialSearch() {
int value;
string line;

[Code] .....

I am just working on the while loop right now. Then the function after I get the loop working.

View 10 Replies View Related

C :: Secure Entry Keypad Simulator

Feb 15, 2015

We've been tasked write a code which would mimic a secure entry keypad.. Only recognising the digits 0-9 for the passcode, and non-numerics S (start again) C (clear last digit) and E (enter) for the control. All other key strokes are to be ignored.

The passcode has to be <10 digits and represented on the screen by "****", with any keystrokes >10 ignored.
The valid passcode being 4 digits (1234).

With 3 attempts to get the correct pass code, after each fail attempt as please try again message show, where after the 3rd attempt a specific message is displayed and an alarm sounds..

View 13 Replies View Related

C :: The Last User Entry In Loop Fprintfed Twice?

Apr 13, 2014

Still working on my first homegrown C program design . The function basically allows the user to enter a list of classes and grades and saves the list to a file to be used later in the file. The function compiles and runs through without error except for the fact that it always prints the last user entry to the *profilep file twice. Just as a note, the scanchar function is one I made to scan in one character and an end of line character to throw away the end of line char before I learned about %*c about 30 minutes ago...

Also I haven't much bothered to strengthen the function against crazy user input but I have heard using fgets and sscanf in conjunction can replace scanf and protect against weird user input. How to apply this within the program.

Code:
// creates a new profile and prints it to the profile file.
void newprof(FILE* profilep, const char *allclasses[ABBR_SIZE]){
int c, checker, counter;
int i, a;
char prof[MAX_PROF][ABBR_SIZE];
char grades[MAX_PROF][3];

[Code] .....

View 1 Replies View Related

C++ :: Error 453 - Can't Find DLL Entry Point

Nov 7, 2013

Using VC++ 2010 Express. I am creating a dll to export a simple Multiply function so I can use it in Excel/VBA

These e are the steps I am following :

. Create a Win32 C++ Project and give a name. For example: CallDllFromVBA
. Select the DLL option in the Wizard and click Finish
. In the CPP file (here CallDllFromVBA.cpp), add the following code

#include "stdafx.h"
int _stdcall Multiply(int x, int y) {
return x * y;

[Code] ....

The Build output show everything is ok as follows :

CallDllFromVBA.cpp
CallDllFromVBA.vcxproj -> c:documents and settingsadministrateurmes documentsvisual studio 2010ProjectsCallDllFromVBADebugCallDllFromVBA.dll
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

In VBA, I insert a module and add the following code:

Declare Function Multiply Lib _
"c:documents and settingsadministrateurmes documentsvisual studio 2010ProjectsCallDllFromVBADebugCallDllFromVBA.dll" _
(ByVal x As Long, ByVal y As Long) As Long
Sub test()
MsgBox Multiply(2, 4)
End Sub

When I run the Test sub I get the error: 453 - Can't find dll entry point

I also opened the CallDllFromVBA dll with Dependency walker and I can't find the Multiply export function - In fact, the dependency walker doesn't show any function exports at all for the CallDllFromVBA dll !

View 2 Replies View Related

C/C++ :: Conditional Multiple Entry Points?

Nov 16, 2014

I'm playing with my final year project, building a game boy emulator in C, and I wanted to try out something to streamline my code base. I'm building against Win32, GNU C and Googles Native Client.There are no platform specific headers or functions in use. What I'm trying to do is have a file that conditionally includes the entry point (so _tmain for Windows etc) based on a preprocessor directive being set/not-set.

[note] I realise I could write both entry point classes in one file and use the preprocessor directive in there, but it's not as neat as a single file calling in one or the other. I figure this should work because I can conditionally include headers for Win/NaCl (providing the signatures match, of course).

View 3 Replies View Related

C++ ::  Passing A Polymorphic Array Entry

May 31, 2013

I'm having an issue during the linking stage of the .exe during compile time, and it's because of a call to a function with a polymorphic parameter.

//here's how the classes are setup
class grandpa {};
class mom public grandpa{};
class dad public grandpa {};

[Code]....

dad has sons in the vector and mom has daughter in the vector. What I want to do is have a function that can accept either of these vectors as one parameter like so: void func(const grandpa* aObject);

Finally, I have an error when I pass an object to the function like so: func( d[0] );

View 1 Replies View Related

C/C++ :: Modifying Row Of Matrix Based On Zero Entry?

Nov 19, 2014

Here is the problem:

Write an algorithm such that if an element in an M * M matrix is 0, its entire row and column is set to 0.

Your function prototype may look like the following:

void setZeros ( int size, int arr[][size] );

Heres what I have:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 3
void scan_matrix(int arr[][SIZE]);
void print_matrix(int arr[][SIZE]);
void initiailize_matrix(int arr[][SIZE]);
void set_zeros(int matrix[][SIZE]);

[code]....

I'm not sure on how to scan zero for this code and I have bolded some comments that I am having trouble with as well.

View 1 Replies View Related

C# :: How To Add Data Entry List In Array

Jan 29, 2014

I'm learning C# and having fun and I've been practicing by working on this little data entry console application. Basically the user inputs first name, last name, age, gender, employee id, then I ask the user if he/she wants to add another entry, if yes then loops back at the top, and if no, it prints out the amount of entries added. The issue I'm having is that the entry list is never kept or stored when adding another entry, it replaces what was entered before which is not what I'm looking for. I don't know how to stuff one entry list information seperately in an array so that I can print out which ever entry the user decides to choose once he/she is done adding entries. Is there a way to make this work?

Here is my program code:

using System;
namespace Ch02_Exercises_12
{
class Program {
static void Main() {
string firstName;
string lastName;
string input;
sbyte age;
char gender;

[Code] .....

View 4 Replies View Related

C/C++ :: Prevent Duplicate Entry When Insert Age

Oct 17, 2014

I created program that insert employes data and then print their data but never accept duplicate age if user entered duplicated age prompt him to enter another age (age must be unique)

Here is my code

#include<conio.h>
#include<stdio.h>
#define size 3
struct emp {
int age,overtime,dedcution,netsal;

[Code] .....

View 1 Replies View Related

C++ :: File I/O - Entry Point For Console Application

Aug 1, 2013

I am stuck in visual studio 2010 file I/O ... i placed file1 file2 using the following program under VS2010/projects/projectname/file, file1 and also in debug also once......I am actually using cmd line arguments in debug mode

Code:
// feof files.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main(int argc, char* argv[])

[Code] ....

I dont think in C++ forum the printf will do any problem...when i run the program it says "cannot open source file" and a window appears saying"Debug assertion failed"....and other details such as Expressionstream!=NULL).perror

View 4 Replies View Related

C :: DLL Error - Procedure Entry Point Could Not Be Located

Oct 22, 2013

I hope that this isn't an elementary question to you more experienced people, but I am having some trouble with my .DLL file. I haven't ever had a problem with compiling and linking it with my main project before, but it appears now some sort of problem has started. The message that appears is :

I have no qualms with posting my .DLL source, as it is not particularly long or complex. It seems the problem functions are the last two I've added ( load_sound( ) and play_sound( ) ).

Here is what I'm linking it with :

Code:

-------------- Build: Debug in game (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -shared -Wl,--output-def=binDebuglibgame.def -Wl,--out-implib=binDebuglibgame.a -Wl,--dll -L"F:FBLARandom gamegame.dll.sourcegame" objDebugconversion.o objDebugprojectile.o objDebugSDL_utility_functions.o objDebug ime.o -o binDebuglibgame.dll -lSDL -lSDL_mixer
Creating library file: binDebuglibgame.a

Output size is 49.10 KB
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings (0 minutes, 0 seconds) projectile.c :

Code:
#include "game.h"
#include <stdio.h>
#include <stdlib.h>

/* ******************************************************** */
/* ********* create( ) ********* */
/* ******************************************************** */
/* - Allocates one node of type projectile on the heap, */
/* and returns its' address */
/* ******************************************************** */

[Code] ....

View 6 Replies View Related

C++ :: Control Execution Of Code Block By Entry

Apr 25, 2013

I have a program including several code blocks in the following simplified structure:

int main() {
// block A
if(a > 0) {
}

// block B
if(a > 1) {
} }

Block A and B should be executed separately, according to entry from keyboard. For example, if entry "1", block A will be executed and block B will be ignored; if entry "2" the inverse will happen.

I can control the execution of these two blocks through macro but the code will be separated during compilation. But is there a way to control them without using macro?

View 4 Replies View Related

C Sharp :: How To Show Only Current Entry In DataGridView

Apr 12, 2012

When I am filling a Application form and save this Application form Entries in database it saved successfully but below Application form in DataGridView How to show only current Entry row; There is not show a previous Entries in DataGridView?

View 1 Replies View Related

Visual C++ :: Voting Bot - Every 50th Entry Wins?

Oct 22, 2014

I am supposed to write a simple voting program as a semestral project. There are about 30 people in our class and we are going to compete with our voting bots against each other (+ some random traffic bots). The principle is simple - every 50th entry (vote) wins.

We are given the results website, where we can see winners and current vote count. Nothing more. Oh, and everybody has only 50 votes (except traffic bots).

I have already written voting function, function to extract the number of votes from the results website, function to find out server response time and made some voting bots to simulate traffic on the server (voting every 2s, 4s,..., randomly). But now I got stuck with the algorithm which should decide, when to vote.

I guess that most people in my class are going to use something like "if there are more than 45 votes and less than 50 -> vote" approach.

I was thinking about measuring average latency and average traffic for first few rounds but there are going to be many 'outliers' just before the 50th votes and based on my bots, the latency is going to drop rapidly (my 2s bot voted 10s late because the server couldn't handle the load). I just don't see the connection between vote count and server response and how to measure the right voting moment accurately.

View 3 Replies View Related

C :: Why Print Entry Function Is Not Printing First Element At Phonebook

Feb 20, 2013

I have 2 function (AddEntry & PrintEntry)

I don't understand why the "PrintEntry" function doesn't print the first element at "phonebook[x].Name".

Code:
int counter=0;
void AddEntry(phone phonebook[]) {
counter++;
printf("Enter first name:
");
scanf("%s",phonebook[counter-1].Name);
printf("Enter last name:

[Code]...

Code:

int main(void) {
phone phonebook[20];
int i;
for (i=0;i<4;i++) {
AddEntry(phonebook);
PrintEntry(phonebook);
}
return 0;
}

View 3 Replies View Related

C++ :: Wrong Check For Batch Code Entry End Condition?

Jan 13, 2015

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int check_Pythag(int DIMA, int DIMB, int DIMC) {

[Code] .....

View 4 Replies View Related

C++ :: Program To Make Shopping List - One Line Per Entry

Jan 9, 2015

OK I'm making a simple program to make a shopping list. I would like the program at start up to load the previous shopping list that was saved as a text file. The format is one line per entry which consists of the category or Isle, and the item description. Here's an example:

3 Dog Food
Produce Sweet Onions

I reading the first word, and then I want to read the rest of the line which may have more than one word... the problem is my code hangs... or goes into the old infinite loop. It doesn't see the end of file.

Here is my code:

void
addItemsFromFile(vector<item> &shoppingListVector) {
string word;
char buf[30];
if (fileExists("shoppinglist.txt"))

[Code] .....

View 3 Replies View Related

Visual C++ :: Address Of Entry Point In Binary File?

Dec 28, 2013

How can I find/calculate the address of the entry point for an exe binary file using its PE32 optional header?

I have added a picture, where it says (file addr) thats the address I want to know how to calculate

View 2 Replies View Related







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