why there are 2 getlines in the string name? (what will happen if only one?) - since there is an if statement, why is there no else statement?
In the C++ code below, what is the explanation:
- why there are 2 getlines in the string name? (what will happen if only one?)
- since there is an if statement, why is there no else statement?
#include <iostream>
using namespace std;
int main()
{
int n;
// uer input
cout << "Enter number of students: ";
cin >> n;
string gender[n], name[n];
// input for name and gender
for (int i = 0; i < n; i++)
{
cout << "Enter gender of Student: ";
cin >> gender[i];
cout << "Enter name of Student: ";
getline(cin, name[i]);
getline(cin, name[i]);
}
cout << "---------------------" << endl;
cout << "List of Female Students" << endl;
// printing female students
for (int i = 0; i < n; i++)
{
if (gender[i] == "Female")
cout << name[i] << endl;
}
cout << "List of Male Students" << endl;
cout << "---------------------" << endl;
// printing male students
for (int i = 0; i < n; i++)
{
if (gender[i] == "Male")
cout << name[i] << endl;
}
return 0;
}
![#include <ioștream>
using namespace ștd;
int main()
{
int n;
cout << "Enter number of students: ";
cin >> n;
string gender[n], name[n];
for (int i = 0; i< n; i++)
{
cout << "Enter gender of Student: ";
cin >> gender[i);
cout << "Enter name of Student: ";
getline(cin, name[i]);
getline(cin, name[i]);
}
%3D
cout <<
" << endl;
cout << "List of Female Students" << endl;
for (int i = 0; i < n; i++)
{
if (gender[i] == "Female")
cout << name[i] << endl;
}
< endl;
cout << "List of Male Students" << endl;
cout <<
for (int i = 0; i < n; i++)
{
if (gender[i] == "Male")
cout << name[i] << endl;
}
return 0;
}](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F74f7ae45-f0e3-44d2-9ad1-30211498e68b%2F0de01853-3b7a-4dec-af97-40aeb3f30d9a%2Fquuz6m_processed.png&w=3840&q=75)
![#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter number of students: ";
cin >> n;
string gender[n], name[n];
for (int i = 0; i< n; i++)
{
cout << "Enter gender of Student: ";
cin
cout << "Enter nameStudent: ";
getline(cin, name[i]);
getline(cin, name[i]);
<< endl;
cout << "LIst OI Female Students" << endl;
for (int i = 0; i < n; ¡++)
%3D
{
if (gender[i] == "Female")
cout << name[i] << endl;
}
cout <<
cout << "List of Male Students" << endl;
%3D
<< endl;
for (int i = 0; i < n; i++)
{
if (gender[i]
cout << name[i] << endl;
= "Male")
}
return 0;
}](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F74f7ae45-f0e3-44d2-9ad1-30211498e68b%2F0de01853-3b7a-4dec-af97-40aeb3f30d9a%2F1k6mrh9_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)