This is code for c++. Any help would be great.
#include <iostream>
using namespace std;
/* 1. Create a method that prints your name
*/
/* 2. Create an overloaded method that takes an integer and prints it out
multiplied
* by itself
* Print out the argument inside the method and then call the method from main
* and print it out
* What was the typed of passing used inhere ?
*/
/* 3. Create an overloaded method that takes a double and returns it as an integer
* Call the method from main , reassign the passed in argument to the return value
* What was the typed of passing used inhere ?
*/
/* 4. Create an overloaded method that takes an address of an integer
* Pre decrement the argument
* Print it out inside the method and in the main
* What was the type of passing used inhere ?
*/
/* 5. Create a method that takes a double array and the size of the array.
* The method casts elements of the array to an integer
* Print out the result inside the method and outside
* What was the type of passing used for the array?
*/
/* 6. Create an overloaded method that takes a double array and returns it an
integer array
* Remember to use pointer and define your return array to be static
* Print out the returned array in the main method
*/
/* 7. Create a method that takes three doubles whose default values are 2.2 3.3 4.4
* The method returns the additions of the arguments and print the result
* Call the method again and pass in two arguments and print the result
* Call the method again and pass in three arguments and print the result
*/
/* 8. Create an overloaded method of the previous method that takes two integers
* with default values and assign the answer to a global variable called addition
* The method returns the additions of the arguments
* Print out the result inside the main method
*/
int main() {
// Call your methods in the main method and show your work
return 0;
}
Here is the code for the above assignment.
Feel free to comment on any doubts and give thumbs up.
Additionally, I have added comments for your better understanding.
Code :
#include<iostream>
using namespace std;
int addition;
/* 1. Create a method that prints your name
*/
void printName(const char* name){
cout << "Name : "<< name << "\n";
}
/* 2. Create an overloaded method that takes an integer and prints it out
multiplied
* by itself
* Print out the argument inside the method and then call the method from main
* and print it out
* What was the typed of passing used inhere ?
* Ans : the type of passing used in here is pass by value.
*/
void overloadedMethod(int value){
cout << "Priting out the argument : " << value << "\n";
cout << "Printing int value by multiplied by itself: " << value * value << "\n";
}
/* 3. Create an overloaded method that takes a double and returns it as an integer
* Call the method from main , reassign the passed in argument to the return value
* What was the typed of passing used inhere ?
* Ans : the type of passing used in here is pass by value.
*/
int overloadedMethod(double value){
return (int)value;
}
/* 4. Create an overloaded method that takes an address of an integer
* Pre decrement the argument
* Print it out inside the method and in the main
* What was the type of passing used inhere ?
* Ans: the type of passing used in here is pass by address.
*/
void overloadedMethod(int *address_of_int){
cout << "Printing the int value after increement it by one : " << ++(*address_of_int) << "\n";
}
/* 5. Create a method that takes a double array and the size of the array.
* The method casts elements of the array to an integer
* Print out the result inside the method and outside
* What was the type of passing used for the array?
* Ans : the type of passing used for the array is pass by reference
*/
void doubleArray(double arr[], int size){
cout << "Printing double array as an int values: \n";
for(int i = 0 ; i < size ; ++i){
arr[i] = (int)arr[i];
cout << arr[i] << "\n";
}
}
/* 6. Create an overloaded method that takes a double array and returns it an integer array
* Remember to use pointer and define your return array to be static
* Print out the returned array in the main method
*/
static int* method(double arr[], int size){
static int* intArr = new int[size];
for(int i = 0 ; i < size ; ++i){
intArr[i] = (int)arr[i];
}
return intArr;
}
/* 7. Create a method that takes three doubles whose default values are 2.2 3.3 4.4
* The method returns the additions of the arguments and print the result
* Call the method again and pass in two arguments and print the result
* Call the method again and pass in three arguments and print the result
*/
double method1(double d1 = 2.2, double d2 = 3.3, double d3 = 4.4){
return d1 + d2 + d3;
}
/* 8. Create an overloaded method of the previous method that takes two integers
* with default values and assign the answer to a global variable called addition
* The method returns the additions of the arguments
* Print out the result inside the main method
*/
int method1(int i1 = 2, int i2 = 3){
addition = i1 + i2;
return addition;
}
// main method
int main(){
// 1. calling print name method to print name;
printName("Your Name");
// 2.
overloadedMethod(5);
// 3
int value = overloadedMethod(2.123);
cout << "Printing value after converting the double number to int : " << value << "\n";
// 4
int intNumber = 5;
overloadedMethod(&intNumber);
cout << "Value after calling method : " << intNumber << "\n";
// 5
const int arraySize = 3;
double doubleArr[arraySize] = {2.2, 3.45, 4.56};
cout << "Printing the double array : \n";
for(int i = 0 ; i < arraySize ; ++i){
cout << doubleArr[i] << "\n";
}
doubleArray(doubleArr , arraySize);
// 6
cout << "Printing array after making all elements of array int \n";
int* arrPointer = method(doubleArr, arraySize);
for(int i = 0; i < arraySize ; ++i){
cout << arrPointer[i] << "\n";
}
// 7
cout << "Calling method with two double values : " << method1(5.6, 6.5) << "\n";
cout << "Calling method with three double values : " << method1(5.3, 5.6, 6.5) << "\n";
// 8
cout << "Calling overloaded method with two int arguments : " << method1(2 , 6) << "\n";
cout << "Value of addition global variable : " << addition << "\n";
}
Screenshot

