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

Application The project requires the design and implementation of an application

ID: 3819811 • Letter: A

Question

Application

The project requires the design and implementation of an application program that maintains the membership roster for an organization such as a club or a charity. The roster contains member names and mailing addresses.

Members can be individuals or families, which have a head of household and a partner or children, or both. There can be:

couples without children

couples with children

single parents with children

The input for the roster comes from a file with records like this:

id   type   name   address       city       state   zip

For family memberships, only the head of household has address information, since everyone lives at the same place.

Here’s an example of a file with an individual membership and several family memberships that illustrate the different options. Note that there are two formats, one for individuals and head of households, and another for partners and children.

1000

I

Jack Jones

1200 South Central Ave

Sunset Dunes

CA

99456

2000

H

John Smith

100 West Shady Lane

Hemet

CA

99123

2000

P

Joan Smith

2000

C

Sally Smith

2000

C

Billie Smith

2000

C

Bobbie Smith

300

H

Fred Brown

700 North Ocean Drive

Long Beach

CA

94327

300

P

Marcia Jones

4000

H

Paul Sims

400 East Grand Blvd

Walnut

CA

92155

4000

C

Mary Sims

4000

C

Doug Sims

Each row of the table is a file line, terminated by an end-of-line. Each column is a field within the line, delimited by a tab.

For this project, you may assume that the input file is well-formed: nothing out of order within a family membership and no duplicate id numbers.

Functions:

The roster program must have these functions:

Roster::LoadRoster: Load the roster from a file, given the file’s name

Roster::ShowAllMemberships: Show the entire roster

Roster::ShowOneMembership Show a single membership’s name(s) and address(es), given an id number.

Roster::RemoveMembership: Remove a membership, given an id number

Roster::StoreRoster: Store an updated roster in a file, given the file’s name, which doesn’t have to be the same file from which the roster was loaded.

The two Show functions have an argument called an ostream (an output stream) where they are expected to write their text. The ostream is a class with the STL’s iostream library. It’s used in the same manner as a file or the cout console output stream. Here’s a code fragment that illustrates this:

#include <iostream>

using namespace std;

ShowAllMemberships(ostream& stream)

{

   stream << “This is ShowAllMemberships.” << endl;

}

The stream argument is used in exactly the same manner as cout or an fstream object such as file. When writing to the stream, don’t end lines by inserting ’ ’ into the text—use the endl manipulator. The text that you write will be compared against an expected text stream and the line break characters are included in the comparison. A ‘ ’ may cause a test to fail; the endl character depends on the platform (Windows, Linux, Mac OS) where the program is running and isn’t always ‘ ’.

The Show functions must write text in the same format as the input file. ShowAll’s output should look exactly like the input file (assuming there were no Removes); ShowOne’s output should look exactly like the membership’s section of the input file.

Implementation:

You are to use the Standard Template Library (STL) std::map class to hold member information.

Mapguide.pdf: This is a quick guide to the relevant map functions—insert, find, and erase—including how to insert a key/data pair.

Remember that the nodes of a tree, which is the structure that the STL map implements, are key/data pairs. The map’s insert function takes a key and an associated data element, which can be anything, including a structure. The structure can have anything as a member, including other STL containers.

You may find it necessary to use other STL containers within the map’s data elements. A description of the STL classes and their functions can be found at http://www.cplusplus.com/reference/stl/

1000

I

Jack Jones

1200 South Central Ave

Sunset Dunes

CA

99456

2000

H

John Smith

100 West Shady Lane

Hemet

CA

99123

2000

P

Joan Smith

2000

C

Sally Smith

2000

C

Billie Smith

2000

C

Bobbie Smith

300

H

Fred Brown

700 North Ocean Drive

Long Beach

CA

94327

300

P

Marcia Jones

4000

H

Paul Sims

400 East Grand Blvd

Walnut

CA

92155

4000

C

Mary Sims

4000

C

Doug Sims

Explanation / Answer

public class CludOrganization {
private String name;
private Student president;
private Student vicePresident;
private LinkedList<clubs> members;

public CludOrganization(String name) {
this.name = name;
this.members = new LinkedList<Student>();
this.president = null;
this.vicePresident = null;
}
  
public CludOrganization(String name, String f) {
this(name);
try {
Scanner scan = new Scanner(new File(f));
while (scan.hasNextLine() ) {
String line = scan.nextLine();
System.out.println(line);
String[] tokens = line.split(",");
Student s = new Student(tokens[0], tokens[1], tokens[2]);
addMember(s);
}
}
catch (IOException e) {
System.out.println("Was not able to read file.");
}
}
  
  
public String getName() {
return name;
}

public void addMember(Student s) {
if (!members.contains(s)){
members.add(s);
}
}
  
public void addPresident(Student p) {
if (this.president == null) {
addMember(p);
this.president = p;
}
else
System.out.println("This organization has already a president.");
}
  
  
public void removePresident() {
this.president = null;
}
  
public String toString(){
String s = "Organization Name: " + this.name + " ";
s = s + "President: " + this.president ;
s = s + " Vice President: " + this.vicePresident + " ";
s = s + "There are " + members.size() + " total members in the Org: ";
for (int i = 0; i < members.size(); i++)
s = s + members.get(i);
return s;
}
  
  
public boolean isMember(Student s){
return members.contains(s);
}

public void removeYearMembers(String year) {
for (int i=members.size()-1; i>=0; i--) {
Student st = members.get(i);
String s = st.getYear();
if (s.equals(year))
members.remove(i);
}
}
  
public LinkedList<clubs> commonMembers(StudentOrganization other) {
LinkedList<Student> result = new LinkedList<Student>();
for (int i = 0; i < this.members.size(); i++) {
Student current = this.members.get(i);
if (other.isMember(current))
result.add(current);
}
return result;
}
  
public static void main (String [] args){
ClubOrganization donuts = new ClubOrganization("xxxxxxx", "xxxxxxxxxx.txt");
Student tif = new Student("Tiffany Ang", "tang","2017");

System.out.println();
System.out.println("xxxxxxxxxxxxxxxxxxxxxx " + donuts.isMember(tif));
;
  
ClubOrganization cs = new ClubOrganization("cs");
cs.addMember(tif);

System.out.println(" dddddddddddddd:");
System.out.println(cs.commonMembers(donuts));
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote