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

Develop a model of the problem you are developing. This is different from flowch

ID: 3769176 • Letter: D

Question


Develop a model of the problem you are developing. This is different from flowcharting. Make sure the model reflects the problem statement. You then need to develop a C++ program to solve the problem stated. Below is a typical problem statement expected for the assignment.

Define two classes with appropriate data members and member functions. Class Name is defined to handle the user first name and the last name. As a minimum, the class will have one string data member in the private access region of the class, a default constructor, and other accessor and mutating member functions in the public access region of the class. The class File is defined to handle the file names for input, output, and input/output purposes. As a minimum, the class will have one string data member in the private access region of the class, a default constructor, and other accessor and mutating member functions in the public access region of the class. Here is how the program will operate.

Upon execution of the program, an object of the class Name is created and its data member is set to your first name via the class constructor (there are different ways this can be done). Another object of this class is defined and obtains your last name from the keyboard and sets your last name (this can be a constructor or a mutating function). The program will then display your full name using the function displayName() to display your full name in the format shown below.

Firstname Lastname

The class Name provides for accepting the first name and the last name as needed by the program.

Once the first name and last name are displayed, the program prepares to write the first name and last name into a file. The program creates objects of the class File as explained here. The first object, sets the data member of the class to the file name associated with the first name via the class constructor, writes the first name to the file, and closes the file. The user is then prompted for the name of the file for writing the last name to the file. Once the last name is written to the file, the file is closed. The program will then open the two files and writes their contents to the screen in the format shown below.

First name

Last name

The program will then create a file object, gets the file name (for the full name) from the user, and writes the first name from the file that has the first name, and the last name from the file that has the last name and closes the files. The next step is for the program to prompt the user to read the contents of the file that has the full name. If the user entered yes, the program will display the full name in the format shown below.

Firstname Lastname

and closes the file. If the user entered no, the program proceeds to the next step.

The user is then prompted to try other user names and file names and repeats the process explained above.

Other member functions for the two classes are defined by the programmer and as a minimum will include constructors, destructors, accessor, and mutating functions. User-defined functions will be used as needed to solve your problem.

This program leaves out a few options for you to select. For example, writing first name, last name, and full name to their respective files and then retrieving them from these file and displaying them.

Notes:(please read very carefully)

 

1. Make sure your media is VIRUS FREE

2. Comment your program.

3. Use meaningful prompts.

4. Provide a detailed description of the problem you are solving.

6. NO global declarations allowed, except for the function prototypes and class declarations.

7. Use classes, member functions, files, and strings.

8. Full member -function prototyping is required. Member functions must have their purposes fully explained.

8A. No member function should be defined within a class (i.e., no body of a member function should be seen inside any of the classes you are defining)

9. Make sure to use constructors and destructors for the classes. A class may have more than one constructor.

10. Parameter passing to the user-defined functions, the class member functions and the return types will be specified by you. The function prototypes will clearly show the formal parameters and the return values.

11. Use data types as specified in the member function prototypes. All class data members will be in the private access region of the class

13. Use Microsoft Visual C++ .NET 2010 compiler using default compiler settings.

14. Use Microsoft Visio 2013 to develop your model.

15. Adherence to the ANSI C and  ANSI C++  required.  

16. Do not use <stdio.h> and <conio.h >

17. Do not use any #define in your program

18. No goto statements allowed

19. Non-compliance with these notes will cost points

Explanation / Answer

#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;

class Names
{
public:
void setFirstName( string first );
void setLastName( string last );
Names(double len); // constructor

private:
string firstName;
string lastName;
};

// constructor
Names::Names( string firstName, string lastName)
{
this.firstName = firstName;
this.lastName = lastName;
}
//setter methods
void Names::setFirstName( string first )
{
firstName = first;
}
void Names::setLastName( string last )
{
lastName = last;
}
// Main function
int main( )
{
while(true){
//reaing first and last names from user
cout<<" Enter first name: ";
string firstName,lastName,fileName;
cin>>firstName;
cout<<" Enter last name: ";
cin>>lastName;
//creating object
Names(firstName,lastName);
//readinf file name to output data
cout<<"Enter file name to write: ";
cin>>firstName;
//writing first and last names to file
ofstream out_data(fileName);
out_data <<firstName<<" "<<lastName;
cout<<"Entered data: "<<firstName<<" "<<lastName;
//reading filename to read
cout<<" Enter file name to read: ";
string readfileName;
cin>>readfileName;

std::ifstream readfile(readfileName);//reding names from text file
std::string eachline;
while (std::getline(readfile, eachline))
{
std::istringstream iss(eachline);
string first,last;
iss>>first>>last;
//priting first last name side by side
cout<<" Do you want to print: yes/no: ";
string choice;
cin>>choice;
if(choice == "yes"){
cout<<" "<<first<<" "<<last;
break;
}
}
}

return 0;
}