Question

Object Oriented Programming C++ using class I need users (customers) to input their name and id....

Object Oriented Programming C++ using class

I need users (customers) to input their name and id.

Program needs to have a menu:

1. Create - input id, name

2. List - see all the list of the users

3. Exit.

It should be limited to 20 users only.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE FOR THE GIVEN PROGRAM:

#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

// Class having instance variable name and id
class user{
string name;
int id;
public:
// Member function to get id and name
void getter(){
cout<<"Enter your id:\n";
cin>>id;
// remaining input characters up to the next newline character
// are ignored
cin.ignore(256, '\n');
cout<<"Enter your name:\n";
getline(cin,name);
}
// Member function to show id and name
void show(){
cout<<"The id is: "<<id<<endl;
cout<<"The name is: "<<name<<endl;
}
};

//Driver function
int main()
{
user obj[20]; // array of class object
int choice; //varable to store choice enter by user
char ans='y';
cout<<"Menu:\n";
cout<<"1- Create input-id,name\n";
cout<<"2- display the list\n";
cout<<"3- Exit\n";
cin>>choice;
  
while(ans=='y'|| ans=='Y'){
// Switch block to give output as per user choice
switch(choice){
case 1:
for (int i=0;i<20;i++){
obj[i].getter();
}
break;
case 2:
for (int j=0;j<20;j++){
obj[j].show();
}
break;
case 3: exit(1); //function to terminate program if user's choice is 3
}
cout<<"Want to Enter more. Press Y/y\n";
cin>>ans;
cout<<"Menu:\n";
cout<<"1- Create input-id,name\n";
cout<<"2- display the list\n";
cout<<"3- Exit\n";
cin>>choice;
}
return 0;
}

SCREENSHOT OF THE PROGRAM:

SAMPLE OUTPUT:

Sample output have been taken for only two users.

HAPPY LEARNING

Add a comment
Know the answer?
Add Answer to:
Object Oriented Programming C++ using class I need users (customers) to input their name and id....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Object Oriented Programming using class c++ Program where the users (customers) can add Product name, Product...

    Object Oriented Programming using class c++ Program where the users (customers) can add Product name, Product Price, Product Quantity. Program needs a menu: 1. Add item 2. Get total 3. Display all items

  • You are asked to build and test the following system using Java and the object-oriented concepts ...

    You are asked to build and test the following system using Java and the object-oriented concepts you learned in this course: Project (20 marks) CIT College of Information technology has students, faculty, courses and departments. You are asked to create a program to manage all these information's. Create a class CIT to represents the following: Array of Students, each student is represented by class Student. Array of Faculty, each faculty is represented by class Faculty. Array of Course, each course...

  • BMI Class. Using JAVA write Object Oriented Programming by creating class, object and method , that...

    BMI Class. Using JAVA write Object Oriented Programming by creating class, object and method , that takes users' input (weight and Height) and calculates the BMI. If the result is less than 18.5 display "you are underweight", if the result is greater than 18.5 display "you have a normal weight", if the result is greater than 24.9 display "your weight is considered overweight", and the result is greater than 30 display "your weight is considered as obese" (BMI = 703...

  • Write a python program using Object Oriented and do the following: 1. create class "cat" with...

    Write a python program using Object Oriented and do the following: 1. create class "cat" with the following properties: name, age (create constructor method: def __init__) 2. create class "adopter" with the following properties: name, phone 3. create class "transaction" with these properties: adopter, cat (above objects) cat1 = "puffy, 2" adopter1 = "Joe, 123" Test your program: Joe adopts puffy. Print: "Per Transaction 1 <joe> has adopted <puffy>" this can only be done with object oriented programming, no way...

  • I Need Help with this using Java Programming : Class name fname lname Class variable total...

    I Need Help with this using Java Programming : Class name fname lname Class variable total Number Constructor (no arguments) Constructor (takes two arguments, fname and lname) One getter method to return the fname and lname One setter method for fname and lname Inside Main: Create three objects with the following names Jill Doe John James Jack Smith When creating the first object (Should not be an anonymous object) use the argument-less constructor Then use the setter method to assign...

  • *Python* INTRODUCTION: The goal of this programming assignment is to enable the student to practice object-oriented...

    *Python* INTRODUCTION: The goal of this programming assignment is to enable the student to practice object-oriented programming using classes to create objects. PROBLEM DEFINITION: Write a class named Employee that holds the following data about an employee in attributes: name, IDnumber, department, jobTitle The class should have 8 methods as follows:  For each attribute, there should be a method that takes a parameter to be assigned to the attribute. This is known as a mutator method.  For each...

  • c++ object oriented programming

    object oriented programming:Write a program that converts a number entered in decimal toRoman numerals. Your program should consist of a class, say, romanType. Anobject of type romanType should do the following:a. Store the number as a decimal.b. Convert and store the number into roman form.c. Print the number as a Roman numeral or decimal number as requestedby the user.The decimal values of the Roman numerals are:M 1000D 500C 100L 50X 10V 5I 1

  • C# Goals: Practice building a class Use object oriented programming to solve a problem Problem Description:...

    C# Goals: Practice building a class Use object oriented programming to solve a problem Problem Description: Create a Windows Console Application using the .NET Framework For this application you will be designing a program that allows users to keep track of robot inventory. First, you will design a Robot class, and then build an application that creates Robot objects. Important formulas / relationships: Before we begin designing robots, we should understand a few key electrical terms and relationships. Terms: Voltage...

  • Write a program to create a set operation calculator applying object oriented programming principles discussed in...

    Write a program to create a set operation calculator applying object oriented programming principles discussed in the class so far. The set operation calculator need to be enclosed inside one class with different methods responsible for performing the different operations listed below. When the constructor (def __init__() ) is called during object instantiation, two separate objects of this class need to be instantiated two sets S1 and S2. These two set objects can be instantiated from two python lists taken...

  • Programming Assignment 6: Object Oriented Programming Due date: Check Syllabus and Canvas Objectives: After successfully completing...

    Programming Assignment 6: Object Oriented Programming Due date: Check Syllabus and Canvas Objectives: After successfully completing this assignment, students will practice Object Oriented design and programming by creating a Java program that will implement Object Oriented basic concepts. RetailItem Class: Part 1: Write a class named RetailItem that holds data about an item in a retail store. The class should have the following fields: • description. The description field references a String object that holds a brief description of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT