473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

a small pointer help

write a c++ program using Object Oriented Programming
to accept Customer Code No , Customer Name and Total Bill Amount
of (n) number of customer
n is accepted at runtime



Also after accepting print the data as per format given below

Customer

Code No Name Total Bill Amount
----------------------------------------------------------------




----------------------------------------------------------------
Grand Total

Print the Grand total in word format as

If Grand total is 8769
Print as EIGHT SEVEN SIX NINE



till now i have done the following code but i am struck with the looping where i have to take n users...
if anyone can plz modify he code and tell me...
Expand|Select|Wrap|Line Numbers
  1. class customer
  2. {
  3. private:
  4.     int ncust;
  5.     int *codeno;
  6.     char **name;
  7.     int *tbill;
  8.     char name[20];
  9.     int grandttl;
  10.  
  11. public:
  12.     void ct_accept (void);
  13.     void ct_print (void);
  14. };
  15. //Function
  16.  
  17. #include<iostream.h>
  18. #include<string.h>
  19. #include <iomanip.h>
  20.  
  21.  
  22.  
  23. void customer::ct_accept(void)
  24. {
  25.     cout<<"Enter Customer Code no.: ";
  26.     cin>>codeno;cin.get();
  27.     cout<<"Enter Customer Name: ";
  28.     cin.getline(name,20);
  29.     cout<<"Enter Customer Grand Total: ";
  30.     cin>>grandttl;
  31. }
  32.  
  33. void customer::ct_print(void)
  34. {
  35.     /*int num;
  36.     cout<<"Enter the Number of Customers: ";
  37.     cin>>num;*/
  38.  
  39.     cout<<endl << "Customer Code No. ";
  40.     cout<<"Customer Name                 ";
  41.     cout<<"Grand Total      ";
  42.     cout << endl;
  43.     for(int i=0;i<=62;i++)
  44.     {
  45.         cout<<"-";
  46.     }
  47.     cout<<endl;
  48.  
  49.     cout<<setw(10) << codeno;
  50.     cout<<setw(30) << name;
  51.     cout<<setw(20) << grandttl;
  52.     cout<<endl;
  53.  
  54.     for(i=0;i<=62;i++)
  55.     {
  56.         cout<<"-";
  57.     }
  58. cout<<endl;
  59. cout<<"Grand Total: ";    
  60. int word,rem, store[100000];
  61. if(grandttl==0)
  62. {
  63.     cout<<"zero";
  64. }
  65. else
  66. {
  67.  
  68.     while(word!=0)
  69.     {
  70.     word=grandttl/10;
  71.     rem=grandttl%10;
  72.  
  73.     store[i]=rem;
  74.     i++;
  75.     grandttl=word;    
  76.     }    
  77.  
  78. i--;
  79. for(i;i>=0;i--)
  80. {
  81.     store[i];    
  82.  
  83. switch(store[i])
  84.         {
  85.         case 0:
  86.         cout<<"zero ";
  87.         break;
  88.  
  89.         case 1:
  90.         cout<<"one ";
  91.         break;
  92.  
  93.         case 2:
  94.         cout<<"two ";
  95.         break;
  96.  
  97.         case 3:
  98.         cout<<"three ";
  99.         break;
  100.  
  101.         case 4:
  102.         cout<<"four ";
  103.         break;
  104.  
  105.         case 5:
  106.         cout<<"five ";
  107.         break;
  108.  
  109.         case 6:
  110.         cout<<"six ";
  111.         break;
  112.  
  113.         case 7:
  114.         cout<<"seven ";
  115.         break;
  116.  
  117.         case 8:
  118.         cout<<"eight ";
  119.         break;
  120.  
  121.         case 9:
  122.         cout<<"nine ";
  123.         break;
  124.  
  125.         }
  126.  
  127.  
  128. }
  129.  
  130. }    
  131. }
  132.  
  133.  
  134. main()
  135. {
  136.     customer rec;
  137.     rec.ct_accept();
  138.     rec.ct_print();
  139.     cin.get();
  140.     cin.get();
  141.     return 0;
  142. }
Mar 6 '07 #1
2 2015
DeMan
1,806 1GB
The code is a little difficult without "code" tags, however I think (if I understand what you ask) that you would want to change the for loop to loop while i<= num (that is, the number of customers the user entered)
Mar 6 '07 #2
horace1
1,510 Expert 1GB
couple of immediate things to notice
Expand|Select|Wrap|Line Numbers
  1. class customer
  2. {
  3. private:
  4.     int ncust;
  5.     int *codeno;      <<<   why is this a pointer
  6.     char **name;      <<  definintion of name
  7.     int *tbill;
  8.     char name[20];   ,,  definition of name
  9.     int grandttl;
  10.  
  11.  
should variable codeno be a pointer ? - you read it as an int in
Expand|Select|Wrap|Line Numbers
  1. void customer::ct_accept(void)
  2. {
  3.     cout<<"Enter Customer Code no.: ";
  4.     cin>>codeno;cin.get();
  5.  
you have variable name defined twice!
Mar 6 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Bo Peng | last post by:
Dear List, It is not clear what the title means. :-) Here is the details: I need to manage a big bunch of small objects, like struct{ int a; int b; }obj;
1
by: JuanPedro | last post by:
OS: Windows XP Home SP2 CPU/Ram: Mobile AMD Duron 4, 1GHz / 256MB System Manufacturer: Compaq Presario 730us Using windiag.exe to test my RAM I get a consistent error for the following address:...
4
by: Jason Heyes | last post by:
What can I do to circumvent the performance degradation associated with dynamic allocation and small objects? Thanks.
16
by: mamo74 | last post by:
Hello. I am administering a SQL Server (Enterprise Edition on Windows 2003) from some month and can't understand what is going on in the latest week (when the db grow a lot). The DB is around...
12
by: jl_post | last post by:
Dear C++ community, I have a question regarding the size of C++ std::strings. Basically, I compiled the following code under two different compilers: std::string someString = "Hello, world!";...
1
by: Ramprasad A Padmanabhan | last post by:
I have written a simple script to search a word in an array But bsearch does not seem to work here. I know I am missing out something very simple , But I am not able to find out what Thanks...
9
by: anonymous | last post by:
The following program : #include <stdio.h> void func ( char * psz ) { char * sz = "func"; psz = sz; } int main() {
7
by: nas | last post by:
Consider this example program which i hav taken from some site #include <iostream> using namespace std; class Base1 { public: virtual void f() { } };
1
by: pilafi | last post by:
void CSVImageIO::Read( void * buffer) { char onedataline; char *tmp=0; double d=0; unsigned short data=0; unsigned short * inptr = static_cast< unsigned short * >( buffer ); unsigned...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.