Write a C++ program that contains a structure named “Account” having four data members

1) Account number
2) Account holder name
3) Account type
4) Account Balance

Account type may be Saving, Current, etc.

In main function, declare an array of structure “Account” of size 10. Populate this array by taking data from user and store user account data into a structure.

The above account information for all users should also be stored in a text file that contains Account number, Account holder name, Account type and Account balance separated by comma (,).

When user enters all account information for all account holders then following menu should be displayed to the user:

• Enter 1 to search account information by Account number
• Enter 2 to search account information by Account holder name
• Enter 3 to search number of user having particular Account type
• Enter 4 to search number of user having Account balance greater than 10,000
• Enter 5 to quit from program


The program should repeat the above process from menu 1 to 4 until user enters 5.


Detailed description:


1. If user enters 1 then program should prompt the user to enter “Account number” to be searched. If the Account number found within array of structure then account information corresponding to the given account number should be displayed on the output screen otherwise it should display message: “Account information is not available”.

2. If user enters 2 then program should prompt the user to enter “Account Holder Name” to be searched. If the Account Holder name found within array of structure then account information corresponding to the given account holder name should be displayed on the output screen otherwise it should display message: “Account information is not available”.

3. If user enters 3 then program should prompt the user to enter “Account type” and then displays the number of users having particular account type. For example, if user enters Account type as “Saving” then it should display the number of user having account type saving otherwise it should display message: “No user has Account type Saving” and so on.

4. If user enters 4 then program should display the number of users having salary greater than 10,000 otherwise displays message: “No user has balance greater than 10,000”.

5. If user enters 5 then program should terminate.

What have you written so far?
I assume it should be in C++ since it is posted here.
What kind of problems do you have with your code?

http://www.daniweb.com/forums/announcement8-2.html

If you want us to complete the assignment for you, give me the name of your school and your professor so I can make sure I get the marks I deserve.

That said, what have you done so far? Do you have any sort of pseudo-code? Any plans on paper? Anything?

Here goes your code. Its compiled.

In case of any problem mail me at<snipped>

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

struct Account
{
       int num;
       char name[200];
       char type[200];
       double bal;
       };
       
       void search_by_act(struct Account *act,int num)
       {
       int i;
       for(i=0;i<10;i++)
       {
             
            if( act[i].num == num )
            {
            cout<<"Act info :"<<endl;
            cout<<"Act number:"<<act[i].num<<endl;
            cout<<"name:"<<act[i].name<<endl;
            cout<<"Act type:"<<act[i].type<<endl;
            cout<<"Act Bal:"<<act[i].bal<<endl;
            return ;
            }           
       }
       cout<<"\nNo such record";
                        
       }
       
       void search_by_name(struct Account *act,char *name)
       {
       int i,flag=0;
       for(i=0;i<10;i++)
       {
             
            if( strcmp(act[i].name,name)==0)
            {
            cout<<"Act info :"<<endl;
            cout<<"Act number:"<<act[i].num<<endl;
            cout<<"name:"<<act[i].name<<endl;
            cout<<"Act type:"<<act[i].type<<endl;
            cout<<"Act Bal:"<<act[i].bal<<endl;
            flag=1;
            }           
       }
       if(flag ==0)
       cout<<"\nNo such record";                        
       }
       void search_by_type(struct Account *act,char *type)
       {
       int i,flag=0;
       for(i=0;i<10;i++)
       {
             
            if( strcmp(act[i].type,type)==0)
            {
            cout<<"\n\nAct info :"<<endl;
            cout<<"Act number:"<<act[i].num<<endl;
            cout<<"name:"<<act[i].name<<endl;
            cout<<"Act type:"<<act[i].type<<endl;
            cout<<"Act Bal:"<<act[i].bal<<endl;
            flag=1;
            }           
       }
       if(flag ==0)
       cout<<"\nNo such record";                        
       }
       void search_by_bal(struct Account *act,double bal)
       {
       int i,flag=0;
       for(i=0;i<10;i++)
       {
             
            if( act[i].bal > bal)
            {
            cout<<"\n\nAct info :"<<endl;
            cout<<"Act number:"<<act[i].num<<endl;
            cout<<"name:"<<act[i].name<<endl;
            cout<<"Act type:"<<act[i].type<<endl;
            cout<<"Act Bal:"<<act[i].bal<<endl;
            flag=1;
            }           
       }
       if(flag ==0)
       cout<<"\nNo such record";                        
       }
int main()
{
    struct Account act[10];
    int in,i;
    int num;
    char name[200];
    char type[200];
    double bal;
  ofstream myfile;
  myfile.open ("output.txt");



    for(i=0;i<10;i++)
    {
    cout<<"\n\nEnter the "<<(i+1) <<" information:"<<endl;
    cout<<"Enter the account number";
    cin>>act[i].num;
    cout<<"Enter the name:";
    do{
    cin.getline(act[i].name,200);
}while(strcmp(act[i].name,"")==0);

    cout<<"Enter the type:";
    do{
    cin.getline(act[i].type,200);
}while(strcmp(act[i].type,"")==0);

cout<<"Enter balance:";
cin>>act[i].bal;
                     
myfile<<act[i].num<<","<<act[i].name<<","<<act[i].type<<","<<act[i].bal<<"\n";
}
cout<<"\noutput.txt is created , with the entered data, now\n";
  myfile.close();
while(1)
{
        cout<<"\n\nEnter 1 to search account information by Account number"<<endl;
        cout<<"Enter 2 to search account information by Account holder name"<<endl;
        cout<<"Enter 3 to search number of user having particular Account type"<<endl;
        cout<<"Enter 4 to search number of user having Account balance greater than 10,000"<<endl;
        cout<<"Enter 5 to quit from program"<<endl;
        cin>>in;
        switch(in)
        {
        case 1:
    cout<<"Enter the account number";
    cin>>num;
search_by_act(act,num);
             break;
        case 2:
    do{
    cin.getline(name,200);
}while(strcmp(name,"")==0);
search_by_name(act,name);
             break;
        case 3:
    cout<<"Enter the type:";
    do{
    cin.getline(type,200);
}while(strcmp(type,"")==0);
search_by_type(act,type);
             break;
        case 4:
search_by_bal(act,10000);
             break;
        case 5:
        system("pause");
        return 0;
             break;
             
        }

}
        system("pause");
        return 0;
}

Here goes your code. Its compiled.

Syed, did you read any-of the rules, before you even posted?

There's a good reason why you're not supposed to feed the bears. If you give them something for free, they'll expect that all the time and won't figure out how to feed themselves. It would seem that people can be the same way...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.