Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

please solve below questions both in c++ and java and send answers urgently required

+1 vote
asked May 5, 2021 by Jahanvi Giriya (240 points)
A) Write any five attributes names of Person. Design and write Person class with that attributes and make two methods. One method is used to input values of attributes and second method is used to display values of attributes in proper format.

 B) Create class the point must include members such as X and Y, and make member function setX(int x), setY(int y) and setXY(int x, int y) to set the value of respective coordinates. Make one more member function to display point values in coordinator format.

C) Define a class to represent a Bank account. Include the following members. Data members: Name of the depositor Account number Type of account Balance amount in the account. Rate of interest (static data) Also make member functions to deposit amount, to withdraw amount after checking for minimum balance, to display all the details of an account holder and display rate of interest (a static function).

2 Answers

0 votes
answered May 5, 2021 by Peter Minarik (53,530 points)
edited May 5, 2021 by Peter Minarik

This looks like an assignment to me.

Your best interest here is to try to solve it yourself.

When you've got a solution, you may post it here and ask for second opinion.

The goal is that you learn the basics (these questions are really revolving around the basics). If you just copy someone else's solution and submit that in your assignment, then you will learn nothing and you'll just struggle with future assignments.

So go ahead, do some research. Try to write some code.

Good luck!

Note

There are plenty of tutorial pages and reference pages for both C++ and Java. I'll include a pair. Feel free to use your preferred tutorial pages instead:

Also, in the solution of this problem I posted a simple C++ class so you can see an example there too.

commented May 5, 2021 by Jahanvi Giriya (240 points)
is it correct please guide?

import java.util.*;
import java.util.Scanner;  


class people{
    int age,idnum ;
    String nameofp,city,education;
    people(int a, int id, String nam, String cty, String educ){
       age = a;
       idnum = id;
       nameofp = nam;
       city = cty;
       education = educ;
   }
   
   
    public static void main(String args[]){
    getdata();
    printdata();
}


    public static void getdata(){
      Scanner scan=new Scanner(System.in);
        System.out.println("Enter id of person:: ");
        int idnum=scan.nextInt();
        System.out.println("Enter name of person:: ");
        String nameofp = scan.nextLine();
        System.out.println("Enter city of person:: ");
        String city = scan.nextLine();
        System.out.println("Enter age of person:: ");
        int age=scan.nextInt();
        System.out.println("Enter education of person:: ");
        String education = scan.nextLine();
       
       
    }
    public static void printdata(){
        int age,idnum ;
        String nameofp,city,education;
       
        System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.println("Id of person:: " + idnum);
        System.out.println("Name of person:: "+ nameofp);
        System.out.println("City of person:: " + city);
        System.out.println("Age of person:: " + age);
        System.out.println("Education of person:: " + education);
    }
}
commented May 5, 2021 by Peter Minarik (53,530 points)
edited May 5, 2021 by Peter Minarik
If you compile the code (select Java in the top right corner) you can see there are 5 compilation errors.

Also, the naming could be better. E.g. "people" refers to multiple human beings. The grammatically / logically right name for the class would be "Person". With a capital "P". Classes usually are named according to UpperCamelCase.

Your functions getdata() and printdata() must be instance functions and not static functions (remove static) otherwise they won't be able to access non-static members, such as age, id, name, etc.

Furthermore, as explained in http://question.onlinegdb.com/9869/please-solve-errors-of-the-program, if you create a local variable within a function, then others won't be able to see those variables outside of that function.

You should use your member variables in your class and set their value in getdata(), not set local values.

Also, with this setup, I believe your constructor should not do anything, not set any values as that will be the role of getdata().

Last, but not least, in the main() method, you need to instantiate the people (please, call it Person XD) class and call it's getdata() and printdata() functions.

Oh, some more. :) You should provide a visibility modifier for your class fields (member variables) and functions to indicate if they are public/private.
0 votes
answered May 6, 2021 by MANI GARG (160 points)
b.

#include<iostream>
using namespace std;
class Point
{
    private:
    int x;
    int y;
    public:
    Point()
    {
        x=0;
        y=0;
    }
    void setX(int x)
    {
        this->x=x;
    }
    void setY(int y)
    {
        this->y=y;
    }
    void setXY(int x,int y)
    {
        this->x=x;
        this->y=y;
    }
    void display()
    {
        cout<<"( "<<x<<" , "<<y<<" )";
    }
};
int main()
{
    Point p;
    p.setX(5);
    p.setY(6);
    p.display();
    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...