1 Enter your name student ID platform and date Name Class CI
1) Enter your name, student ID, platform and date
Name:
Class: CIS054 C/C++ Programming
Platform (Mac or PC):
Date:
2) PROJECT DESCRIPTION
Create an application that searches a file of male and female first names. A link to the file is provided on the class webpage. \"FirstNames2015.txt\" is a list of the most popular baby names in the United States and was provided by the Social Security Administration.
Each line in the file contains a boy\'s name and a girl\'s name. The file is space-delimited, meaning that the space character is used to separate the boy name from the girl name. The file begins with:
Noah Emma
Liam Olivia
Mason Sophia
Jacob Ava
William Isabella
Ethan Mia
James Abigail
Write a program that asks the user to enter a name. The program then searches the file for the name and displays the position of the name in the file if it matches either a boy name or a girl name. The program also displays a message if the name could not be found. Sample outputs:
Enter a name to search: Daniel
Daniel is ranked 12 for boy names
Daniel was not found for girls
Enter a name to search: Cassandra
Cassandra is ranked 511 for girl names
Cassandra was not found for boys
Enter a name to search: Taylor
Taylor is ranked 76 for girl names
Taylor is ranked 462 for boy names
NOTE: You can use any method you wish to match the name input on the keyboard with the names in the file. You can compare two strings ignoring upper/lower case by using #include<cstring> in C++ or#include<string.h> in C and the following comparison if ( stricmp(string1,string2) == 0)
If your compiler does not have stricmp, you may need to use _stricmp or strcasecmp.
3) DISCUSSION
a) What did you do to develop the program? (\"Followed the Directions\" is not a complete description
b) What problems did you have and how did you overcome the problems?
4) PROGRAM OUTPUT
Submit seven screen shots:
1) search result for your first name
2) search result for a name used for both boys and girls, such as Taylor, or Dylan
3) search result for a name used only for boys
4) search result for a name used only for girls
5) search result for a name that at the very top of the file
6) search result for a name that is at the very bottom of the file
7) search result for a name that is not in the file
5) PROGRAM LISTING
Copy and paste YOUR code.
-----------------------------------------------------------------------------------------------------/
help me for this project thanks and approciate
Expert Answer
Was this answer helpful?
0
0
364 answers
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main(){
int rank1=0, rank2=0;
string name;
cout << \"Please enter a name: \";
cin >> name;
string boy,girl;
string line;
string names[2];
ifstream myfile( \"input.txt\" );
if (myfile){
while (getline( myfile, line )){ // same as: while (getline( myfile, line ).good())
//cout << line << endl;
string myText(line);
istringstream iss(myText);
string token;
int i=0;
while ( getline(iss, token, \' \')){
names[i]=token;
i = i+1;
}
boy=names[0];
girl = names[1];
rank1=rank1+1;
rank2=rank2+1;
}
if(name.compare(boy)){
cout << boy <<\"ranked \" << rank1 << \" among boys.\" << endl;
}else{
cout << boy <<\"was not found for boys\" << endl;
}
if(name.compare(girl)){
cout << girl <<\"ranked \" << rank1 << \"among boys.\" << endl;
}else{
cout << girl <<\"was not found for girls.\" << endl;
}
myfile.close();
}
return 0;
}
Solution
Code to copy:
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main(){
int rank1=0, rank2=0;
string name;
cout << \"Please enter a name: \";
cin >> name;
string boy,girl;
string line;
string names[2];
ifstream myfile( \"input.txt\" );
if (myfile){
while (getline( myfile, line )){ // same as: while (getline( myfile, line ).good())
//cout << line << endl;
string myText(line);
istringstream iss(myText);
string token;
int i=0;
while ( getline(iss, token, \' \')){
names[i]=token;
i = i+1;
}
boy=names[0];
girl = names[1];
rank1=rank1+1;
rank2=rank2+1;
}
if(name.compare(boy)){
cout << boy <<\"ranked \" << rank1 << \" among boys.\" << endl;
}else{
cout << boy <<\"was not found for boys\" << endl;
}
if(name.compare(girl)){
cout << girl <<\"ranked \" << rank1 << \"among boys.\" << endl;
}else{
cout << girl <<\"was not found for girls.\" << endl;
}
myfile.close();
}
return 0;
}
3 a) Well the first obvious answer is I simply concentrated on the directions.
As language was not an option for me to choose, I had to stick to the language C++
Brief description about C++ ( C++ is the object oriented adaptation of C, and is the most prevalent programming dialect on the planet. Programs, for example, Chrome, Firefox, Photoshop, and numerous others are altogether worked with C++. It is additionally an extremely mainstream dialect for making computer games. C++ engineers are quite often popular.)
Next, I started to write a design document- which will layout the components and what you plan to accomplish with the venture. Alluding to the plan report amid the improvement procedure will keep your venture on track and centered.
Went through some books-
There are books for each dialect and for each level of ability. Which helps us to discover programming books at our neighborhood book shop or any online retailer. A book can be a priceless apparatus as you can keep it close within reach while you\'re working.
Past books, the web is an unending fortune trove of aides and instructional exercises. Scanned them for aides on my preferred dialect on locales, for example, Codecademy, Code.org, Bento, Udacity, Udemy, Khan Academy, W3Schools, and some more.
Next, I started writing the code with core functionality- It was a prototype, that shows off the usefulness that we are meaning to accomplish. A prototype is a speedy program, and ought to be iterated on until you discover a plan that works. For instance, in the event that you are making a schedule program, your prototype would be a fundamental timetable (with right dates!) and an approach to add occasions to.
When this was done, I started testing my prototype program over and over again to get rid of any bugs. Than addressed those bugs on the priority
-----------------------************************--------------------------------******************************______________
3 b) The major problems faced while programming this program were the compiler error messages.Since I was a beginner and wasn\'t familiar with the strictness of the syntax of the program, I\'d to face lot of complaints from the compiler.
Debugging :
Debugging is hard for a couple reasons; to begin with, it\'s baffling. You just composed a group of code, and it doesn\'t work despite the fact that you\'re almost certain it ought to. Damn! Second, it can be dreary; troubleshooting regularly requires a considerable measure of push to contract in on the issue, and until you have some practice, it can be difficult to proficiently limit it down.
Designing a program :
Design is a genuine test. Knowing how to consider writing computer programs is one piece, however the other piece is knowing how to assemble programs in a way that makes it simple to adjust them later. Thoughts like \"remarking your code\", \"embodiment and information covering up\" and \"legacy\" don\'t generally mean anything when you haven\'t felt the torment of not having them. The issue is that program design is about making things less demanding for your future self- - kind of like eating your vegetables. Awful outlines make the program rigid to future changes, or difficult to comprehend after the program is composed.




