In: Computer Science
Optional Assignment 1: Method Man
Assignment Description
Write some methods and call them from the main.
Tasks
Here we have to create 3 method with different parametrs and return type as mentioned in the questien and call them from main
You didnt mentioned a specific language to do this task hence i assume any programming language is fine,here i am taking c++ to implement the above task
If you want to code this in C just change cout and cin all others are correct in C too(comment down if u need that,so i can change it for you :) ) ,If you need to done this in another language please repost it with mentioning the language
Now lets see how to implement this in C++
Please read all comments for better understanding of the program
OUTPUT (Test run)
I am also attching the text version of the code too in case you need to copy paste
#include <iostream> //calling iostream library
#include <string> //calling string library
using namespace std;
void nickelbackMeme(string str ,int x){ //defining function
nickelbackMeme with parameters
if (x<=0){ //checking number is 0 or negative
cout<<"WHAT THE HELL IS ON JOEY’S HEAD?"<<endl;
}
else
{
for (int i=0;i<x;i++){ //looping statement to print the
statement x times
cout<<"LOOK AT THIS..."<<str<<endl;
}
}
}
string evenOrOdd(){ //defining the function evenOrOdd
int num;
cout<<"Ente a whole number"<<endl;
cin>>num; //statement to get a number from user
if (num%2==0){ // checkin the reminder of number when it is
get
return "Even"; // divided by 2 (even numbers are divisible by
2)
}
else
{
return "Odd";
}
}
int sevenAteNine(int x,int y, int z){ //defining the function
sevenAteNine with parametrse
int small; // a variable to store the smalles t number
if(x < y && x < z) // checking whether x is less than
y and z
{
small=x;
}
else if(y < z) // if yes checking z is greater than
z
{
small=y;
}
else
{
small=z;
}
return small; //returrning small
}
int main() //main function starts here
{
nickelbackMeme("Dude",5); // calling methods from main
cout<<evenOrOdd()<<endl; // calling methods from
main
cout<<sevenAteNine(5,7,3); // calling methods from main
return 0;
}