Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop a C++ application on the UNIX operating system. The application defines

ID: 671796 • Letter: D

Question

Develop a C++ application on the UNIX operating system. The application defines and uses two classes: Customer and Contact. The Customer class has a vector of Contact as a one of the data members.

II. Requirements:

1. The class Customer should be implemented based on the class diagram shown below:
Customer
-CompanyName: String
-Address: String
-City: String
-State: String
-Zip: String
-Contacts: vector <Contact>
«constructor»+ Customer()
«constructor»+ Customer(companyname:String, address:String, city:String state:String, zip: String)
+setCompanyName(company_name: String)
+getCompanyName(): String
+setAddress(address: String)
+setCity(city: String)
+setState(state: String)
+setZip(zip: String)
+getAddress(): String
+getCity(): String
+getState(): String
+getZip(): String
+getFullAddress(): String
+addContact(contact: Contact)
+RemoveContact(contact: Contact): bool
+listContacts(): String

2. The class Contact should be implemented based on the class diagram shown below:
Contact
-FirstName: String
-LastName: String
-Phone: String
«constructor»+ Contact()
«constructor»+ Contact(firstname:String, lastname: String, phone: String)
+setFirstName(firstname: String)
+setLastName(lastname: String)
+getFirstName(): String
+getLastName(): String
+setPhone(phone: String)
+getPhone(): String
+getContactInfo(): String

3. Description of the member functions for class Customer
*Customer() This constructor initializes CompanyName, Address, City, Zip to a zero-length string ("").
*Customer(address: String, city: String, state: String, zip: String) This constructor initializes CompanyName, Address, City, State and Zip using the arguments passed in.
*setCompanyName(), setAddres(address:String), setCit(city:String), setZip(zip:String) These setter functions update corresponding data members.
*getCompanyName(), getAddress(), getCity(), getZip() These getter functions returns corresponding data members.
*getFullAddress() returns the combined address with this format: <address>,<City>,<State>,<Zip>
*addContact(contact: Contact) Add a contact to the vector of Contact
*removeContact(contact: Contact) Compare the argument with the contacts in the vector of Contact, if the first name, last name and phone number match, remove the contact from the vector
*listContacts() Return a String that contains information of all contacts. The information of each contact is obtained by calling the getContactInfo of the Contact class.
Note: The word "return" in the description above means the "return" keyword in C++, rather than display on screen.

4. Description of the member functions for class Contact
*Contact() This default constructor initializes FirstName, LastName and Phone to zero-length string ("").
*Contact(firstname:String, lastname: String, phone: String) This constructor initializes FirstName, LastName and Phone using the arguments passed in.
*setFirstName(firstname: String) setLastName(lastname: String) setPhone(phone: String) These setter functions update corresponding data members.
*getFirstName(): String getLastName(): String getPhone(): String These getter functions returns corresponding data members.
*getContactInfo(): String returns a String with this format: <First Name> <Last Name> < Phone>
Note: The word "return" in the description above means the "return" keyword in C++, rather than display on screen.

5. Write a driver program as the client of the Customer class. It should instantiate an object of the Cusotmer class; then it should demonstrate the use of all member functions. However, only one constructor should be used.

Explanation / Answer

1)

Public Function parseAddress(ByVal input As String) As Collection
input = input.Replace(",", "")
input = input.Replace(" ", " ")
Dim splitString() As String = Split(input)
Dim streetMarker() As String = New String() {"street", "st", "st.", "highway", "hwy", "hwy.", "road", "rd", "rd.", "lane", "ln", "ln.", }
Dim address1 As String
Dim address2 As String = ""
Dim city As String
Dim state As String
Dim zip As String
Dim streetMarkerIndex As Integer

zip = splitString(splitString.Length - 1).ToString()
state = splitString(splitString.Length - 2).ToString()
streetMarkerIndex = getLastIndexOf(splitString, streetMarker) + 1
Dim sb As New StringBuilder

For counter As Integer = streetMarkerIndex To splitString.Length - 3
sb.Append(splitString(counter) + " ")
Next counter
city = RTrim(sb.ToString())
Dim addressIndex As Integer = 0

For counter As Integer = 0 To streetMarkerIndex
If IsNumeric(splitString(counter)) _
Or splitString(counter).ToString.ToLower = "po" _
Or splitString(counter).ToString().ToLower().Replace(".", "") = "po" Then
addressIndex = counter
Exit For
End If
Next counter

sb = New StringBuilder
For counter As Integer = addressIndex To streetMarkerIndex - 1
sb.Append(splitString(counter) + " ")
Next counter

