Exercise 1
#include <iostream>
using std::cout;
using std::cin;
using std::string;
void name(string);
int main()
{
cout << “Hello, my name is “;
string parameter = “Rock”;
name(parameter);
cout << “.”;
cout << “It’s about drive, it’s about power, we stay hungry, we devour Put in the work, put in the hoursand take what’s ours Black and Samoan in my veins, my culture bangin’ with Strange I change the game so what’s my motherfuckin’ name ? “;
name(parameter);
cout << “\n” << “What they gonna get though? Desecration, defamation, if you wanna bring it to the masses Face to face now we escalatin’ when I have to put boots to asses Mean on ya like a dream when I’m rumblin’ You’re gonna scream,”;
name(parameter);
return 0;
}
void name(string name)
{
cout << name;
}
Exercise 2
#include <iostream>
using std::cout;
using std::cin;
void launch();
int num1;
int main()
{
launch();
return 0;
}
void launch()
{
cout << “enter a number: “;
cin >> num1;
while (num1– >= 1)
cout << “Countdown:” << num1 << “\n”;
if (num1 <= 1)
cout << “Liftoff!”;
}
Exercise 3
#include <iosteam>
using std::cout;
using std::cin;
void stars();
int main()
{
stars();
return 0;
}
void stars()
{
int y, w;
cout << “Please enter a width axis: “;
cin >> y;
for (w = 1; w <= y; w++)
{
cout << “X”;
}
cout << “\n”;
}
Exercise 4
#include <iosteam>
using std::cout;
using std::cin;
void stars();
int main()
{
stars();
return 0;
}
void stars()
{
int x, y, h, w;
cout << “Please enter a x axis: “;
cin >> x;
cout << “Please enter a y axis: “;
cin >> y;
for (h = 1; h <= x; h++)
{
for (w = 1; w <= y; w++)
{
cout << “X”;
}
cout << “\n”;
}
}
Exercise 5
Exercise 6
#include <iostream>
using std::cout;
using std::cin;
int num1, num2;
int add(int a, int b);
int main()
{
int num1;
int num2;
int answer;
cout << “Enter a number: “;
cin >> num1;
cout << “\nThis is your first number: ” << num1;
cout << “\nEnter your second number: “;
cin >> num2;
cout << “\nThis is your second number: ” << num2 << “\n”;
answer = add(num1, num2);
cout << num1 << ” + ” << num2 << ” = ” << answer;
return 0;
}
int add(int a, int b)
{
return (a + b);
}
Exercise 7
#include <iostream>
using std::cout;
using std::cin;
void question1();
void question2();
void question3();
int main()
{
question1();
question2();
question3();
Return 0;
}
void question1()
{
char answer1;
cout << “Do you enjoy food? Enter either y/n: “;
cin >> answer1;
if (answer1 == ‘y’)
{
cout << “True\n”;
}
else if (answer1 == ‘n’)
{
cout << “False\n”;
}
}
void question2()
{
char answer2;
cout << “Have you ever seen a UFO? Enter either y/n: “;
cin >> answer2;
if (answer2 == ‘y’)
{
cout << “False\n”;
}
else if (answer2 == ‘n’)
{
cout << “True\n”;
}
}
void question3()
{
char answer3;
cout << “Is the moon made of cheese? Enter either y/n: “;
cin >> answer3;
if (answer3 == ‘y’)
{
cout << “True\n”;
}
else if (answer3 == ‘n’)
{
cout << “False!\n”;
}
}
Exercise 8
#include <iostream>
using std::cout;
using std::cin;
int area();
int main()
{
area();
return 0;
}
int area()
{
int radius;
float pi = 3.14, answer;
cout << “Enter a radius: “;
cin >> radius;
answer = pi * (radius * radius);
cout << “\nThis is the area of your circle: ” << answer;
return 0;
}
Exercise 9
#include <iostream>
using std::cout;
using std::cin;
bool multiply(int*, int*);
int main()
{
int num1, num2;
cout << “Enter a number: “;
cin >> num1;
cout << “\nEnter a second number: “;
cin >> num2;
if (multiply(&num1, &num2))
{
cout << num1 << ” is a multiplier of ” << num2;
}
else
{
cout << num1 << ” is not a multipier of ” << num2;
}
return 0;
}
bool multiply(int *a, int *b)
{
if (*a % *b == 0)
{
return true;
}
else
{
return false;
}
}
Exercise 10
#include <iostream>
using std::cout;
using std::cin;
void increase(int*);
int main()
{
int x;
cout << “Enter a number: “;
cin >> x;
increase(&x);
cout << x;
return 0;
}
void increase(int *x)
{
*x += 15;
}
Exercise 11
#include <iostream>
using std::cout;
using std::cin;
void halfdouble(float*, float*, float*);
int main()
{
float a, b, c;
cout << “Enter a number: “;
cin >> a;
halfdouble(&a, &b, &c);
cout << a << ” ” << b << ” ” << c ;
return 0;
}
void halfdouble(float* q, float* w, float* e)
{
*w = *q / 2;
*e = *q * 2;
}