Question

Please create a C++ code that is around 20-30 lines of code and make it compile...

Please create a C++ code that is around 20-30 lines of code and make it compile and run showing how to use templates, overloading, and vectors (define these functions in the code)

Homework Answers

Answer #1

#include <iostream>
using namespace std;
#include<vector>

template <class T, class U>
T smaller(T a, U b) {
return (a < b ? a : b);
}
void printNumber(int x) {
cout << "Prints an integer: " << x << endl;
}
void printNumber(float x) {
cout << "Prints a float: " << x << endl;
}

int main () {
int x=72;
double y=15.34;
cout << smaller(x, y) << endl;
vector<int> a;
a.push_back(5);
a.push_back(6);
a.push_back(8);
for(int i=0;i<a.size();i++){
cout<<a.at(i)<<" ";

}
cout<<endl;
int c = 16;
float b = 54.541;
printNumber(c);
printNumber(b);

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C# Programming Write, compile, and test a program named Lyrics that displays at least four lines...
C# Programming Write, compile, and test a program named Lyrics that displays at least four lines of your favorite song. Code Patterns to follow are the following (All these have to check out: -Checks for correct use of WriteLine (4x) Description Searched your code for a specific pattern: (\s*WriteLine\(".*"\);\s*){4,} Start code with this outline: using static System.Console; class Lyrics {    static void Main()    {     // Write your main here    } }
(Do this in C++ please and make sure no compile/run errors): I. Write a function that...
(Do this in C++ please and make sure no compile/run errors): I. Write a function that writes a series of random Fahrenheit temperatures and their correspond- ing Celsius temperatures to a tab-delimited file. Use 32 to 212 as your temperature range. From the user, obtain the following: 1. The number of temperatures to randomly generate. 2. The name of the output file. A sample run is included below (you must follow the format provided below): Please enter the name of...
I need the code in C++ not C. please dont forget to create the menu!!!! Create...
I need the code in C++ not C. please dont forget to create the menu!!!! Create a phone book program that allows users to enter names and phone numbers of friends and acquaintances. Create a structure to hold contact information and use to calloc() reserve the first memory segment. The user should be able to add or modify phone book entries through a menu. Use the function to add contiguous memory segments to the realloc() original memory block when a...
C++ PROGRAMMING Submit the code for each problem separately. Important: Please place all appropriate coding comments...
C++ PROGRAMMING Submit the code for each problem separately. Important: Please place all appropriate coding comments inside of the code. Problem 1    Create a simple linked list program to create a class list containing class node {             void *info;              node *next; public:              node (void *v) {info = v; next = 0; }              void put_next (node *n) {next = n;}              node *get_next ( ) {return next;}              void *get_info (...
JavaScript Programming Assignment PLEASE NOTE:  You must create and call a main function, and if instructed include...
JavaScript Programming Assignment PLEASE NOTE:  You must create and call a main function, and if instructed include additional functions called by the main. Make sure to use ES6 style of keywords => instead of the older function and for local scope variables use the keyword let and not a keyword var. Make sure to follow the requirements and recheck before submitting. PROJECT GOAL: Write a program that is required to use nested loops to generate a triangle as shown in the...
Casting class objects 1.2 Compile and execute the code listed below as it is written. Run...
Casting class objects 1.2 Compile and execute the code listed below as it is written. Run it a second time after uncommenting the line obj.speak();. public class AnimalRunner {    public static void main(String[] args)    {       Dog d1 = new Dog("Fred");       d1.speak();       Object obj = new Dog("Connie");       // obj.speak();    } } The uncommented line causes a compile error because obj is an Object reference variable and class Object doesn’t contain a speak() method. This...
C programming 1. Create a file function.c that contains a function called printNumbers() that prints the...
C programming 1. Create a file function.c that contains a function called printNumbers() that prints the numbers 1 to 15. 2. Create a file function.h that contains the prototype for the printNumbers() function. 3. Create a file main.c that contains a main function that calls the printNumbers() function. You will need to be sure to include the header file. 4. Use gcc to compile the entire program (all files) without warnings. 5. Run the program and make sure that it...
Run Using Kali Linux....Create a source code file named "Lab1.c". The code is as follows. A...
Run Using Kali Linux....Create a source code file named "Lab1.c". The code is as follows. A child is created and prints a message five times. The original process (parent) prints a message only three times. How would this code look on the compiler if you could please post the code and the compiler results. Need Reference Thank You #include <sys/types.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> int main() { pid_t pid; char *message; int n; printf("fork program starting\n"); pid =...
Using C++ / provide code comments so I can understand. Create a simple linked list program...
Using C++ / provide code comments so I can understand. Create a simple linked list program to create a class list containing class node { void *info; node *next; public: node (void *v) {info = v; next = 0; } void put_next (node *n) {next = n;} node *get_next ( ) {return next;} void *get_info ( ) {return info;} }; Be able to initially fill the list. Provide functions to insert/append nodes and remove nodes from the linked list. Be...
can you please do this lab? use lunix or C program its a continuation of a...
can you please do this lab? use lunix or C program its a continuation of a previous lab. the previous lab: Unix lab 4: compile and link multiple c or c++ files Please do the following tasks step by step: create a new directory named by inlab4 enter directory inlab4 create a new file named by reverse.c with the following contents and then close the file: /*reverse.c */ #include <stdio.h> reverse(char *before, char *after); main() {       char str[100];    /*Buffer...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT