c++
Jun 1, 2012 at 6:57pm UTC
write a program in c++ that allows users to enter 10 names of students and 5 units with their marks, it should also calculate the average and total of the marks of each student
Jun 1, 2012 at 7:04pm UTC
write a program in c++ that allows the user to enter 10 homework assignments and then calculates the probability that someone on cplusplus.com will do them for you.
Last edited on Jun 1, 2012 at 7:04pm UTC
Jun 1, 2012 at 7:04pm UTC
Sure, if you write a program that can handle 5 student names and 2 marks each, I'll do the other half of the program.
Jun 1, 2012 at 7:06pm UTC
Sure, if you write a program that can handle 5 student names and 2 marks each, I'll do the other half of the program.
Lol
Last edited on Jun 1, 2012 at 7:07pm UTC
Jun 1, 2012 at 7:53pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#include <cstddef>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <string>
struct Student {
std::string name;
std::map<std::string, unsigned int > activity;
float average() const
{
return total() / activity.size();
}
float total() const
{
float r=0;
for (std::map<std::string, unsigned int >::const_iterator it = activity.begin();
it != activity.end();
++it
)
r += (*it).second;
return r;
}
};
int main()
{
const std::size_t units_no = 3; // EDIT THIS
const std::size_t students_no = 2; // EDIT THIS
std::list<Student> l;
for (std::size_t i=1; i <= students_no; ++i)
{
Student temp_student;
std::cout << "Student input for student number " << i << '\n' ;
std::cout << "Name: " ;
std::getline(std::cin, temp_student.name);
for (std::size_t j=1; j <= units_no; ++j)
{
std::string temp_unit_name;
unsigned int temp_unit_mark;
std::cout << "Unit name: " ;
std::getline(std::cin, temp_unit_name);
std::cout << "Unit mark: " ;
std::cin >> temp_unit_mark;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n' );
temp_student.activity[temp_unit_name] = temp_unit_mark;
}
l.push_back(temp_student);
}
for (std::list<Student>::const_iterator it = l.begin(); it != l.end(); ++it)
std::cout << (*it).name << "\n\tTotal:\t" << (*it).total()
<< "\n\tAverage:\t" << (*it).average() << '\n' << std::endl;
}
Topic archived. No new replies allowed.