C++ :: Functions Without Parameters - Compute And Print Total Number Of Products For Company

Mar 27, 2013

Summary: 6 companies have a product in 5 different warehouses. Each company is identified by a positive ID number and each warehouse is identified by a number (1 for the first, 2 for the second,…)

Object: the object of this assignment is to write a C++ program which asks the user to enter a company ID number, and the number of products in each of the warehouses. It then computes and prints the total number of products for that company

If the total number of product is less than 100, it prints the message “place a new order”

Input: for each company, its ID, and the number of products in each warehouse with appropriate prompt messages.
Example: Enter company ID number: 101
Enter number of products in warehouse #1:30
Enter number of products in warehouse #2:60
Enter number of products in warehouse #3:0
Enter number of products in warehouse #4:5
Enter number of products in warehouse #5:27
The total for company 101 is:122

Output: for each company, the total number of product, and the message “place a new order” if the total number of product is less than 100.

Method:
1. Define global variable, int total_prod to hold the total number of products for a company
2. define the function void compute_total() that uses a loop to read the number of the products in all warehouses for one company, computer the total number of products and store it into the global variable total_prod.
3. Define the function void new_order() that determines if a new order need to be placed as follows: if the total number of products (in the global variable total_prod) is less than 100, it prints the message “place a new order”
4. Your function main does the following in a loop:
- read a company ID number
- call function compute_total() to read the number of the product in all warehouses for that company, and to compute their sum
- print the total number of the product for that company with an appropriate message
- call the function new_order() to determine if a new order need to be placed.

View 17 Replies


ADVERTISEMENT

C :: Read Amount Of Order From Standard Input / Compute And Print Total Price After Discount

Apr 13, 2014

A Bookseller makes special discount for multiple orders of a book as follows:

AMOUNT and DISCOUNT as follows.

5-9 5% 10-14 10% 15-19 15% 20+ 20%

Write a C main function to read the amount of order from the standard input and compute and print the total price of the given order after the discount. Assume that unit price of a book is 10.00$

My problem is that.When i start with this

