An Introduction To Programming Through C++
IIT Bombay.
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 cricketer 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 returns true(1) when the first cricketer's average is more than the Cricketer whose object is passed as parameter, else false(0).
Public Test Cases:
Test Case 1:
Input:
Pravin 100 83 13 4320
Amar 150 137 27 5421
Output:
61.7143 49.2818 1
61.7143 49.2818 1
Passed
Test Case 2:
Input:
Manali 150 137 27 5421
Shefali 100 83 13 4320
Output:
49.2818 61.7143 0
49.2818 61.7143 0
Passed
Test Case 3:
Input:
Ranjit 75 37 47 5421
Praneel 123 125 13 4320
Output:
-1 -1 0
-1 -1 0
Passed
Test Case 4:
Input:
Amin 50 39 39 5421
Sameer 47 43 13 4320
Output:
5421 144 1
5421 144 1
Passed
Test Case 5:
Input:
Sharayu 199 177 27 15421
Shilpa 123 83 43 4320
Output:
102.807 108 0
102.807 108 0
Passed
WRITE/COPY THESE CODE DIRECTLY IN NPTEL TERMINAL AND COMPILE AND RUN THEN SUBMIT.
PROGRAM:
#include<iostream>
using namespace std;
class Cricketer
{
public:
char name[100];
int matches;
int innings;
int notOut;
int runs;
double average;
double avg()
{
if(matches<innings||notOut>innings)
{
return -1;
}
if(innings==notOut)
{
average=runs;
return average;
}
double n=innings-notOut;
if(n<=innings)
{
average=runs/n;
return average;
}
}
int operator >(Cricketer c2)
{
int a,b;
a=average;
b=c2.average;
if(a==b)
return 0;
if(average>c2.average)
return 1;
else
return 0;
}
void read()
{
cin>>name>>matches>>innings>>notOut>>runs;
}
};
CLICK ON BELOW LINK.
<<CLICK HERE FOR WEEK =10 :PROGRAMMING ASSIGNMENTS 1>>
FOLLOW OUR WEBSITE FROM THE BUTTON PROVIDED TO THE BOTTOM OF PAGE TO GET SOON ANSWERS OF PROGRAMS.
Disclaimer: Here you can find all nptel assignment solutions related to CS stream.These may help you for your assignment.The answers are only for verification.You cannot copy these directly from the post(code of conduct of NPTEL).These is not 100% correct solutions.
Programming Assignment - 2:-
ReplyDeletestruct Observation
{
int date;
int patients;
void read()
{
cin>>date>>patients;
}
};
int uncured(Observation* ob, int n, int D, int date)
{
int ans=0;
for(int i=0;i=(ob[i].date) && date<((ob[i].date)+D)) ans+=(ob[i].patients);
}
return ans;
}
sir please upload Programming assignmen1 as soon as possible
ReplyDeletesir please upload Programming assignmen1 as soon as possible
ReplyDeletesir please upload Programming assignmen1 as soon as possible
ReplyDeletesir please upload assignment 1
ReplyDeleteAj Lagta Hain aur Nahin hoga upload
ReplyDelete