Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

ASSN-03

OOP LAB G1
ANKIT KUMAR
2K20/IT/24

SOL.1

CODE:

class
Student{pri
vate :

int age,standard;
string first_name,last_name;

public :

void set_age(int
a){age = a;
}
int get_age(){
return age;
}

void set_first_name(string
s){first_name=s;
}
string
get_first_name(){ret
urn first_name;
}

void set_last_name(string
t){last_name=t;
}
string
get_last_name(){ret
urn last_name;
}

void set_standard(int
b){standard = b;
}
int
get_standard(){
return standard;
}
string to_string()
{
stringstream ss;
ss << age << "," << first_name << "," << last_name << "," <<
standard;
return ss.str();
}

};
OUTPUT:
SOL.2
CODE:
class
Student{pu
blic :
int scores[5];
void input(){
for (int i=0 ; i<5 ;
i++){cin >> scores[i];
}
}
int
calculateTotalScore(){i
nt sum = 0;
for (int j=0 ; j<5 ;
j++){sum +=
scores[j];
}
return sum;
}
};
OUTPUT:
SOL.3
CODE:
int countingValleys(int steps, string path) {

cin>>steps>>path;
int height = 0;
int count = 0;
for(int i=0;i<steps;i++){
if (path[i]=='U') height++;
else {
if (height==0) count++;
height--;
}
}
if (height<0) count--;
return count;
}
OUTPUT:

SOL.4
CODE:
int jumpingOnClouds(vector<int> c)
{int i=0;
int steps=0;
int size=c.size();
while(i<size)
{ if(c[0]==
1)
{
if(c[2]!=1) i+=2;
else i+=1;
steps+=1;
}
else
{
if(i==size-1)
{
break;
}
else if(i==size-2 || i==size-3)
{
steps+=1;
break;
}
else
{
if(c[i+2]!=1)
{ i+=
2;
steps+=1;
}
else
{
i+=1;
steps+=1;
}
}
}
}
return steps;
}
OUTPUT:

You might also like