Code:
#include<stdio.h>
#include <stdlib.h>
int main(void)
{
int number;
float TotalPrice;
printf("enter a number:");

[Code] ....

I get 0 if i enter a number between 0 and 4(0 and 4 included). I don't know where I am doing a mistake. I also want to know if i can handle this buy just if statements. or how can i do it by while and for loops ?

View 1 Replies View Related

C :: Compute Total Price Of Books By A Given Author

May 7, 2013

Given a structure book defined as follows and an array lib of books

Code:
struct Book{
char title[100];
char author[100];
int price;
struct Book *nextedition;
};

struct Book lib[1000]; I'm going to write a function to compute total price of books by a given author including all books which are future editions of his book, even if the author of that future edition is NOT the specified author. title author price nextedition Book1 Author1 25 &lib[2] Book2 Author2 20 NULL Book3 Author3 30 &lib[3] Book4 Author1 35 NULL
For the example above, given the author "Author1", the function should return 90 (=25+30+35), and given the author "Author 3", the function should return 65 (=30+35).

So here's my attempt:

Code:
int totalPrice(char author[100]){
int total=0;
for (i=0; i<numbooks; i++)
if(strcmp(author, lib[i].author==0))

[Code] ....

What I'm trying to do is finding the first book in the lib of the specified author using for loop and then let the while loop do the rest. However, it seems the price is over-counted after each iteration of the for loop but I don't know how to fix it.

View 2 Replies View Related

C++ :: Program To Calculate Company Weekly Payroll - Calling Functions?

Jun 9, 2014

This program in not completed. I am creating a large program in order to calculate a company's weekly payroll. For now I am filling in the separate functions piece by piece before the rest of the program is completed.

Right now I am trying to use separate functions to call other functions. I need to ask the user for the file name and then open the file. I am no longer getting any compiler errors however when I run the program all it displays is "Welcome."

So it's not actually calling the NameTheFile function and the OpenTheFile function. It just says "Welcome" and then closes down. Why is it doing this?

/*Program to determine company's weekly payroll*/

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void NametheFile() {

ifstream inputFile;

[Code] ....

View 1 Replies View Related

C :: Obtain Check Number And Then Company Information From Datafile

May 13, 2013

I have to obtain a check number from a datafile and then also get company information also from a datafile.

So my first question is about the:

Code:
char outputFilename[]= "out.list"

Is this the name of the output file I'm going to write to? And also the file has to be created before being used...is that line of code creating the file or do i have to create it in notepad?

Code:
FILE *ifp, *ofp;
char *mode = "r";
char outputFilename[] = "out.list";
ifp = fopen("in.list", mode);
if (ifp == NULL) {
fprintf(stderr, "Can't open input file in.list!

[Code] .....

View 7 Replies View Related

C++ :: Program To Compute And Print A Billing Statement For Each Patient

Oct 17, 2013

Community Hospital needs a program to compute and print a billing statement for each patient. Charges for each day are as follows:

a. room charges: private (P) room = $125.00; semi-private (S) room = $95.00; or ward (W) = $75.00
b. telephone charge = $1.75
c. television charge = $3.50

Write a program to get data from the keyboard, compute the patient’s bill, and print an appropriate statement. Typical input (nut yours do not have to be identical to this) is the following:

How many days was the room occupied? 5
What type of room? P
Telephone used during the stay? N
Television used during the stay? Y

Keep in mind that the user needs to know that the input can be any integer number of days for the length of stay, either (P, S, or W) for the room type, and either (Y or N) for both telephone and television options.

A statement (which yours MUST be identical to) for the data given follows:

Community Hospital Patient Billing Statement

Number of days in hospital: 5
Type of room: Private
Room charge:$ 625.00
Telephone charge:$ 0.00
Television charge:$ 17.50

TOTAL DUE = $642.50

View 3 Replies View Related

C++ :: Void Functions - Passed By Value To Find A Total

Dec 4, 2014

I missed last class on doing void functions because I got sick and im completely lost! ive being using the texts book example for a reference but its not running !

The output should look similar to this:

how much was your shirt?
20
shirt 20.00
tax =1.20
the total 21.20

Code:

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

void getShirtCost(double shirtCost);
void calculate(double shirtCost,double taxAmount, double total, double taxamount) ;
void printReceipt(double shirtCost, double taxAmount, double total, double taxamount);

[Code] ....

View 1 Replies View Related

C :: Recursive Functions With Arrays As Parameters

Sep 21, 2013

I wrote a fuction in C with the prototype 'void raisePowerOf2(int array[],int pow);'

If someone want to find the value of 2^456 ,just have to invoke this function 456 as the value for pow and int array with 2 elements :1 & -1 as the argument for the array.(There I used -1 to denote the end of the array.)

But it seems that this function doesn't give the exact answer

And I tried this from java also,with the same implementation.It produced the answer precisely .

I tried for hours, but unable to detect reasons why this code blok in C doesn't work properly

This is the code in c

Code:

#include<stdio.h>
void raisePowerOf2(int array[],int pow);
int main(){
int a[2]={1,-1};
raisePowerOf2(a,5);
return 0; }
void raisePowerOf2(int array[],int pow){

[Code]...

This is the code in java....

Code:

public class NewClass4 {
void raisePowerOf2(int array[],int pow){
final int len=array.length;
int store[]=new int[len+1];
int qtnt=0;
for(int i=len-1;i>=0;i--){
store[i+1]=(array[i]*2)%10+qtnt;
qtnt=(array[i]*2)/10;

[Code]...

View 7 Replies View Related

C/C++ :: Recursive Functions With Arrays As Parameters

Sep 21, 2013

I wrote a fuction in C with the prototype

'void raisePowerOf2(int array[],int pow);'

If someone want to find the value of 2^456 ,just have to invoke this function 456 as the value for pow and int array with 2 elements :1 & -1 as the argument for the array.(There I used -1 to denote the end of the array.)

But it seems that this function doesn't give the exact answer

And I tried this from java also,with the same implementation.It produced the answer precisely .

I tried for hours, but unable to detect reasons why this code blok in C doesn't work properly .

This is the code in c

#include<stdio.h>
void raisePowerOf2(int array[],int pow);
int main(){
    int a[2]={1,-1};
    raisePowerOf2(a,5);  
    return 0;
}  void raisePowerOf2(int array[],int pow){

[Code] ....

View 5 Replies View Related

C++ :: Optional / Default Parameters In Class Functions?

Aug 19, 2014

In the thread "Making a argument optional to function", it is stated that to set default values for arguments of a function you can simply do so in the function definition, like:

int myfunc(int a, int b, int c=3) {...}

This then automatically puts c to 3 in the function body if a call like myfunc(1,2); is made, if I understood correctly. However, this does not seem to hold for class functions. For example, something like:

class classy {
public:
int class_func(int, int, int); // class function prototype
}
int classy::class_func(int a, int b, int c=3) {...}

fails to compile. What I would like is to be able to call class_func outside of this class (by including it as a header in another macro), optionally specifying c. If c is not specified in the call, it should use a default value.

View 2 Replies View Related

C++ :: Class Member Functions With Pointer Parameters?

Jan 30, 2013

Here is the assignment: (3pts) Given the following class header file, write the class’ source code for each of the accessor and mutator functions listed. (How the functions have listed their parameters, varying between passing by reference and by value.) Don’t forget to comment your code – it counts!

class Album {
private:
char * artist; // band or singer’s name
char * title; // title of the album

[code]....

The input will be an array. My questions: First, am I on the right track?

When using (char * a) for a function, for example, this is passing the address of a, correct? so then *artist=a; changes what the address of a points to?

also, the functions are bool when I would expect void. Why? for all of the set_" " functions, the parameter is *... but for set_record_label it is *&. That appears to be a mistake to me. Is that right?

what is the difference between *& and * as parameters?

View 5 Replies View Related

C/C++ :: Functions Passing Size Of Arrays As Value Parameters?

Mar 11, 2014

we were given this code:

// Music Shuffle Program
// This program takes an array of strings and randomly permutes their order.
// This allows us to generate new song shuffles.
#include <iostream>

[Code]....

or are they referring to something else?

View 4 Replies View Related

C# :: How To Add Number To Previous To Get Total

Feb 7, 2015

decTotalAmountOwed = decAmountOwed + decAmountOwed;

This is what i've tried so far. The numbers are supposed to be added together once placed in listbox.

View 8 Replies View Related

C++ :: Printing Total Number Of Even / Odd Integers

Feb 28, 2013

The program requires the user to enter 10 integers then print the total no. of even integer,highest even integer, lowest even integer then total no. of odd integer,highest odd integer, lowest odd integer

I already got the total no. of even integer and total no. of odd integer. But I don't know how will i get the highest even integer, lowest even integer and highest odd integer, lowest odd integer.

View 2 Replies View Related

C++ :: Counting Total Number Of Each Topic Separately?

Feb 25, 2015

How can i count total number of each topic separately? For example total number of topic 1 between all nodes. To begin enter 10 and 7 to initial node number and number of topic.

#include <iostream>
#include <vector>
#include <list>
#include <stdlib.h>
#include<time.h>
#include<iomanip>
#include <iostream>
#include <string>

[Code] ....

View 1 Replies View Related

C++ :: Number Of Array Parameters In Function?

Mar 19, 2014

So in this function it is already passing the array into the function but the thing is one parameter being passed into the function and if so how do I go about passing 3 arrays as parameters into the function? Also the program only asks for a user entry of hours for three different cars so why would there be a point in making two additional arrays to be passed into the function?

#include <iostream>
#include <iomanip>
using namespace std;
//passing array into function
double calculateCharges(double hours[], int HoursArrayLocation);//call function

[Code] ....

View 12 Replies View Related

C :: How To Count Total Number Of Unique Elements In Array

Mar 19, 2013

How can i count the total no of unique elements in an array? Like I have an array.

Code:
int array[]= { 2,1,4,0,3,3,0,0,1,2,1,1}
// As it has 0,1,2,3,4 as unique values so total no of unique values are=5
int unique =5;

View 4 Replies View Related

C++ :: For Loop That Computes Total Of Certain Number Of Integers And Then Outputs Sum

Sep 30, 2014

I am trying to do a simple for loop that computes sum of a certain number of integers and then outputs the sum.

.text
.globlmain
main:
li $9, 0
li $10, 0
li $11, 10
li $12, 0
li $13, 0

[Code] ....

There error I keep getting is on the line with the branch

Instruction references undefined symbol at 0x0040003c [0x0040003c] 0x10200000 beq $1, $0, 0 [exit-0x00400038]

View 1 Replies View Related

C/C++ :: How To Get Total Number Of Items Selected From Options Menu

Jul 28, 2014

My project is to make a options menu for the user to select a shape and than draw out the shape. That whole process is already done and ready to go. What i am having trouble on is totaling the number of selected shapes. For example, at the end of the program i need to prompt a message saying ("You have selected "shape" this many times "number").

View 1 Replies View Related

C++ :: Calculate Fewest Number Of Each Denomination Needed To Pay A Bill Of Amount Total

Mar 5, 2013

Write a C++ program to calculate the fewest number of each denomination needed to pay a bill of amount TOTAL. For example, if the end user enters $97 for TOTAL, program will output that the bills would consist of one $50 bill, two $20 bills, one $5 bill, and two $1 bills. (Assume that the amount is in whole dollars, no cents, and only $100, $50, $20, $10, $5, and $1 denominations are available.) Aid: You may want to use the modulus operator %.

View 1 Replies View Related

C++ :: Word Counter - Calculate Number Of Letters And Give Total Cost

Nov 4, 2013

I am currently working on an assignment.

#include <iostream>
using namespace std;

int main(int argc, char *argv[]) {
char letter;
int count = 0;
double ppl = 0;
double finalCost = ppl * (count - 1);

[Code] ....

I am trying to create a word counter program that asks for the price per letter and then asks for the sentence they are writing. The app should then calculate the number of letters and give the total cost similar to:

You have 40 letters at $3.45 per letter, and your total is $138.00.

Everything compiles fine but when I run it the inputs don't work and it outputs:

You have -1 per letter, and your total cost is $-0.

View 2 Replies View Related

C/C++ :: Using Print Statement To Print Certain Number Of Spaces

Sep 1, 2014

is there a to use printf to print certain number of blank spaces, where the number is derived from the output of a function?

for(m=low; m<=high;m++)
{
printf("t=%2d %'f(m)-1's %3c", m, ' ',*);
}

This is suppose to output

t=-3 *
t=-2 *
t=-1
.
.
.

View 2 Replies View Related

C :: Array Add Total Rows And Total Columns

Apr 16, 2013

Code: i am trying to display the information in the array as a table and add the total rows and the total colums separately

#include<stdio.h>
int main(void)
{
int row, col;

[Code].....

View 1 Replies View Related

C :: Program That Allow User To Enter A Number N And Print Nth Prime Number

Nov 3, 2013

I need to write a program that will allow the user to enter a number "n" and the program tell you that the nth prime number is .....

EXAMPLE

user enters 55

printf("The 55th prime number is %i", variable");

View 1 Replies View Related

C++ :: Program That Takes Sum Of Products And Generates Sum Of Minterms

Nov 28, 2013

Write a C/C++ program that reads a boolean expression in sum-of-products form and generates the sum-of-minterms form (canonical form). Use single letter to represent variables. The following symbols will be used to represent operators: NOT: ~, AND: *, OR: +. Other operators won't be used.

Examples of execution:
number of variables: 2
SOP expression: ~A+B
output: ~A*~B + ~A*B + A*B

number of variables: 3
SOP expression: x*y*z + ~x*~y + y*~z
output: x*y*z + ~x*~y*z + ~x*~y*~z + x*y*~z + ~x*y*~z

View 3 Replies View Related

C++ :: Using Class Functions To Enter And Print Out Info

May 19, 2013

I have a program that uses class functions to enter and print out info. The problem is with the second function answers(). Here is the whole cpp file. In the answer function I need to use an exception to exit when its the end of an array. I could just be doing it wrong. I used try/catch originally but when I used it, it caught the exception but ended the whole program.

#include <iostream>
#include <cstdlib>
#include "answering_machine.h"
using namespace std;
void AnsweringMachine::init(){
numMessages = 0;

[Code] ......

View 6 Replies View Related







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