Passing pointers to functions pointer arithmetic c

Info icon This preview shows pages 14–23. Sign up to view the full content.

View Full Document Right Arrow Icon
 passing pointers to functions  pointer arithmetic   c strings  new and delete Classes:  struct  class  public and private   member variables   member functions  const functions  construction  destruction  the C++ “string” class Syntax counts! 
Image of page 14

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

View Full Document Right Arrow Icon
Visual C++ 2008 You can use any C++ compiler you like in this class, as long as your programs  compile and work with  Visual C++ 2008  when we grade them.   Note: If you use another compiler, make sure your projects work with Visual C+ + 2008 before submitting them!   You can get a free copy of the student version of  Visual C++ from:  Or, you can use Visual C++ in the lab.
Image of page 15
Time for CS Alright…  Enough administration.  It’s time to do some Computer Science. To get you back into the CS mood, let’s do some  challenge problems ! (oh boy)
Image of page 16

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

View Full Document Right Arrow Icon
Class Challenge #1 You can pair up with another person in the  class for this challenge. The winning team wins $2. Challenge: Write a function called  SumOdds  that sums all of the  odd numbers  in  an array up until it hits a  -1  and then returns the result. main( ) {    int arr[6] = {2, 3 ,10, 19 , 7 ,-1 };    n = SumOdds(arr);     cout << n;             // prints 29 }
Image of page 17
Challenge #1: Answer int SumOdds(int arr[]) {    int temp = 0;    int j;    for (  j=0 ;  arr[j] != -1  ;  j++)    {       if (arr[j] % 2 == 1)          temp += arr[j];    }    return(temp); }
Image of page 18

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

View Full Document Right Arrow Icon
0, 1, 1, 2, 3, 5, 8, 13, etc… Class Challenge #2 Write a function called  isFibonacci  that accepts an array of  100 integers  as an  argument, and returns a  boolean  result. The function should return  true  if the sequence of numbers is a  Fibonacci  sequence  and  false  otherwise.  Example:      int arr[100] = {0,1,1,2,3,5,8,13,21,…};      if ( isFibonacci (arr) == true)          cout << “We have a winner!”; A Fibonacci sequence is a list of numbers where the first two numbers are  0 and 1.  Each successive number is the sum of the previous two numbers:                     You can also work in pairs on this problem. But… the team that won Challenge #1 is  exempt from winning the prize. And, the prize is… $5.
Image of page 19
Challenge #2: Answer bool isFibonacci(int arr[]) {    int j;    if (arr[0] != 0 || arr[1] != 1)      return(false);    for (  j=2 ;  j < 100  ;  j++)    {       if (arr[j] != arr[j-1] + arr[j-2])          return(false);    }    return(true); }
Image of page 20

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

View Full Document Right Arrow Icon
Algorithms and Data Structures Data Structures Get it?
Image of page 21
What is an Algorithm What was the algorithm we used for the Fibonacci program?
Image of page 22

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

View Full Document Right Arrow Icon
Image of page 23
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