C :: 3 Students Sharing Their Meals - Settle Bills Equally
Sep 28, 2013
There are 3 students (0=John, 1=Peter, 2=William) sharing their meals. Who does the cooking, does the shopping and pays for the bills. End of the month they sum it all up and settle the bills equally. Who must pay the most is outputted at the top, while the person that collects most is at the bottom. Students that have to pay the same amount are listed in the same order as they are ordered in the input. (receiving same amount, the same). Total of the settlement are rounded to whole cents. Sometimes they loose a cent, sometimes they gain one.
So I started making a plan what the program is supposed to do. Pen and paper:
1. Sum of the total amount from all the meals.
JohnPaid+PeterPaid+WilliamPaid=Total
Total / 3 = FairShare
calculate difference of all three the students
if JohnPaid == FairShare
print John receives 0.00
if JohnPaid > FairShare
print John receives difference
if JohnPaid < FairShare
print John pays difference
etc. (same for Peter and William)
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
/* type definition of student */
typedef struct student {
int who; /* 0=John, 1=Peter, 2=William */
float paid; /* amount that student paid */
[Code] .....
Example in/outputs:
<0 39.85>
<1 30.83>
<2 35.43>
Peter pays 4.54
William receives 0.06
John receives 4.48
<1 106.32>
<0 88.14>
<2 88.14>
John pays 6.06
William pays 6.06
Peter receivers 12.12
Looking at this code, I see a lot of global (general) variables. Do I need to adjust this skeleton code I received or should I just add code?
View 6 Replies
ADVERTISEMENT
Aug 15, 2013
Code to accept the information of 5 students and display the information of first 3 students......
Code:
#include<stdio.h>
main() {
struct stud {
char name[20];
int rollno;
float per;
char grade;
[Code] ....
View 6 Replies
View Related
Nov 9, 2013
So, as the title says, I'm trying to eliminate false sharing, or, eliminate sharing writes between threads with TBB. The question is how.
Normally I'd make an array whose size is equal to the number of threads, then locally write to a local variable and update the array only at the end of the thread.
But, of course, I cannot seem to get either thread id or total number of threads TBB uses. I found a reference to tbb::enumerable_thread_specific, which as I understand, is supposed to work for exactly this. But as soon as I added it, it hurt performance by ~60% instead of making it better.
How to do this properly? You don't really need to look so hard on how the algorithm works (I don't know either). I know it's not quite right right now due to race conditions, but I'll fix that later. I used a reference implementation that I copied™, and my task is to parallelize it.
The parts where the problem is right now is in red (of course, it's not all problems; it's only a subset of them).
Code:
#include <iostream>
#include <vector>
#include <fstream>
#include <ctime>
#include <algorithm>
[Code] ....
View 11 Replies
View Related
Aug 30, 2013
The problem is I have a function which sets some variables and I want to access the variables, but myfunc() is nested too deeply for me to pass a data structure all the way down and to return all the way up. The functions reside in different files. I'm not allowed to use extern structs (i.e. a global variable).
How to use a class and instantiate it in myfunc(). My solutions are:
- using the singleton class method
- static variables and function residing in the class (but I'm suspicious of this way. seems like it's just class variables masquerading as global variables.
View 2 Replies
View Related
Mar 16, 2014
my goal:
have 1 program handle the UI
have that program store variables to a DLL
have the 2nd program grab the stored variables to reform some number crunching, without interfering with the UI program, and once done, have it drop the answers back into that DLL, so that the UI can grab it when it's ready.
I have made the 2 programs, + dll
What I've Achieved:
the first program accesses the dll, and loads up a variable (and stays connected to the dll, so that the Dll instance doesn't reset)
I've gotten the DLL to output the variable to make sure it's received it, and stored it to it's own global variable.
the second program connects to the dll successfully, but when it tries to retrieve the data, it returns 0's (NULL's)
My research:from what I've read, so long the dll is connected to a program, all additional programs will attach to the same instance.
how do I make the global variable in the dll be accessible to both programs? (without resorting to saving it to the HDD Idealy)
View 7 Replies
View Related
May 22, 2013
I am just wondering if it is possible to send a project to someone via email - In a simple way, almost like you would install software from the internet, maybe a setup file, or something. The compiler I use "Dev C++" creates a .cpp file and an executable. Unfortunately, I cannot send that .exe file. How would you recommend sharing a program?
View 5 Replies
View Related
Nov 4, 2014
I've changed up my code to the retail checkout WFA I am trying to make. I have an item list filled with objects of the now globally accessible 'Item' class, but I'm having trouble.
Essentially, I want to send an object of the item class chosen from a dropdown menu to form2, where I will fill in certain blank attributes with data entered in form2's text boxes and comboboxes. The problem, it seems, is I need another itemlist in form2 that will hold the object being passed to form 2, so I can then pass all the information to textboxes on form3 (the receipt/review page). It's been more than a year since I coded with C#, and I've forgotten quite a bit. I was also not able to find any tutorials on building an item list without an associated combobox or droplist, which is what I need.
This is my item class (minus most of its properties so the page doesn't stretch).
class Item {
public string prodName;
public string fName;
public string lName;
public string ccNum;
public string ccProv;
public string shipAddr;
[code] ....
For anyone who didn't see my last question, I'm in a User Interface Design class, not a C# class. I know this probably isn't the best code out there, but for my purposes the program just needs to compile beginning to end and pass the data like it should.
View 1 Replies
View Related
May 13, 2014
I need a program. I need to add the data of five students their mobile number,address,sec, and deprtmnt....program should be like:
s.no name address phone
1.
2.
3.
4.
5.
And starting should be like press 1 to insert data
press 2 to save data
press 3 to find data
press 4 to quit
View 5 Replies
View Related
Mar 10, 2015
I have a form with 2 text boxes (Email and Password)
The user fills in the text boxes and clicks on the Log in button. The code behind the log in button does the following, First connects to a table (Users) in phpmyadmin. Next runs a SQL query (SELECT * FROM `users` WHERE Email = '" + sEmail + "' AND Password = '" + sPassword + "'") sEmail being the variable created from the text entered in Email text box and the same for password.
Next if the record count == to 1 it opens up the main menu form and if the record count == 0 it fails and the user does not get to the main menu.
All of the above is fine and working however what I want to do is take over a variable from the log in form to the other forms.
The code is below for the sign in button as all my code is behind that (I think this may be where I'm going wrong).
public partial class WelcomeForm : Form{
public static string connStr = "server = localhost; " +
"database = ppw5; " +
"uid = James; " +
"pwd = buster;";
[Code] .....
And the Main menu form where I'd like to take a variable over with me, lets assume the variable is the UserID from the database table that I pull from the dTable I created.
public partial class MenuForm : Form {
//Call the CloseProgram class and create a new method called ClassClose.
CloseProgram ClassClose = new CloseProgram();
WelcomeForm User = new WelcomeForm();
public MenuForm() {
InitializeComponent();
[Code] .....
View 7 Replies
View Related
Oct 30, 2013
Code:
#include<stdio.h>
int calcAbvAvg(int marks[10], int avg) {
int students = 0;
int i;
for(i=0;i<10;i++)
[Code] .....
I suck at function and linked list. The only problem i am having in this question is the function calcAbvAbg() not working! I want that function to display the students who are above and below average!
View 4 Replies
View Related
Feb 28, 2013
I have to search an array of struct students on the basis of their first names, last names and roll numbers .. so far i am done with the input of the student first , last names and roll numbers . I have problem in searching the array ..
Code:
#include <iostream> Code: #include <string>
using namespace std;
struct Student {
string FirstName ;
string LastName ;
[Code] ....
View 5 Replies
View Related
Apr 12, 2014
So here I have a program that is supposed to basically sort out who passed and failed. I am currently stuck on the switch statement, I'm trying to count how many students received an A, B, C, etc.
Here's what I have so far:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void printIdInfo(ofstream &fout);
void printColumnHeaders(ofstream &fout);
[Code] ....
View 1 Replies
View Related
Feb 20, 2013
I need to write a program on that language. I start with the explanation: The program has 3 tasks:
First: User can add the First Names, Second Names, Third Names and the Marks of a students.
Second: The program can calculate the Avarege Marks of the students.
Third: To show the students that have marks more than 5.50.
View 1 Replies
View Related
Nov 29, 2014
I have learnt about string class, file I/O and pointers. Now I am asked to write a program that includes the above topics, basically testing the ability to use dynamic arrays.
I've got 2 documents, namely "Students.txt" and "EnrollRecords.txt". "Students.txt" includes 40 students' info, which are university ID, programme names and their names. These 40 students are all BEng but from different departments.
E.g. 20141129 BEng(Civil) Tom Jerry
"EnrollRecords.txt" includes 166 data, which are course codes, university ID, respective scores in the test and GPA. In this document, the same student can have several scores of different courses' tests. So their uids repeat in it. And this document only contains the data of the Department of Computer Science. So students exist in the "Students.txt" may not exist in this document.
So my task is that the user enter a name (e.g. John), then the programme will know to find John and his uid, and get all the GPA of the courses that he has taken to calculate the average GPA.
E.g. 20147777 BEng(CompSc) John David //this is a John we are looking for in the "Students.txt"
//line 15 COMP1220 20147777 90 4 //so we find 3 courses in "ErollRecords.txt" that John has taken
//line 50 COMP1500 20147777 85 3.3
//line 88 ENGG2012 2014777 70 2.3
The programme should display :
20147777 3.2
To able to do anything for this task, I am asked to define 4 struct types:
struct Student {
int uid;
string programme;
string name;
[Code] ....
So now I am going to write a function queryD(Database d, string searchName) and any necessary functions in it. I am able to do the search part,
void queryD(Database d, string searchName) {
for (int i = 0; i < d.numberOfStudents; i++) {
if (d.students[i].name.substr(0, searchName.length()) == searchName) {
match_uid(d);
[Code] ....
But I struggle in how to match the uid in "Students.txt" and "EnrollRecords.txt" . Because there are repeated data for the same student in "ErollRecords.txt". So how am I gonna be able to match the uid and do the calculation? I get stuck in the for loop part...
View 1 Replies
View Related
Feb 14, 2015
Write a C++ program to output information for three students. The information stored in your program contains student’s first name, middle name, last name, and test score. The following shows the information for the three students, where test score is in the int type.
John Jacob Smith 78
Mary Jane Weems 82
Dave Joe Dale 61
Your program should declare three named string constants for the three students. Each constant contains the student’s first name, middle name, and last name. You may use three int variables to hold values for the three test scores. The first name, middle name, and last name of a student are then extracted using the substr() function shown in class. Your program should also compute the average (in floating-point number format) for the three test scores. The average score computed should be printed to the screen with 2 digits displayed after the decimal point.
The following shows the output from the program. Note that all the output is left-justified with 15 character positions reserved for each.
first name middlename lastname testscore average
John Jacob Smith 78 73.67
Mary Jane Weems 82 73.67
Dave Joe Dale 61 73.67
View 1 Replies
View Related
Jun 27, 2014
I need to create a program that continuously records data until the user enters '0'
The data that I read in is the student's last name, the year of the student (1-4), the major, the gpa, and the advisors name. I then need to print out how many students are in each year (1-4), the number of students each advisor has, the average gpa for each major, and so on. This is what I have, but I am stuck and think that I might be headed the wrong direction because the only thing working is the loop (not my gpa test calc).
//This program displays information pertaining to students
#include <iostream>
#include <string>
using namespace std;
int main () {
int studYear;
double average, studGpa;
string studName, studMajor, studAdvisor, complete;
[code]....
View 2 Replies
View Related
Jul 24, 2014
I can display the highest and lowest score but I can't display the number of students who got the highest and lowest score.
int h=array[1];
int l=array[0];
int m=0,n=0;
for(int z=1; z<=20; z++) {
if(array[z]>h) {
h=array[z];
[code]....
this should be the output
12 students got the highest score of 45
8 students got the lowest score of 1
View 2 Replies
View Related
Feb 27, 2015
//USG ELECTION
//Voting Program
#include <iostream>
[Code]....
View 6 Replies
View Related
Feb 20, 2014
I'm working on a program that shows all the students enrolled in certain courses.
This is what the correct solution is supposed to output:
enrollmentReport.exe sections0.dat enrollment0.dat
Undergraduate enrollments: 1
Graduate Enrollments: 3
CS 355
23272:Line, S.: 1 students
Squyres, Kristen
CS 571
22000:Caro, Virgil: 2 students
Arnold, Hayley
Aiken, Roberto
22002:Caro, Virgil: 2 students
Belur, Shirley
Aiken, Roberto
This is the output I get:
Undergraduate enrollments: 0
Graduate Enrollments: 0
CS 355
CS 571
I've included all the source code in an attachment. The trick is that I can only modify the section.h and section.cpp
course.zip (523.39K)
View 5 Replies
View Related
Apr 25, 2013
I am doing a c project .it is a system that stores the name of txt format reports made by students and opens them.
View 1 Replies
View Related
Jan 18, 2014
I need to sort these students based on their test scores.
My biggest problem is with my sort function. I am not sure of the syntax to call the items the proper way. I also don't know how to call the function properly as I know that i can't pass a int to a struct. Also not sure about the z malloc. Just threw that one in there.
Code:
struct student{
int id;
int score;
};
void sort(struct student* students, int n){
/*Sort the n students based on their score*/
[Code] ....
View 5 Replies
View Related
Jan 17, 2014
This is the program below..can you spot the errors in it.. I am getting lots of errors...!!
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct student {
char name[10];
int rollnumber,result
float m1,m2,m3,total
[Code] .....
View 12 Replies
View Related
Apr 18, 2013
Trying to write a program that calculates a students grade based on how many assignments have been graded. I am using a switch case since there is a total of 5 assignments, however when I enter case 1, and enter in how many I got out of 100, it just closes the program it doesn't go to the next part.
#include <iostream>
using namespace std;
char calculategrade(int total);
int main() {
// local variable declaration:
char input;
[Code]....
View 6 Replies
View Related
Feb 28, 2014
Q.1 Write a program to store marks obtained by 50 students. Initialise the array having passed to a function initilise() having passed the array as parameter. Write another function which should take this array as parameter and return the highest score from the array. you have to write the proper function call, prototype and definition for each function.
And this is the program which i wrote and got errors: -
#include<iostream.h>
#include<conio.h>
#define s 50
void init(int m[s]);
void display(int m[s]);
void find_max(int max, int m[s]);
void main(){
clrscr();
int max;
[code]....
View 1 Replies
View Related
Oct 7, 2014
NOTES AT BOTTOM---EXPLANTION, PROBLEMS ETC. SCROLL DOWN
#include <iostream>
#include <iomanip>
#include <string>
[Code]....
I have to write a program that stores information about students and displays results (Formated). Example-
Inputs ( # of students, First and Last name of student, the gender, age, and hieght. (height inputed as inches and outputed as feet and inches))
Student 2
---------
Jett, Joan Female
100 years old 5' 7"
Ive been falling behind a little due to working late and barely having time for my school work. Coming across several issues, one being an error with GENDER (Error C4700: uninitialized local variable 'gender' used:). As well as how to format the end result, i understand that u have to use #include <iomanip>, but am confused on how to format correctly.
View 2 Replies
View Related
Jan 22, 2015
is this according to it??
#include <iostream>
#include <fstream>
using namespace std;
int main(void){
fstream file("textfile.txt");
int linecount = 0;
int tempArray[100];
[Code] ....
View 1 Replies
View Related