03/07/2020 An Introduction To Programming Through C++ - Course
https://onlinecourses.nptel.ac.in/noc20_cs53/progassignment?name=221 1/4
Due on 2020-04-01, 23:59 IST
Week 9 Programming Assignment 2
Write a class Cricketer with following member variables:
char name[100];
int matches;
int innings;
int notOut;
int runs;
double average;
Write member function avg() to calculate average of the crickete r with following rules
1) If the data provided is a mismatch, returned value would be - 1
a) number of matches is less than number of innings b) number of notOut is more than number of innings
2) if innings is equal to notOut then avg is the number of runs 3) avg is runs scored divided by the number of innings when the cricketer got out (innings - notOut)
Write another opertor (>) which takes one more Cricketer object as parameter and compares the avg of the two Cricketers. It retu rns true(1) when the first cricketer's average is more than the Cricketer whose object is passed as parameter, else false(0).
X
NPTEL (https://swayam.gov.in/explorer?ncCode=NPTEL) » An Introduction To Programming Through C++
(course)
(https://swayam.gov.in)
(https://swayam.gov.in/nc_details/NPTEL)Announcements (announcements)
About the Course (https://swayam.gov.in/nd1_noc20_cs53/preview) Ask a Question (forum) Progress (student/home) Mentor (student/mentor)
Course outline
How does an NPTEL online course work?
Week 0 Week 1 Week 2 Week 3 Week 4 Week 5 Week 6 Week 7 Week 8 Week 9
Lecture 19 : Structures :
03/07/2020 An Introduction To Programming Through C++ - Course
https://onlinecourses.nptel.ac.in/noc20_cs53/progassignment?name=221 2/4
Sample Test Cases
Input Output
Test Case 1 Sharayu 99 177 27 15421
Shilpa 23 83 43 4320 -1 -1 0
Test Case 2 Sharayu 99 177 27 15421
Shilpa 23 13 41 4320 -1 -1 0
Test Case 3 Puru 70 13 13 4320
Amit 50 17 17 5421 4320 5421 0
Test Case 4 Puru 70 33 13 4320
Amit 50 37 27 5421 216 542.1 0
Test Case 5 Amit 50 37 27 5421
Puru 70 33 13 4320 542.1 216 1
Test Case 6 Pravin 100 83 13 4320
Amar 150 137 27 5421 61.7143 49.2818 1
Test Case 7 Manali 150 137 27 5421
Shefali 100 83 13 4320 49.2818 61.7143 0
Test Case 8 Ranjit 75 37 47 5421
Praneel 123 125 13 4320 -1 -1 0
Test Case 9 Amin 50 39 39 5421
Sameer 47 43 13 4320 5421 144 1
Test Case 10 Sharayu 199 177 27 15421
Shilpa 123 83 43 4320 102.807 108 0
The due date for submitting this assignment has passed.
As per our records you have not submitted this assignment.
Sample solutions (Provided by instructor) Part 1 :
Definition and instantiation (unit?
unit=94&lesson=120) Lecture 19 :
Structures : Part 2 : Operations on structures (unit?
unit=94&lesson=121) Lecture 19 :
Structures : Part 3 : An example program (unit?
unit=94&lesson=122) Lecture 19 :
Structures : Part 4 : Pointers and lecture conclusion (unit?
unit=94&lesson=123) Lecture 20 :
Structures Part 2 : Part 1 : Introduction to Member functions (unit?
unit=94&lesson=124) Lecture 20 :
Structures Part 2 : Part 2 : Vectors from Physics (unit?
unit=94&lesson=125) Lecture 20 :
Structures Part 2 : Part 3 : Taxi dispatch (unit?
unit=94&lesson=126) Lecture 21 :
Classes : Part 1 : Introduction (unit?
unit=94&lesson=127) Lecture 21 :
Classes : Part 2 :
Constructors (unit?
unit=94&lesson=128)
#include <iostream>
#define repeat(x) for(int _iterator_i = 0, _iterator_limit = x; _iterat
#define main_program int main()
#include <cmath>
using namespace std;
class Cricketer{
private:
char name[100];
int matches;
int innings;
int notOut;
int runs;
double average;
public:
Cricketer(){};
Cricketer(char *str, int mat, int inns, int nt, int r){
int i=0;
while(str[i] != 0){
this->name[i] = str[i];
i++;
} i 12
34 56 78 109 1112 1314 1516 1718 1920 2122 23
03/07/2020 An Introduction To Programming Through C++ - Course
https://onlinecourses.nptel.ac.in/noc20_cs53/progassignment?name=221 3/4
Week 10 Week 11 Week 12
Text Transcripts Lecture 21 : Classes : Part 3 : Operator overloading (unit?
unit=94&lesson=129) Lecture 21 :
Classes : Part 4 : Access control (unit?
unit=94&lesson=130) Lecture 21 :
Classes : Part 5 : Classes for graphics and input output (unit?
unit=94&lesson=131) Lecture 21 :
Classes : Part 6 : General remarks (unit?
unit=94&lesson=132) Download
Videos (unit?
unit=94&lesson=185) Weekly
Feedback (unit?
unit=94&lesson=197) Quiz : Week 9 Assignment (assessment?
name=219) Week 9 Programming Assignment 1
(/noc20_cs53/progassignment?
name=220) Week 9 Programming Assignment 2
(/noc20_cs53/progassignment?
name=221)
this->matches = mat;
this->innings = inns;
this->notOut = nt;
this->runs = r;
}
void read(){
cin >> name >> matches >> innings >> notOut >>
}
double avg(){
if(matches < innings) average = -1;
else if(innings-notOut < 0) average = -1;
else if(0 == (innings-notOut) ) average = runs;
else
average = 1.0 * runs/(innings-notOut);
return average;
}
bool operator>(Cricketer c1){
c1.avg();
this->avg();
return average > c1.average ; }
};int main(){
Cricketer c1;
c1.read();
cout << c1.avg() << " ";
Cricketer c2;
c2.read();
cout << c2.avg() << " " ; cout << (c1 > c2) ;
} 2425 2627 2829 3031 3233 3435 3637 3839 4041 4243 4445 4647 4849 5051 5253 5455 5657 5859 6061 6263 64
03/07/2020 An Introduction To Programming Through C++ - Course
https://onlinecourses.nptel.ac.in/noc20_cs53/progassignment?name=221 4/4