address1 = RTrim(sb.ToString())

sb = New StringBuilder

If addressIndex = 0 Then
If splitString(splitString.Length - 2).ToString() <> splitString(streetMarkerIndex + 1) Then
For counter As Integer = streetMarkerIndex To splitString.Length - 2
sb.Append(splitString(counter) + " ")
Next counter
End If
Else
For counter As Integer = 0 To addressIndex - 1
sb.Append(splitString(counter) + " ")
Next counter
End If
address2 = RTrim(sb.ToString())

Dim output As New Collection
output.Add(address1, "Address1")
output.Add(address2, "Address2")
output.Add(city, "City")
output.Add(state, "State")
output.Add(zip, "Zip")
Return output
End Function

Private Function getLastIndexOf(ByVal sArray As String(), ByVal checkArray As String()) As Integer
Dim sourceIndex As Integer = 0
Dim outputIndex As Integer = 0
For Each item As String In checkArray
For Each source As String In sArray
If source.ToLower = item.ToLower Then
outputIndex = sourceIndex
If item.ToLower = "box" Then
outputIndex = outputIndex + 1
End If
End If
sourceIndex = sourceIndex + 1
Next
sourceIndex = 0
Next
Return outputIndex
End Function
2) #include <iostream>
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
using namespace std;
// contact structure
struct Contact {
string name, street, city, email, phone, birthdate;
};
// global array
const int size = 20;
Contact entry[size];
// contacts database file
ofstream database;
// function prototypes
int addContact(const int);
void writeContactsToFile(void);
int main (int argc, char *argv[]) {
int menuChoice;
char response;
string line;
stringstream ss;
bool done = false;
int numContacts = 0;
while (done == false) {
// call loadContacts();
// display menu
cout << endl << endl
<< "Welcome to your address book! What would you like to do?"
<< endl << endl
<< "1. Print my contacts to the screen." << endl
<< "2. Add a contact." << endl
<< "3. Remove a contact." << endl
<< "4. Quit program." << endl << endl
<< "Choose 1, 2, 3, or 4: ";
getline(cin,line);
ss.clear(); ss.str(line);
if (!(ss >> menuChoice)) menuChoice = 0;
switch (menuChoice) {
case 1:
// call printContacts();
break;
case 2:
numContacts = addContact(numContacts);
cout << "Would you like to save your changes to contacts.txt? (y/n) : ";
getline(cin,line);
if ((ss >> response) && (response == 'y')) {
writeContactsToFile();
}
break;
case 3:
// call removeContact();
cout << "Would you like to save your changes to contacts.txt? (y/n) : ";
getline(cin,line);
if ((ss >> response) && (response == 'y')) {
writeContactsToFile();
}
break;
case 4:
cout << " Have a nice day!";
done = true;
break;
default:
cout << endl << "You did not enter a valid option." << endl;
break;
} // end case of menuChoice
} // end while not done
return 0;
}
// addContact function
int addContact(int n) {
// get information from user
cout << endl << "You wish to add a new contact." << endl;
cout << "Name? (Lastname, Firstname) : ";
getline(cin,entry[n].name);
cout << "Address? (9999 Boardwalk Ave.) : ";
getline(cin,entry[n].street);
cout << "City, state, & zip code? (City, State, Zip) : ";
getline(cin,entry[n].city);
cout << "e-mail address? (name@gmail.com) : ";
getline(cin,entry[n].email);
cout << "Phone number? (xxx-xxx-xxxx) : ";
getline(cin,entry[n].phone);
cout << "Birth date? (MM/DD/YYYY) : ";
getline(cin,entry[n].birthdate);

return n+1;
}
void writeContactsToFile() {
// open contacts.txt database to store user's input
database.open("contacts.txt", ios::out | ios::app);

database.close();
}

5)

package com.javatpoint;
import java.rmi.*;
import java.rmi.server.*;
import java.sql.*;
import java.util.*;
class BankImpl extends UnicastRemoteObject implements Bank{
BankImpl()throws RemoteException{}
  
public List<Customer> getCustomers(){
List<Customer> list=new ArrayList<Customer>();
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
PreparedStatement ps=con.prepareStatement("select * from customer400");
ResultSet rs=ps.executeQuery();
  
while(rs.next()){
Customer c=new Customer();
c.setAcc_no(rs.getInt(1));
c.setFirstname(rs.getString(2));
c.setLastname(rs.getString(3));
c.setEmail(rs.getString(4));
c.setAmount(rs.getFloat(5));
list.add(c);
}
  
con.close();
}catch(Exception e){System.out.println(e);}
return list;
} //end of getCustomers()
}