Question

In: Computer Science

How would I write a C++ code that gives me the following out put:    Enter...

How would I write a C++ code that gives me the following out put:

   Enter count of male students: 14

Enter count of female students: 17

Students registered

Total:    31

Male:     14   45.16%

Female:   17   54.84%

   Enter count of male students: 7

Enter count of female students: 2

Students registered

Total:     9

Male:      7   77.78%

Female:    2   22.22%            */

Solutions

Expert Solution

Code:

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
//Declaring Variables
int total, male, female ;
float male_per, female_per;

//Taking inputs like number of male n female
cout << endl;
cout << "Enter count of male students: ";
cin >> male;
cout << "Enter count of female students: ";
cin >> female;
cout << endl;

//calculate total
total = male + female;

//calculate percentage of male n female
male_per = (male / static_cast<float>(total)) * 100;
female_per = (female / static_cast<float>(total)) * 100;

// Printing percentage
cout << setprecision(2) << fixed;
cout << "Students Registered:" ;
cout << "\n total:" << total ;
cout << "\n Male:" << male <<"\t" << male_per <<"%";
cout << "\n Female:" << female <<"\t" << female_per <<"%"<< ".\n" <<endl ;
  

// program end
return 0;
}

Snapshot of Code:

Output:


Related Solutions

I am needing assistance figuring out how to write the code for this project in C#...
I am needing assistance figuring out how to write the code for this project in C# (C sharp)... Create a new Project and name it - InClassParticipation3 Get up to 5 inputs from the user. The user must enter at least 1 number. After the first input, ask them if they would like to input another number if they say 'yes' get the provided input and multiply it to the other inputs provided by the user. If the user says...
Write out code for a nested if statement that allows a user to enter in a...
Write out code for a nested if statement that allows a user to enter in a product name, store the product into a variable called product name and checks to see if that product exists in your nested if statement. You must include 5 product names to search for. If it is then assign the price of the item to a variable called amount and then print the product name and the cost of the product to the console. If...
Write MIPS assembly code for the following C code. for (i = 10; i < 30;...
Write MIPS assembly code for the following C code. for (i = 10; i < 30; i ++) { if ((ar[i] > b) || (ar[i] <= c)) ar[i] = 0; else ar[i] = a; }
C++ Write the C++ code for a void function that prompts the user to enter a...
C++ Write the C++ code for a void function that prompts the user to enter a name, and then stores the user's response in the string variable whose address is passed to the function. Name the function getName.
I cannot get this code to run on my python compiler. It gives me an expected...
I cannot get this code to run on my python compiler. It gives me an expected an indent block message. I do not know what is going on. #ask why this is now happenning. (Create employee description) class employee: def__init__(self, name, employee_id, department, title): self.name = name self.employee_id = employee_id self.department = department self.title = title def __str__(self): return '{} , id={}, is in {} and is a {}.'.format(self.name, self.employee_id, self.department, self.title)    def main(): # Create employee list emp1...
Im asked to edit the C++ code given to me so that the user can enter...
Im asked to edit the C++ code given to me so that the user can enter as many courses as they would like. I've already built the array to house the courses, but Im a tiny bit stuck on writing the user input to the array every time a new line Is made. Code: //CSC 211 Spring 2019 //Program Description: // // Originally From: // CSC 211 Spring 2018 // Dr. Sturm // This program... // #include<iostream> #include<string> #include<fstream> using...
Write a C++ code to perform the following steps: 1. Ask the user to enter two...
Write a C++ code to perform the following steps: 1. Ask the user to enter two whole numbers number1 and number2 ( Number 1 should be less than Number 2) 2. calculate and print the sum of all even numbers between Number1 and Number2 3. Find and print all even numbers between Number1 and Number2 4. Find and print all odd numbers between Number1 and Number2 5. Calculate and print the numbers and their squares between 2 and 20 (inclusive)...
Write a C++ code to perform the following steps: 1. Ask the user to enter two...
Write a C++ code to perform the following steps: 1. Ask the user to enter two whole numbers number1 and number2 (Number1 should be less than number2) 2. Calculate and print the sum of all even numbers between Number1 and Number2 3. Find and print all even numbers between Number1 and Number2 4. Find and print all odd numbers between Number1 and Number2 5. Calculate and print the numbers and their squares between 1 and 20 (inclusive) 6. Calculate and...
How do I write a C# and a C++ code for creating a character array containing...
How do I write a C# and a C++ code for creating a character array containing the characters 'p', 'i', 'n','e','P','I','N','E' only and then using these lower and capital case letter character generate all possible combinations like PInE or PinE or PIne or PINE or piNE etc. and only in this order so if this order is created eg. NeIP or EnPi or NeIP or IPnE and on. You can generate all the combinations randomly by creating the word pine...
How would I write a code from this following word problem? 3. Use the pow() and...
How would I write a code from this following word problem? 3. Use the pow() and sqrt() functions to compute the roots of a quadratic equation. Enter the three coefficients with a single input statement. Warning: if you give sqrt() a negative value, the function cannot produce a valid answer.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT