answersLogoWhite

0


Best Answer

#include<iostream>

#include<iomanip>

#include<vector>

#include<string>

#include<random>

#include<time.h>

struct student_t

{

unsigned m_student_id;

std::string m_student_name;

student_t(const unsigned student_id, const std::string& student_name): m_student_id(student_id), m_student_name(student_name) {}

};

struct students_t : std::vector<student_t>

{

students_t() : std::vector<student_t> ()

{

push_back( student_t( 1, "Albert Black"));

push_back( student_t( 2, "Charlie Dawson"));

push_back( student_t( 3, "Eric Farrel"));

push_back( student_t( 4, "Gary Houston"));

push_back( student_t( 5, "Iain Jackson"));

push_back( student_t( 6, "Kevin Lawson"));

push_back( student_t( 7, "Michael Nicholson"));

push_back( student_t( 8, "Oscar Peterson"));

push_back( student_t( 9, "Robert Stevenson"));

push_back( student_t( 10, "Tony Urquart"));

}

};

struct subject_t

{

unsigned m_subject_id;

std::string m_subject_name;

subject_t(const unsigned subject_id, const std::string& subject_name): m_subject_id(subject_id), m_subject_name(subject_name) {}

};

struct subjects_t : std::vector<subject_t>

{

subjects_t() : std::vector<subject_t> ()

{

push_back( subject_t( 1, "English"));

push_back( subject_t( 2, "Mathematics"));

push_back( subject_t( 3, "Physics"));

push_back( subject_t( 4, "Biology"));

push_back( subject_t( 5, "Chemistry"));

push_back( subject_t( 6, "History"));

push_back( subject_t( 7, "Geography"));

}

unsigned max_length()

{

// Returns length of longest name.

unsigned max=0;

for (std::vector<subject_t>::const_iterator isubject=begin(); isubject!=end(); ++isubject)

{

const subject_t& subject = *isubject;

if (max < subject.m_subject_name.size())

max = subject.m_subject_name.size();

}

return max;

}

};

struct mark_t

{

student_t& m_student;

subject_t& m_subject;

unsigned m_mark;

mark_t(student_t& student, subject_t& subject, const unsigned mark): m_student(student), m_subject(subject), m_mark(mark) {}

mark_t& operator= (const mark_t& rvalue)

{

this->m_student = rvalue.m_student;

this->m_subject = rvalue.m_subject;

this->m_mark = rvalue.m_mark;

return *this;

}

};

struct marks_t : std::vector<mark_t>

{

students_t& m_students;

subjects_t& m_subjects;

marks_t (students_t& students, subjects_t& subjects) : std::vector<mark_t>(), m_students(students), m_subjects(subjects)

{

// pseudo-random number generator

std::default_random_engine generator;

generator.seed ((unsigned) time (NULL));

std::uniform_int_distribution<unsigned> distribution (0, 100);

for (std::vector<student_t>::const_iterator istudent=students.begin(); istudent!=students.end(); ++istudent)

{

student_t& student = const_cast<student_t&> (*istudent);

for (std::vector<subject_t>::const_iterator isubject=subjects.begin(); isubject!=subjects.end(); ++isubject)

{

subject_t& subject = const_cast<subject_t&> (*isubject);

push_back( mark_t(student, subject, distribution(generator)));

}

}

}

std::ostream& print (std::ostream& os)

{

unsigned last_student_id = 0;

for (std::vector<mark_t>::const_iterator imark=begin(); imark!=end(); ++imark)

{

const student_t& student = imark->m_student;

if (last_student_id != student.m_student_id)

{

if (last_student_id)

os << '\n';

last_student_id = student.m_student_id;

os << '#' << student.m_student_id << '\t' << student.m_student_name << ":\n" << std::endl;

}

const subject_t& subject = imark->m_subject;

os << '\t' << std::setw (m_subjects.max_length()) << subject.m_subject_name << '\t' << std::setw(3) << imark->m_mark << std::endl;

}

os << std::endl;

return os;

}

};

