SHARE
TWEET

code

a guest Mar 19th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. /* Your solution goes here  */
  5.  
  6. void CoordTransform(int xVal, int yVal, int& xValNew, int& yValNew)
  7. {
  8.   xValNew = (xVal + 1) * 2;
  9.   yValNew = (yVal + 1) * 2;
  10. }
  11.  
  12. int main() {
  13.    int x;
  14.    int y;
  15.    int xValNew;
  16.    int yValNew;
  17.    
  18.    cout<<"Enter x coord:";
  19.    cin>>x;
  20.    cout<<"\nEnter y coord:";
  21.    cin>>y;
  22.    
  23.    CoordTransform(x, y, xValNew, yValNew);
  24.    cout << "\n("<<x<<", "<<y<<") becomes " << "(" << xValNew << ", " << yValNew << ")" << endl;
  25.  
  26.    return 0;
  27. }
  28.  
  29. --------------------------
  30.  
  31. //M19-02: Passing by Reference: Checking string length and capitalization
  32. #include <iostream>
  33. #include <stdio.h>
  34. #include <ctype.h>
  35.  
  36.  using namespace std;
  37.  
  38.  //FIXME: Modify function below to use pass by reference
  39.  bool message(string& msg)
  40.  {
  41.    cout << msg << endl;
  42.  
  43.    if(msg.length() > 10)
  44.      return(true);
  45.    return(false);
  46.  }
  47.  
  48. bool isCapital(string msg)
  49. {
  50.  
  51.   if(isupper(msg.at(0)))
  52.     return (true);
  53.   return (false);
  54.  
  55. }
  56.  int main(int argc, char **argv)
  57.  {
  58.    string userString;
  59.    cout<<"Enter your message:"<<endl;
  60.    getline(cin, userString);
  61.    
  62.    //FIXME: Modify code below to print state of capitalization
  63.    
  64.    bool msg_is_long = message(userString);
  65.    bool iscap = isCapital(userString);
  66.    if(msg_is_long)
  67.      cout << "That was a long message." << endl;
  68.    else
  69.      cout << "That was a short message." << endl;
  70.    
  71.     if(iscap)
  72.       cout << "The message was properly capitalized." << endl;
  73.    else
  74.      cout << "The message was not properly capitalized." << endl;
  75.    
  76.    return(0);
  77.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top