Question:
Can I get some Dev C++ help?
djbullano
2011-04-19 14:04:39 UTC
Write a C++ program to calculate boarding bills for a kennel. The cost per day is determined by the weight of the dog according to the following chart:
Weight < 10 pounds $ 8.00 per day

10 <=Weight < 30 $12.00 per day

30 <=Weight < 50 $18.00 per day

Weight >=50 pounds $ 22.00 per day

A text file has information about the dogs that are boarding at the kennel. Each line contains the following information for one dog:
the last name of the dog’s owner, the dog’s weight , the number of days the dog is staying at the kennel. The three data items are separated by blank spaces. The two numbers are both integers.

Your output should contain:


Four labeled columns of information about the dogs in the file
Dog owner dog weight number of days total cost

A counter of the total number of dogs processed.
A count of dogs in each category.
The total amount of money collected for all dogs in the file.

Money should have 2 decimal places and a dollar sign.



here is the txt file

a.txt
Smith 50 5
Jones 70 5
Hacker 42 3
Henson 10 8
Byrd 30 1
Jarman 25 10
Shaffer 12 7
Klaus 6 3



can someone lead me in the right direction. all i want to do is print out the information from the text file then i can probably do the rest. if you can help me i would appreciate it greatly. im studying for my lab final. this is just a practice for lab final. i wont be turning this in, so its not hw

thank you
Three answers:
?
2011-04-19 14:41:47 UTC
Why the hell are u using DevEnv but not C#? OK I's your program.



I would use some ANSII C commads using

#include

#include

#include



// Open the file and read each line.

main(int argc, char** argv)

{

char sz[256];

File *hf=NULL;

int total=0;



hf = fopen ("...\\a.txt");

if (hf!=NULL) {

while (!feof(hf))

{

fgets (sz, sizeof(sz), hf);

sz[strlen(sz)-1]='\0';

total +=calculate(sz);

}

printf("total amount ; %d", total);

fclose(hf);

}

}





// calc each line

int calculate(char* psz){

char*psz1=NULL;

char*psz2=NULL;

char*psz3=NULL;

int v2;

int v3;



psz1 = strtok(psz, " ");

psz2 = strtok(psz, NULL);

psz3 = strtok(psz, NULL);

v2 = atoi(psz2);

v3 = atoi(psz3);



printf("Name %s Weight:%d Time:%d amount ; %d", psz1, v2, v3, v2*v3 )

return v2*v3;

}
Aaron
2011-04-19 14:23:13 UTC
First, you need to create a file stream to the txt file. To initialize that, use the istream declaration.

Then, you would initiate the filestream using the open("a.txt") function for the istream variable.



Then, I'd recommend reading the words in via a for loop or a while loop, reading them line-by-line and incrementing the counter for number of dogs as well as maybe a switch or series of if-else statements to count specific dogs. The While loop should have the either of these conditions (let the istream var. be myIn): either while(myIn) or while (myIn.peek() != EOF)



Perhaps constants for the prices for the specific weights?
lopes
2017-02-22 12:09:20 UTC
the func is clrscr() wish it grew to become right into a typing blunders. It desires the the hedder report conio.h pattern #incorporate #incorporate void important() { cout<<"attempt string"; //reflects the text fabric in costs clrscr(); //clears the demonstrate screen and takes cursor to first line }


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...