Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ programming pleas i need all codes in this homework Homework 1) Call foo() t

ID: 3583975 • Letter: C

Question

C++ programming

pleas i need all codes in this homework

Homework

1) Call foo() three times to print “ok” three times.

2) Implement the calculator in lect15 using functions as follows.

#include <iostream>

using namespace std;

void show_menu(){

      printf(“1. add 2. sub 3. mul 4. div 5. quit ”);

      printf(“select operation ”);

}

void add(){

   int x, y, z; // local variable for add

   printf(“enter two numbers ”);

   scanf(“%d %d”, &x, &y);

   z=x+y;

   printf(“the sum is %d ”, z);

}

void sub(){

   int x, y, z; // local variable for sub

   printf(“enter two numbers ”);

   scanf(“%d %d”, &x, &y);

   z=x-y;

   printf(“the sub is %d ”, z);

}

...Define mul, div......

void main(){

   int s; // local variable for main

   for(;;){

      show_menu();

      scanf(“%d”, &s);

      if (s==1){

          add();

      }else if (s==2){

          sub();

      }else if (s==3){

          mul();

      }else if (s==4){

          div();

      }else{

          printf(“Bye ”);

          break;

      }

   }

}

1. add 2. sub 3. mul 4. div 5. quit

select operation

1

enter two numbers

12 22

the sum is 34

1. add 2. sub 3. mul 4. div 5. quit

select operation

3

enter two numbers

10 20

the mul is 200

...............

1. add 2. sub 3. mul 4. div 5. quit

select operation

5

Bye

3) Add “power”, “factor-of”, “factor” to the menu items. Use functions to implement these new menu items.

power menu:

enter =two numbers

2 5

2 to the power of 5 is 32

factor-of menu:

enter two numbers

3 24

3 is a factor of 24.

factor menu:

enter a number

24

The factors of 24 are

1 2 3 4 6 8 12 24

Explanation / Answer

#include <iostream>
using namespace std;

void foo(){
   for(int i=0; i<3; i++){
       cout<<"ok"<<endl;  
   }
}

void show_menu(){
cout<<"1. add 2. sub 3. mul 4. div 5. quit"<<endl;
cout<<"select operation"<<endl;
}

void add(){
int x, y, z; // local variable for add
cout<<"enter two numbers"<<endl;
cin>>x>>y;
z=x+y;
cout<<"the sum is "<<z<<endl;
}

void sub(){
int x, y, z; // local variable for sub
cout<<"enter two numbers"<<endl;
cin>>x>>y;
z=x-y;
cout<<"the sub is "<<z<<endl;
}

void mul(){
int x, y, z; // local variable for sub
cout<<"enter two numbers"<<endl;
cin>>x>>y;
z=x*y;
cout<<"the mul is "<<z<<endl;
}

void div(){
int x, y, z; // local variable for sub
cout<<"enter two numbers"<<endl;
cin>>x>>y;
z=x/y;
cout<<"the div is "<<z<<endl;
}

int main(){
int s; // local variable for main
for(;;){
show_menu();
cin>>s;
if (s==1){
add();
}else if (s==2){
sub();
}else if (s==3){
mul();
}else if (s==4){
div();
}else{
cout<<"bye";
break;
}
}

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote