int pertambahan(int pilihan, int now){ int result; result =pilihan + now; return result; } int perkalian(int pilihan, int now){ int result; result = pilihan*now; return result; } int main(){ int NoR,initial; int now; int temp1, temp2; scanf("%d %d", &NoR, &initial); getchar(); now=initial; for(int o=0;o=-1000 && pilihan1<=1000) { temp1 = pertambahan(pilihan1,now); } else{ temp1=-10000; } } else if(a=='x') { if(pilihan1>=-2 && pilihan1<=2){ temp1 = perkalian(pilihan1,now); } else { temp1=-10000; } } if(b=='+') { if(pilihan2>=-1000 && pilihan2<=1000) { temp2 = pertambahan(pilihan2,now); } else { temp2=-10000; } } else if(b=='x') { if(pilihan2>=-2 && pilihan2<=2) { temp2 = perkalian(pilihan2,now); } else { temp2=-10000; } } if(temp1>temp2) { now=temp1; } else { now=temp2; } } printf("%d\n", now); return 0; } Can u give general explaination for this code, so i can learn it. pertambahan = Addition. perkalian= multiplication. plihan= choice.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
int pertambahan(int pilihan, int now){
int result;
result =pilihan + now;
return result;
}
int perkalian(int pilihan, int now){
int result;
result = pilihan*now;
return result;
}
int main(){
int NoR,initial;
int now;
int temp1, temp2;
scanf("%d %d", &NoR, &initial);
getchar();
now=initial;
for(int o=0;o<NoR;o++){
char a,b;
int pilihan1,pilihan2;
scanf("%c %d %c %d",&a, &pilihan1,&b, &pilihan2);
getchar();
if(a=='+')
{
if(pilihan1>=-1000 && pilihan1<=1000)
{
temp1 = pertambahan(pilihan1,now);
}
else{
temp1=-10000;
}
}
else if(a=='x')
{
if(pilihan1>=-2 && pilihan1<=2){
temp1 = perkalian(pilihan1,now);
}
else
{
temp1=-10000;
}
}
if(b=='+')
{
if(pilihan2>=-1000 && pilihan2<=1000)
{
temp2 = pertambahan(pilihan2,now);
}
else
{
temp2=-10000;
}
}
else if(b=='x')
{
if(pilihan2>=-2 && pilihan2<=2)
{
temp2 = perkalian(pilihan2,now);
}
else
{
temp2=-10000;
}
}
if(temp1>temp2)
{
now=temp1;
}
else
{
now=temp2;
}
}
printf("%d\n", now);
return 0;
}
Can u give general explaination for this code, so i can learn it.
pertambahan = Addition.
perkalian= multiplication.
plihan= choice.

Step by step
Solved in 3 steps with 1 images









