Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,572 members, 7,812,851 topics. Date: Monday, 29 April 2024 at 08:39 PM

I Have Dis Question Dat I Really Need Help With C++ - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / I Have Dis Question Dat I Really Need Help With C++ (1136 Views)

Why You Should Start Programming With C. / Programmers please help, I really need to get answers to this / Please I Really Need Your Help Urgently . (2) (3) (4)

(1) (Reply) (Go Down)

I Have Dis Question Dat I Really Need Help With C++ by joycej(f): 11:21am On Aug 02, 2010
suppose every student in Bingham University drinks 3 bottles of coke per week, to produce a crate of coke requires 300 cubes of sugar. Assume that there are 1500 students in Bingham, write a program to determine the number of cubes that will satisfy the demand for coke in a monthly basis.
Re: I Have Dis Question Dat I Really Need Help With C++ by chukxy: 5:18pm On Aug 02, 2010
I would tackle this challenge this way:

#include <stdio.h>
#include <conio.h>

#define CUBE_PER_CRATE 300
#define TOTAL_NO_STUDENT 1500
int get_no_bottle_per_week();

int calculate_no_crate_per_month(int no_bottle);

int calcutate_no_cube_per_month(int no_crate);

void print_result(int cube_per_mont);



int main(void) {

int no_bottle_per_student,no_crate_per_month,no_cube_per_month;

no_bottle_per_student =get_no_bottle_per_week();
no_crate_per_month =calculate_no_crate_per_month(no_bottle_per_student );
no_cube_per_month =calcutate_no_cube_per_month( no_crate_per_month);
print_result(no_cube_per_month );


_getche();
return 0;
}
int get_no_bottle_per_week(){
int no_b;

printf("\n Please enter the no of bottle consumed by a student in a week \n"wink;
scanf("%d",&no_b);
while(no_b<0)
{
printf("\n Please enter a valid value \n"wink;

}

return no_b;
}

int calculate_no_crate_per_month(int no_bottle)
{

int no_crate, no_bottle_per_month;

no_bottle_per_month= TOTAL_NO_STUDENT *no_bottle*4;
no_crate =no_bottle_per_month/24;

return no_crate;

}


int calcutate_no_cube_per_month(int no_crate) {

return no_crate*CUBE_PER_CRATE ;
}


void print_result(int cube_per_mont)
{


printf("\n The no cube consumed in a month is %d \n",cube_per_mont);

}
the ans using C programming is shown on the screen shot attached. It is assumed that we hv 4 weeks in month(fact). You can relate to c++. I think what you to need to change is the input and output function.

Re: I Have Dis Question Dat I Really Need Help With C++ by joycej(f): 1:37pm On Aug 07, 2010
thanks alot.
Re: I Have Dis Question Dat I Really Need Help With C++ by chukxy: 8:42pm On Aug 07, 2010
You are welcome!
Re: I Have Dis Question Dat I Really Need Help With C++ by jacob05(m): 12:02am On Aug 08, 2010
chukxy:



I would tackle this  challenge this way:

#include <stdio.h>
#include <conio.h>

  #define  CUBE_PER_CRATE  300
#define   TOTAL_NO_STUDENT 1500
int get_no_bottle_per_week();

int  calculate_no_crate_per_month(int no_bottle);

int calcutate_no_cube_per_month(int  no_crate);

void print_result(int cube_per_mont);



int main(void) {

     int no_bottle_per_student,no_crate_per_month,no_cube_per_month;

    no_bottle_per_student =get_no_bottle_per_week();
   no_crate_per_month =calculate_no_crate_per_month(no_bottle_per_student );
   no_cube_per_month =calcutate_no_cube_per_month( no_crate_per_month);
   print_result(no_cube_per_month );


   _getche();
return 0;
}
     int get_no_bottle_per_week(){
        int no_b;

      printf("\n Please enter the no  of bottle consumed by a student in a week \n"wink;
    scanf("%d",&no_b);
    while(no_b<0)
    {
        printf("\n Please enter a valid value \n"wink;

dead end for invalid answer
    }


return no_b;
}

  int  calculate_no_crate_per_month(int no_bottle)
{

     int no_crate, no_bottle_per_month;

    no_bottle_per_month= TOTAL_NO_STUDENT *no_bottle*4;
   no_crate =no_bottle_per_month/24;

  return  no_crate;

}


int calcutate_no_cube_per_month(int  no_crate) {

    return no_crate*CUBE_PER_CRATE  ;
  }


void print_result(int cube_per_mont)
{


printf("\n The no cube consumed in a month is %d \n",cube_per_mont);

}
    the ans using C programming is shown on the screen shot attached. It is assumed that  we hv 4 weeks in month(fact). You can relate to c++. I think what you to need to change is the input and output function.
your solution is obviously not efficient enough (you did too much calcutations not needed). You also made some mistakes in your calculations hope you correct them when you cross check your solution.
Re: I Have Dis Question Dat I Really Need Help With C++ by chukxy: 10:21am On Aug 08, 2010
Hi jacob05, I know I omitted scanf("%d",",&no_b) in my while loop. Again I broke the calculations to different functions for the person
I am communicating to understand. I can use three functions to achieve this task or even lump everything in the main function; but this would make it difficult for the reader to understand. The code is long because is set to automate the task; not just to calcutate for three bottles consumed in a week but any amount consumed,that is the reason it is program at the first instance. If it is meant to just solve the problem at hand, 6 lines of code can solve it.


Always watch your statement in a public forum. If you know it vey well, all you could do is do the right thing rather than rubbishing someones effort ok?
Also point out where I made mistake in my calculation or better still paste your own version of the soultion.
Re: I Have Dis Question Dat I Really Need Help With C++ by marcus1234: 10:21am On Aug 08, 2010
Re: I Have Dis Question Dat I Really Need Help With C++ by chukxy: 10:27am On Aug 08, 2010
@ marcus1234 what do you mean?
Re: I Have Dis Question Dat I Really Need Help With C++ by jacob05(m): 3:39pm On Aug 08, 2010
chukxy:

Hi jacob05, 1 i know I omitted scanf("%d",",&no_b) in my while loop. 2Again I broke the calculations to different functions for the person
I am communicating to understand.
I can use three functions to achieve this task or even lump everything in the main function; 3but this would make it difficult for the reader to understand. The code is long because is set to automate the task; not just to calcutate for three bottles consumed in a week but any amount consumed,that is the reason it is  program at the first instance. If it is meant to just solve the problem at hand, 6 lines of code can solve it.


4Always watch your statement in a public forum. If you know it vey well, all you could do is do the right thing rather than rubbishing someones effort ok?
Also point out where I made mistake in my calculation or better still paste your own version of the soultion.


1. Thank God you saw that, hope you correct it quickly

2. 3 functions would be better and much more understanding to the user you are presenting it to.

3. The naming you give your functions are obviously too long for me and makes your code looks ugly. You should have used comments for proper documentation of the function.

4. Hmm reserve my words.
Re: I Have Dis Question Dat I Really Need Help With C++ by turag: 10:15pm On Aug 08, 2010
#include<iostream>
using namespace std;
int main()
{
int a, b, c, d, e, x, y, ans;

cout << "How many bottles of coke are there in a crate?: ";
cin >> a;

cout << "How many numbers of student?: ";
cin >> b;

cout << "How many cubes of sugar are required to make a crate?: ";
cin >> c;

cout << "Ration of student to one bottle\n";

cout << "Student = ";
cin >> d;

cout << "Bottle(s) = ";
cin >> e;

x = d * 4;
y = c / 2;
ans = y * b;

cout << ans << "cube(s) of sugar is required to satisfy the demand for coke on a monthly basis" << endl;
system("pause"wink
return 0;
}

Correct errors if any.
Thanks
Re: I Have Dis Question Dat I Really Need Help With C++ by jacob05(m): 8:51am On Aug 09, 2010
turag:

From 1 Abraham Isesele Omobhude
need more solutions? hook me up-(abrahamomobhude@yahoo.com)


#include<iostream>
using namespace std;
int main()
{
2 int a, b, c, d, e, x, y, ans;


cout << "How many bottles of coke are there in a crate?: ";
cin >> a;


cout << "How many numbers of student?: ";
cin >> b;

cout << "How many cubes of sugar are required to make a crate?: ";
cin >> c;

cout << "Ration of student to one bottle\n";

cout << "Student = ";
cin >> d;

3 cout << "Bottle(s) = ";
cin >> e;


4 x = d * 4;
y = c / 2;
ans = y * b;


cout << ans << "cube(s) of sugar is required to satisfy the demand for coke on a monthly basis" << endl;
system("pause"wink
return 0;
}

Correct errors if any.
Thanks

1. Nice meeting you. My 'names' are Oyebanji jacob mayowa. Pleased to me you.

2. You ARE TEACHING US MAN NOT YOURSELF !. your variable names are very poor . I was complaining earlier about too long and ugly variables , NOW too short and unself-documentating variable names are used. Try to correct this man.

3. You requested for variable a and e but you never used them i your program. If you are not using the why requesting for them ?

4. WRONG !!! do your math very well.

@chuxy
waiting for your modified solution. Love the way you did yours.

Oops! I'm becoming a critic. Hope you are not annoyed. Should have posted my solution but my laptop adapter got faulty.
Re: I Have Dis Question Dat I Really Need Help With C++ by jacob05(m): 8:52am On Aug 09, 2010
turag:

From 1 Abraham Isesele Omobhude
need more solutions? hook me up-(abrahamomobhude@yahoo.com)


#include<iostream>
using namespace std;
int main()
{
2 int a, b, c, d, e, x, y, ans;


cout << "How many bottles of coke are there in a crate?: ";
cin >> a;


cout << "How many numbers of student?: ";
cin >> b;

cout << "How many cubes of sugar are required to make a crate?: ";
cin >> c;

cout << "Ration of student to one bottle\n";

cout << "Student = ";
cin >> d;

3 cout << "Bottle(s) = ";
cin >> e;


4 x = d * 4;
y = c / 2;
ans = y * b;


cout << ans << "cube(s) of sugar is required to satisfy the demand for coke on a monthly basis" << endl;
system("pause"wink
return 0;
}

Correct errors if any.
Thanks

1. Nice meeting you. My 'names' are Oyebanji jacob mayowa. Pleased to me you.

2. You ARE TEACHING US MAN NOT YOURSELF !. your variable names are very poor . I was complaining earlier about too long and ugly variables , NOW too short and unself-documentating variable names are used. Try to correct this man.

3. You requested for variable a and e but you never used them i your program. If you are not using the why requesting for them ?

4. WRONG !!! do your math very well.

@chuxy
waiting for your modified solution. Love the way you did yours.

Oops! I'm becoming a critic. Hope you are not annoyed. Should have posted my solution but my laptop adapter got faulty.
Re: I Have Dis Question Dat I Really Need Help With C++ by chukxy: 9:22am On Aug 09, 2010
#include <stdio.h>
#include <conio.h>


int main()
{
  int noBottle,noStudent,sugar,cubePerMonth;   //declaration of variables
   noStudent = 1500;
  sugar = 300;
 
printf("\n Please enter the no of bottle consumed by each student in week \n"wink;
   scanf("%d",&noBottle);     //gets the value from user


while(noBottle< 0)         //validates the user input
{
  printf("\n Please enter a valid value\n"wink;
scanf("%d",&noBottle);
}

cubePerMonth = (noBottle*noStudent*sugar*4)/24;

printf("The no of cube consumed in a month =%d",cubePerMonth);


-getche();
return 0;


}

@ oga jacob05, if it is this way you want the code to be, then I would sack you as your employer because of the following reason:
1. you have not justified your pay as a programmer, ordinary calculator or smart phone would accomplish the task ahead faster.
2. you have not implemented in your code the concept or re-usability,scalability,maintainability etc.
3. you did not think outside the box to know the relevance of this task to your employer(in this case coca cola)
4. Finally, you did not consider that you are working as a team of developers/programmers.


Thinking Differently:


The relevance of this task to your employer includes among others the following:
1. to be able to calculate the total number of bottles they need for their production in a month not just the one consumed by the school in question but also from other customers.
2. to calculate the no of crates they need for the production in a month.
3.to calculate the total amount of sugar the need and the total cost of production.
4. to generate the reports, graphs for management personnel.


When you are thinking differently, you would know that for you to accomplish the task list above, you only need to call the functions I defined in my former code and loop through them with certain values and your objective would be achieved. Also other member of your team can import the file and use any of the function to accomplish the set task. Doing it the way I did it before, automation is achieved and not just to do input and output as reflected in the second code.

Oga jacob do you understand where I am coming from now?
Re: I Have Dis Question Dat I Really Need Help With C++ by jacob05(m): 2:32pm On Aug 09, 2010
chukxy:

#include <stdio.h>
#include <conio.h>


int main()
{
  int noBottle,noStudent,sugar,cubePerMonth;   //declaration of variables
   noStudent = 1500;
  sugar = 300;
 
printf("\n Please enter the no of bottle consumed by each student in week \n"wink;
   scanf("%d",&noBottle);     //gets the value from user


while(noBottle< 0)         //validates the user input
{
  printf("\n Please enter a valid value\n"wink;
scanf("%d",&noBottle);
}

cubePerMonth = (noBottle*noStudent*sugar*4)/24;

printf("The no of cube consumed in a month =%d",cubePerMonth);


-getche();
return 0;


}

@ oga jacob05, if it is  this way you want the code to be, then I would sack you as your employer because of the following reason:
1. you have not justified your pay as a programmer, ordinary calculator or smart phone would accomplish the task ahead faster.
2. you have not implemented in your code the concept or re-usability,scalability,maintainability etc.
3. you did not think outside the box to know the relevance of this task to your employer(in this case coca cola)
4. Finally, you did not consider that you are working as a team of developers/programmers.


Thinking  Differently:


The relevance of this task to your employer includes among others the following:
1. to be able to calculate the total number of bottles they need for their production in a month not just the one consumed by the school in question but also from other customers.
2. to calculate the no of crates they need for the production in a month.
3.to calculate the total amount of sugar the need and the total cost of production.
4. to generate the reports, graphs for  management personnel.


When you are thinking differently, you would know that for you to accomplish the task list above, you only need to call the functions I defined in my former code and loop through them with certain values and your objective would be achieved. Also other member of your team can import the file and use any of the function to accomplish the set task. Doing it the way I did it before, automation is achieved and not just to do input and output as reflected  in the second code.

Oga jacob do you understand where I am coming from now?



kia all this for me ?? .
oga ke, who be oga, me ?? Jacob05 is still a teen age BOY o and searching badly for SIWES Placement o.

Sack ME Ke, Pls O, What Have i Done Wrong ?? Crime to Correct Mistakes or What

know let break your comments down

I never for once hate [size=13pt]modular [/size]programming, i try as  much as possible to break my program segments into modules. i would never ever Advice you to Program Like This. OK?

I love the Spirit of Group Coding (Although Not in One Before) and Breaking Down Your Work would help in Easy division of the Work to Be Done (From What i Read). OK?

The main point i was trying to make was that your function name is rather too long and making your code look UGLY GET THAT !!!! ?

e g : calcutate_no_cube_per_month(int  no_crate)

using this Style Can Get YOU into big trouble when dealing with larger Programs and even debugging. GET THAT ?? (lol)

i strongly apologize if i have offended you OK? especially in the calculation aspect OK? (Using Another Simple But Clear logic on PAPER.)

Make Things As Simple As Possible But Not Simpler .
By Albert Einstein
Re: I Have Dis Question Dat I Really Need Help With C++ by marcus1234: 2:33pm On Aug 09, 2010
Re: I Have Dis Question Dat I Really Need Help With C++ by turag: 8:11pm On Aug 09, 2010
...
Re: I Have Dis Question Dat I Really Need Help With C++ by jacob05(m): 9:39pm On Aug 09, 2010
turag:

@jacob05, 1I wasn't trying to teach anyone, was just trying to help 'joyce' out with her work.2 My calculations are not for static variables, they are for variables that changes. 3My variable names are poor, cos I was trying to pin-point each step, but I should be blamed for that, cos I wasn't following the rules. 4I used the the variables 'a' and 'e', check it well, u will see it. [/color] As for my maths calculations, it goes like this cubes / 2 = ans(150), then ans * 1500 = ans1(225000)

I guess I tried making the working simpler than urs.

1. But the whole world is reading this right now!. You are not only teaching her you are teaching ALL. To teach her alone Call her to a private lesson.

2. Ok.

3. Thank goodness you know this. But trying to "pin-point" to her the bases would require a little more detail about what she is learning.

4. WURU WuRu TO THE ANSWER. this is a dubious math . But check chukxy's calculations. And i've not yet seen where you used a and e in your CALCULATION O. Think i need a GLASS.

(1) (Reply)

Add Vorguepay Online Payment System To Your Website / Join The Unilag Programmers Club! / Bedtime Story Of A CS Student

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 64
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.