Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Object Oriented ProgrammingRSS Feeds

Program which read device data from a text file and show each extension’s dues

Posted By: Easy Tutor     Category: C++ Programming     Views: 2469

Write a program which read device data from a text file and show each extension’s dues.

Administration of GCU has decided to cut charges from its employee’s salaries. The VC of GCU orders a Software House to make software which should keep records of phone calls. And in the end of every month employees will receive their telephone bill at the rate of Rs.5 after every 5 minute call. The Software House bought a device to attach with the main telephone exchange. The device keeps record of incoming and outgoing calls for every extension. There are only 10 extensions in GCU from 0 to 9. 0 is extension of receptionist. Device saves data in following format;

Source Destination-1 Destination-2 Minutes
5666373, 0, 2, 7
6775775, 4, -, 10
3, 0, 7645303,2
4, 2, -,-
8, 6475774, -, 3

Make such a program which read this device data from a text file and show each extension’s dues e.g.

1 200
2 120
3 0
4 320
5 330
6 203
7 245
8 900
9 302

Note: Input will end with a line containing 0.

Code for Program which read device data from a text file and show each extension’s dues in C++ Programming


 # include <iostream.h>
 # include <fstream.h>
 # include <string.h>
 # include <stdlib.h>
 # include <conio.h>

 int main( )
    {
       clrscr( );

       fstream File("CP-09.txt",ios::in|ios::nocreate);

       if(!File)
      {
         cout<<"Unable to open the input file."<<endl;
         cout<<"Press any key to exit."<<endl;

         getch( );
         exit(EXIT_FAILURE);
      }

       char Data[100]={NULL};

       char *Ptr=NULL;

       int source=0;
       int minutes=0;
       int bill[9]={0};

       File.getline(Data,80);

       do
      {
         source=-1;
         minutes=0;

         Ptr=NULL;
         Ptr=strtok(Data," ");

         if(atoi(Ptr)>0 && atoi(Ptr)<=9)
        source=(atoi(Ptr)-1);

         Ptr=NULL;
         Ptr=strtok(NULL," ");

         Ptr=NULL;
         Ptr=strtok(NULL," ");

         Ptr=NULL;
         Ptr=strtok(NULL,"\n");

         minutes=atoi(Ptr);

         if(source!=-1)
        {
           int calls=(minutes/5);

           if((minutes%5))
              calls++;

           bill[source]+=(calls*5);
        }

         strset(Data,NULL);
         File.getline(Data,80);
      }
       while(strcmpi(Data,"0")!=0);

       for(int count=0;count<9;count++)
      cout<<bill[count]<<endl;

       File.close( );

       getch( );
       return 0;
    }
  
Share: 



Easy Tutor
Easy Tutor author of Program which read device data from a text file and show each extension’s dues is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!