Thank you!
This is code for c++. Any help would be great. #include <iostream> using namespace std; /*...
C++ Fraction calculator Need help with code, cant use "using namespace std" Objectives Create and use functions. Use a custom library and namespace. Use reference variables as parameters to return values from functions. Create a robust user interface with input error checking. Use exceptions to indicate errors. Resources kishio.h kishio.cpp Assignment requirements You will need eight methods (including main). One is given to you. Their requirements are specified below: menu: The menu function takes no arguments, but returns a char...
Part 1- Method practice Create a main method. In there, make an array of 100 random integers(numbers between 0 and 1000). Create a method to find average of the array. Pass the array and return the number(double) that is the average In the main method, call the method created in Step 2. Print out the average Create a method to find the min value of the array. Pass the array and return the int that is the smallest.(pass the value...
Example program
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
vector<int> factor(int n)
{
vector <int> v1;
// Print the number of 2s that divide n
while (n%2 == 0)
{
printf("%d ", 2);
n = n/2;
v1.push_back(2);
}
// n must be odd at this point. So we can
skip
// one element (Note i = i +2)
for (int i = 3; i <=...
In this lab, you will create one class named ArrayFun.java which will contain a main method and 4 static methods that will be called from the main method. The process for your main method will be as follows: Declare and create a Scanner object to read from the keyboard Declare and create an array that will hold up to 100 integers Declare a variable to keep track of the number of integers currently in the array Call the fillArray method...
#include <iostream>
using namespace std;
int * newZeroArray(int size) {
//your code here
}
int main() {
int size = 10;
int * A = newZeroArray(size);
for(int i = 0; i < size; i++)
cout << A[i] << " ";
cout << endl;
}Write a function that takes a size, creates a new array of that size with all zeros, and returns the array. If the size is not a valid size for an array, do not return a valid...
Edit this C++ code to show the output as well.
#include<iostream>
#include<cstring>
using namespace std;
class Product {
private:
// private variables
int id_number;
char pDescription[40];
int mId;
double productPrice;
double productMarkUp;
int qty;
public:
// constructor
Product() {
id_number = 0;
strcpy_s(pDescription, "");
mId = 0;
productPrice = 0.0;
productMarkUp = 0.0;
qty = 0;
}
...
part one : Review Exercises 1. Write method called raggedCount that takes an integer n as argument and returns a ragged array of n rows of lengths 1, 2, 3, 4, ... , n and the whole array has the integers 1, 2, 3, 4, ... , n(n+1) 2 in row order. For example, raggedCount(4) should return the array: 1 2 3 4 5 6 7 8 9 10 1 2. Write a method called arrayConcat that takes as argument...
c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input: an int output: boolean function: Return true if the number is a prime number and return false otherwise */ //TO DO ************************************** /* Write a function checkPrime such that input: an array of int and size of array output: nothing function: Display the prime numbers of the array */ //TO DO ************************************** /* Write a function SumofPrimes such that input: an int output: nothing...
Here is the code from the previous three steps:
#include <iostream>
using namespace std;
class Student
{
private:
//class variables
int ID;
string firstName,lastName;
public:
Student(int ID,string firstName,string lastName)
//constructor
{
this->ID=ID;
this->firstName=firstName;
this->lastName=lastName;
}
int getID() //getter method
{
return ID;
}
virtual string getType() = 0; //pure virtual function
virtual void printInfo() //virtual function to print basic details
of a student
{
cout << "Student type: " << getType() <<
endl;
cout << "Student ID: " << ID...
Code should be in C# Create a class called SavingsAccount. Use a static variable called annualInterestRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12 – this interest should be added to savingsBalance. Provide static method setAnnualInterestRate to set the annualInterestRate to a new value....