0% found this document useful (0 votes)
7 views

Lab 3 Classes

Uploaded by

Tamara Enad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Lab 3 Classes

Uploaded by

Tamara Enad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Object Oriented Programming I with C++

Lab#3 Classes

Date 3/23/2021 (5PM-8PM)

Question:

A. Define a class named Customer that holds private fields for a customer ID number, last
Customer name, first name, and credit limit. Include four public functions that set one of the
four fields. Do not allow any credit limit over JD10,000. Include a public function that displays a
Customer’s data. Write a main() function in which you declare a Customer, set the Customer’s
fields, and display the results. Save the file as Customer.cpp

B. Write a main() function that declares an array of five Customer objects. Prompt the user for
values of each Customer, and display all five Customer objects. Save the file as Customer2.cpp
Solution of Part A:

#include<iostream> void Customer::displayCustData()


#include<string> {
class Customer cout<<"\n\n Customer Details: \n";
{ cout<<"Customer ID: "<< Customer_ID <<endl;
private: cout<<"First Name: "<<
int Customer_ID; Customer_FirstName<<endl;
string Customer_FirstName; cout<<"Last Name: "<<
string Customer_LastName; Customer_LastName<<endl;
float Credit_Limit; cout<<"Credit Limit: "<< Credit_Limit<<endl;
public: }
void setID(int);
void setfirstname(string); int main()
void setlastname(string); {
void setcredit(float); Customer Cust1;
void displayCustData(); int ID;
}; string Fname, Lname;
float Climit;
void Customer::setID(int ID) cout<<"Please Enter Customer ID: ";
{Customer_ID = ID;} cin>>ID;
Cust1.setID(ID);
void Customer::setfirstname(string Fname) cout<<"Please Enter Customer First Name: ";
{Customer_FirstName = Fname;} cin>>Fname;
Cust1.setfirstname(Fname);
void Customer::setlastname(string Lname) cout<<"Please Enter Customer Last Name: ";
{Customer_LastName = Lname;} cin>>Lname;
Cust1.setlastname(Lname);
void Customer::setcredit(float CreditLimit) cout<<"Please Enter Credit Limit: ";
{ cin>>Climit;
if (CreditLimit>=10000) Cust1.setcredit(Climit);
Credit_Limit = 10000; Cust1.displayCustData();
else return 0;}
Credit_Limit = CreditLimit;
}
Solution of Part B:

#include<iostream> void Customer::displayCustData()


#include<string> {
class Customer cout<<"\n\n Customer Details: \n";
{ cout<<"Customer ID: "<< Customer_ID <<endl;
private: cout<<"First Name: "<< Customer_FirstName<<endl;
int Customer_ID; cout<<"Last Name: "<< Customer_LastName<<endl;
string Customer_FirstName; cout<<"Credit Limit: "<< Credit_Limit<<endl;
string Customer_LastName; }
float Credit_Limit;
public: int main()
void setID(int); {
void setfirstname(string); Customer Customers[5];
void setlastname(string); int ID;
void setcredit(float); string Fname, Lname;
void displayCustData(); float Climit;
}; for(int i=0;i<=4;i++)
{
void Customer::setID(int ID) cout<<"Please Enter Customer ID: ";
{Customer_ID = ID;} cin>>ID;
Customers[i].setID(ID);
void Customer::setfirstname(string Fname) cout<<"Please Enter Customer First Name: ";
{Customer_FirstName = Fname;} cin>>Fname;
Customers[i].setfirstname(Fname);
void Customer::setlastname(string Lname) cout<<"Please Enter Customer Last Name: ";
{Customer_LastName = Lname;} cin>>Lname;
Customers[i].setlastname(Lname);
void Customer::setcredit(float CreditLimit) cout<<"Please Enter Credit Limit: ";
{ cin>>Climit;
if (CreditLimit>=10000) Customers[i].setcredit(Climit);
Credit_Limit = 10000; }
else
Credit_Limit = CreditLimit; for(int j=0;j<=4;j++)
} {
cout<<"\n************************** \n";
Customers[j].displayCustData();
}
return 0;}

You might also like