int main()

{

students_t students;

subjects_t subjects;

marks_t marks (students, subjects);

marks.print (std::cout);

}

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How to print the marks of 10 students in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do make 10student name and his remarks in q-basic?

' '*** PROGRAM: Collecting student data: names/marks. ' '*** Create 2 array variables to store each students name/marks... DIM students$(10), marks$(10) '*** SCREEN ONE/Collect the data... CLS '...(CL)ear the Output (S)creen '*** print heading... PRINT "PROGRAM: Collecting each student names/marks..." PRINT '*** A FOR/NEXT loop is used to collect each individual students data... FOR eachStudentNo% = 1 TO 10 '*** Get each students names/marks 'by typing these values in from the keyboard.... PRINT eachStudentNo%; "&gt;" INPUT " Enter student name"; students$(eachStudentNo%) INPUT "Enter student marks"; marks$(eachStudentNo%) NEXT '*** SCREEN TWO: Output the collected data... CLS '...(CL)ear the Output (S)creen '*** Print headings... PRINT "Student No.", "Student Name", "Student Marks" PRINT '*** FOR/NEXT loop is used to print out the 2 array student 'name/marks' values... FOR eachStudentNo% = 1 TO 10 '*** print out each students 'number/name/mark' values... PRINT eachStudentNo%, PRINT students$(eachStudentNo%), PRINT marks$(eachStudentNo%) NEXT END '...END of program/halt program code execution


How many marks obtained in 10 and plus 2?

564 marks


What is cut off marks for iit madras?

They do not give marks. The top 10 Thousand students are selected. There is no cut off.


Write a program in BASIC to find the sum of the series s equals 2 plus 4 plus . plus 100?

10 print "That is not a question." 20 print "That is a command." 30 end


What are the median marks if the marks obtained by 10 students are 36 44 60 38 55 31 35 40 45 52?

The median is 42.


Explain why a selection of 10 students from your class can have marks that aren't normally distributed when the marks of the whole class are normally distributed?

The sample size is likely to be too small.


What is the code in c plus plus to declare and define a structure keeping records of 10 students?

struct student { std::string id; std::string first_name; std::string last_name; // ... }; student students[10];


How tall am I if I'm 59 inches plus 6 more marks on the ruler?

It depends on the number of marks per inch. You can get measuring equipment with 8, 10, 16 or 32 marks per inch. Assuming there are 10 per inch, your height is 4 ft 11.6 inches.


Where can you find a python script for a nearly infinite loop that looks like water?

You can find such scripts on various websites. Considering that you want a script that print some ASCII image that looks like flowing water, then I will quickly write one for you. Script:import timewhile True:___print "1 " * 10; print " 1 " * 10; print " 1 " * 10; time.sleep(0.75); print " 1 " * 10; print " 1 " * 10; print " 1 " * 10; time.sleep(0.75); print "1 " * 10; print " 1 " * 10; print " 1 " * 10; time.sleep(0.75); print " 1 " * 10; print " 1 " * 10; print " 1 " * 10; time.sleep(0.75);Note (Replace underscore (___) with indentation.


How many boxes of book paper can be printed by M1 in 10 hours or 120x plus 160 hours or 30x squared plus 40x hours M1 can print a box of paper in 3 hours while M2 can be done in 3x plus 20 hours?

*Edit* M2 can print a box of paper in 3x plus 20 hours.


What do you mean by aggregate marks in 10 plus 2 plus 3 should be 50 percent Is it average of your class 10th class 12th and graduation marks should be 50 percent or 50 percent in all of them individu?

It means the weighted average of your mark should be 50%.


Best softwear for graphic design?

Here are the top 10: Print Workshop 2009 Design &amp; Print Business Edition - Avanquest Publishing Studio - Greenstreet Print Shop Deluxe Print Master - Broderbund Microsoft Publisher Print Shop Pro Publisher Print Artist Page Plus X3 - Serif Adobe Creative Suite &lt;--Best