PDA

View Full Version : Can anyone write a program for me?


PCWORM
22-11-2007, 10:28 PM
This question might feel a little dumb.. but im desperately in need of a program written to practice it
for my practical exam which is going to be held 2morrow.... im not stressing ne1 to help (coz this kind of help is not normally asked for)...im just
looking 4 ne1 who has sum time to help me......thnx in advance!!!!

the question for the program:

Write a program to declare a class 'Account' having data members as Account_no and Balance.
Accept this data for 10 accounts and display data of accounts having balance greater than 5000

The_Devil_Himself
22-11-2007, 10:36 PM
first of all this is not the section for your question.u should have used programming section.

xbonez
22-11-2007, 10:43 PM
oh! damn easy....and no constructors shouldn't be needed since u don't need to intialize a value. btw, r u in 12th??

m feeling too lazy to write prog now...sorry...will post in an hour or so...playing FEAR PM abhi...

harryneopotter
22-11-2007, 10:47 PM
i dnt see any need for constuctor here ...........

try this .....


#include<iostream.h>
#include<conio.h>
class Account {

int Account_no,Balance;
} holder[10];

void main()
{ int i ;

for (i=0; i<10;i++)
{cout<<"\nEnter account no for Account "<<i+1<<" :";
cin>>holder[i].Account_no;
cout<<"\nEnter Balance for this account :";
cin>>holder[i].Balance;
}

for(i=0; i<10;i++)
{if(holder[i].Balance>5000)
{cout<<"\nAccount No :"<<holder[i].Account_no;
cout<<"\tBalance :'<<holder[i].Balance;
}
}
getch();
}




try to run it as i havent checked it ....... let me knw if dsnt give the desired output.

The_Devil_Himself
22-11-2007, 11:18 PM
^^
ravi@ravi-desktop:~$ g++ 2.cpp
In file included from /usr/include/c++/4.1.3/backward/iostream.h:31,
from 2.cpp:1:
/usr/include/c++/4.1.3/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
2.cpp:2:18: error: conio.h: No such file or directory
2.cpp:21: error: missing terminating " character
2.cpp:8: error: ‘::main’ must return ‘int’
2.cpp: In function ‘int main()’:
2.cpp:5: error: ‘int Account::Account_no’ is private
2.cpp:13: error: within this context
2.cpp:5: error: ‘int Account::Balance’ is private
2.cpp:15: error: within this context
2.cpp:5: error: ‘int Account::Balance’ is private
2.cpp:19: error: within this context
2.cpp:5: error: ‘int Account::Account_no’ is private
2.cpp:20: error: within this context
2.cpp:22: error: expected primary-expression before ‘}’ token
2.cpp:22: error: expected `;' before ‘}’ token
2.cpp:24: error: ‘getch’ was not declared in this scope
ravi@ravi-desktop:~$


???

T159
23-11-2007, 12:00 AM
i dnt see any need for constuctor here ...........

try this .....


#include<iostream.h>
#include<conio.h>
class Account {

int Account_no,Balance;
} holder[10];

void main()
{ int i ;

for (i=0; i<10;i++)
{cout<<"\nEnter account no for Account "<<i+1<<" :";
cin>>holder[i].Account_no;
cout<<"\nEnter Balance for this account :";
cin>>holder[i].Balance;
}

for(i=0; i<10;i++)
{if(holder[i].Balance>5000)
{cout<<"\nAccount No :"<<holder[i].Account_no;
cout<<"\tBalance :'<<holder[i].Balance;
}
}
getch();
}



try to run it as i havent checked it ....... let me knw if dsnt give the desired output.
Use getter and setter method to access private variable, u r violating the concept of encapsulation

Dont use conio.h - its not ANSI compliant

Use int main() and put a return 0; at the program end

NOTE: These r just my intrepretations

The_Devil_Himself
23-11-2007, 12:02 AM
^^hey T159 can you debug this program and post the working one please.

T159
23-11-2007, 12:24 AM
#include<iostream.h>
#include<stdio.h>

class Account {
//private members cant be accessed outside class directly
private:
int accountNo,balance;

//instead use getter and setter methods to access variable
public:
void setAccountNo(int accountNo)
{
this->accountNo = accountNo;
}

void setBalance(int balance)
{
this->balance = balance;
}

int getAccountNo()
{
return (accountNo);
}

int getBalance()
{
return(balance);
}
} holder[10]; //creates 10 references of class account as an array

int main()
{
int i,accountNo,balance;

//this loop take the values in each object variables
for (i=0; i<10;i++)
{
cout<<"\nEnter account no for Account "<<i+1<<" :";
cin>>accountNo;
holder[i].setAccountNo(accountNo);

cout<<"\nEnter Balance for this account :";
cin>>balance;
holder[i].setBalance(balance);
}

for(i=0; i<10;i++)
{
if(holder[i].getBalance()>5000)
{
cout<<"\nAccount No :"<<holder[i].getAccountNo();
cout<<"\tBalance :'"<<holder[i].getBalance();
}
}

getchar();
return(0);
}

///////////////////////////
/* this will work surely but u might consider using file operations and be sure if u want to clear screen then include conio.h and use clrscr (though i wouldnt recommend doing this), my fingers are aching am quitting now*/

^^hey T159 can you debug this program and post the working one please. done man:D

The_Devil_Himself
23-11-2007, 12:25 AM
it works perfectly.Thanks a lot T159.

T159
23-11-2007, 12:27 AM
it works perfectly.Thanks a lot T159.
:D:):D