workshop_2.cpp - IEEE TAMU C Workshop#2 Oneal...

Info icon This preview shows pages 1–2. Sign up to view the full content.

/* IEEE TAMU C++ Workshop #2 Oneal Abdulrahim */ #include <iostream> #include <string> using namespace std; /// repeat a word /** This method prints a string, line by line, a given number of times. @param times The number of times to print the string @param s The string to print @return void Does not return anything */ void repeat_word(int times, string s) { // this loop goes from 1 until whatever "times" is // Can you convert this to a while loop? for (int i = 1; i <= times; ++i) { cout << s << endl; } } /// add two objects /** This method adds two objects together using the "+" operator. This means that whatever operation is defined for "plus", it will be performed. This is because the method is templated, meaning it can deal with any data type, as long as C++ knows what to do with "+". @param a The first object @param b The second object @return The sum of a and b */ template <class T> T addition(T a, T b) { return a + b; } int main() { // Part 1 Structures and Loops--------------------------------------------- cout << "\n*** Part 1 ***" << endl; // declare new integer for the user's choice int num_choice; // give the user some choices, basically a small menu
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern