<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>Sharing Community - C++</title>
        <description>This is C++ section</description>
        <link>http://www.cppjj.com/forum/list.php?9</link>
        <lastBuildDate>Thu, 09 Sep 2010 07:08:22 -0600</lastBuildDate>
        <generator>Phorum 5.2.9a</generator>
        <item>
            <guid>http://www.cppjj.com/forum/read.php?9,59,59#msg-59</guid>
            <title>testing (no replies)</title>
            <link>http://www.cppjj.com/forum/read.php?9,59,59#msg-59</link>
            <description><![CDATA[ test]]></description>
            <dc:creator>admin</dc:creator>
            <category>C++</category>
            <pubDate>Thu, 24 Sep 2009 21:59:34 -0600</pubDate>
        </item>
        <item>
            <guid>http://www.cppjj.com/forum/read.php?9,44,44#msg-44</guid>
            <title>C++, array, sorting, and functions (no replies)</title>
            <link>http://www.cppjj.com/forum/read.php?9,44,44#msg-44</link>
            <description><![CDATA[ //<br />
//             This project asks the user for a series of grade.<br />
//             Then, it will caculate the grade average, standard Deviation<br />
//             Then it prints out how many grades the user entered,<br />
//             The average, standard deviation, max, and the min of the grades.<br />
//             The program will exit if the user enters -1, numbers that are not<pre class="bbcode"></pre>
<br />
//             Between 0 and 100 or the user entered more than 100 numbers<br />
//<br />
<br />
#include&lt; iostream &gt;<br />
#include&lt; cassert &gt;<br />
#include&lt; math.h &gt;<br />
using namespace std;<br />
<br />
void get_grades(double a[], int size, int& numnberUsed);<br />
void sort_grades(double a[], int& numberUsed);<br />
void comp_stats(double a[], int& numberUsed);<br />
<br />
//This is the main method<br />
// It prints out the grade in a sorting oder<br />
// The grades will be print 10 per row<br />
<br />
int main()<br />
{<br />
    <br />
    <br />
    double sampleArray[100]; // set the array with size 100<br />
    int numberUsed;<br />
    get_grades(sampleArray, 100, numberUsed); // passing the sampleArray, size, and number used into the function get_grade<br />
    sort_grades(sampleArray, numberUsed);//passing sampleArray, and numberUsed into the function sort_grade<br />
   <br />
    cout&lt;&lt;"\n";<br />
    <br />
    //Using a loop to print out the array <br />
    //Check the condition, if the reminder of the index equals to 0 go to the next line<br />
    <br />
    for(int index = 0; index &lt; numberUsed; index++)<br />
    {<br />
           if(((index)%10)==0 && index !=0)<br />
           cout&lt;&lt;"\n";       <br />
           cout&lt;<sampleArray[index]&lt;&lt;" ";     }     cout&lt;&lt;"\n"&lt;&lt;"\n";          comp_stats(sampleArray,  numberUsed);          system("PAUSE"); // uses to pause the command window when the program is executed          return 0; }  //A void fuction that asks the user for a series of grade //The parameters are sampleArray, 100, and numberUsed // We are using the int& instead of int because it's a void function and not a returning function // void get_grades(double a[], int size, int& numberUsed) {                 cout&lt;&lt;"\nEnter grade(-1 to end ):"           &lt;&lt;"\n?";           double next;           int index = 0;           cin>&gt;next;<br />
          <br />
          // If user enters something more than 100 or less than 0<br />
          // The program will terminate<br />
          //<br />
          if((next&gt;=100) || (next &lt; -1 ))<br />
          {<br />
           cout&lt;&lt;"Error: number must be between 0 and 100\n "<br />
               &lt;&lt;"Program will exit\n";<br />
                         system("PAUSE");<br />
                         exit(1);<br />
          }<br />
          // The program will continue to loop until the user enters -1<br />
          // Two condition inside the loop<br />
          //<br />
          else<br />
          while(next != -1)<br />
          {<br />
                 a[index]= next;<br />
                 index++;<br />
                 cout&lt;&lt;"?";<br />
                 cin&gt;&gt;next;<br />
                 <br />
                 // If the user enters something that is below 0 or above 100<br />
                 // The program terminates<br />
                 //<br />
                 if((next&gt;=100) || (next &lt; -1 ))<br />
                 {<br />
                   cout&lt;&lt;"Error: number must be between 0 and 100\n"<br />
                       &lt;&lt;"Program will exit\n";<br />
                         system("PAUSE");<br />
                         exit(1);<br />
                         <br />
                 }<br />
                 // If the user enters more than 100 grades <br />
                 // The program terminates<br />
                 //<br />
                 if(index &gt; size)<br />
                 {<br />
                          cout&lt;&lt; " Warning: maximum number of grades reached\n"<br />
                              &lt;&lt;"Program will exit now\n";<br />
                              exit(1);<br />
                              }                         <br />
                 <br />
                 <br />
          }<br />
          //Determines how many numbers the use entered<br />
          //<br />
                 numberUsed = index;<br />
}<br />
// A void function that sorts the grade<br />
// int& numberUsed holds the size that the user entered<br />
//<br />
void sort_grades(double a[], int& numberUsed)<br />
{<br />
     double temp;<br />
     for(int index = 0; index &lt; numberUsed-1; index++)<br />
     {<br />
             for(int j = (index + 1); j &lt; numberUsed; j ++)<br />
             {<br />
                     if(a[index] &gt; a[j])<br />
                     {<br />
                             temp = a[index];<br />
                             a[index] = a[j];<br />
                             a[j] = temp;<br />
                     }<br />
             }<br />
           <br />
     }<br />
}<br />
// This is a void function that computes  the mean, max, min, and standard deviation<br />
//<br />
void comp_stats(double a[], int& numberUsed)<br />
{<br />
   double sum = 0, total = 0;<br />
   int index=0;<br />
   double max, ave, std, sqstd;<br />
   int startIndex = 0;<br />
   max = a[startIndex];<br />
   int indexOfMax = startIndex;<br />
   double dev[numberUsed];<br />
    <br />
   for (index = 0; index &lt; numberUsed; index++)<br />
    {<br />
        if(a[index] &gt; max)<br />
        {<br />
           max = a[index];<br />
          indexOfMax = index;<br />
     }        <br />
        <br />
        sum = sum + a[index];<br />
        <br />
    }<br />
<br />
   ave = static_cast<double>(sum)/numberUsed;<br />
   <br />
   for (index =0; index &lt; numberUsed; index++)<br />
   {<br />
       dev[index] = ave - a[index];<br />
       <br />
   }<br />
   for(index = 0; index &lt; numberUsed; index++)<br />
   {<br />
             total = total + pow(dev[index], 2);<br />
             <br />
   }<br />
   <br />
   std = total / (numberUsed - 1);<br />
   sqstd = sqrt(std);<br />
   <br />
   cout&lt;&lt;"Count = " &lt;&lt; numberUsed  &lt;&lt; " Mean = " &lt;&lt; ave<br />
       &lt;&lt;" Std. Dev.= "&lt;&lt; sqstd&lt;&lt;" Max.= " &lt;&lt;a[indexOfMax] &lt;&lt;" Min.= " &lt;&lt; a[startIndex]<br />
       &lt;&lt;"\n";<br />
}]]></description>
            <dc:creator>jj</dc:creator>
            <category>C++</category>
            <pubDate>Wed, 11 Feb 2009 15:26:35 -0700</pubDate>
        </item>
        <item>
            <guid>http://www.cppjj.com/forum/read.php?9,35,35#msg-35</guid>
            <title>Guess Random number game C++ (no replies)</title>
            <link>http://www.cppjj.com/forum/read.php?9,35,35#msg-35</link>
            <description><![CDATA[ #include&lt; iostream &gt;<br />
#include&lt; stdlib.h &gt;<br />
#include&lt; stdio.h &gt;<br />
#include&lt; time.h &gt;<br />
using namespace std;<br />
<br />
int main()<br />
{<br />
    int Secret, Guess;<br />
    int n = 0;<br />
    srand( time(NULL) );<br />
    <br />
    Secret = rand()%101;<br />
    <br />
    cout&lt;&lt;"Welcome to Guess-my-Number version 0.1 \n"<br />
        &lt;&lt;"Copyright (C) Jay Lei 2009. All rights reserved.\n";<br />
        <br />
    cout&lt;&lt;"\n"&lt;&lt;"\nA secret number between 1-100 generated...\n";<br />
    cout&lt;<Secret;         do{          cout&lt;&lt;"\nPlease enter your guess? ";          cin>&gt;Guess;<br />
       <br />
         if(Secret == Guess)<br />
         {<br />
                   cout&lt;&lt;"Correct in " &lt;&lt; n + 1 &lt;&lt;" guesses.\n";<br />
                   break;<br />
         }<br />
         else if (Guess == 0)<br />
         {<br />
              cout&lt;&lt;"The secret number is " &lt;&lt; Secret &lt;&lt;".\n";<br />
         }<br />
         else if(Secret &lt; Guess)<br />
         {<br />
                   cout&lt;&lt;"Guess is too high...";<br />
         }<br />
         else if(Secret &gt; Guess)<br />
         {<br />
              cout&lt;&lt;"Guess is too low...";<br />
         }<br />
    <br />
	     n++;<br />
       }while((n &lt;8) && (Guess !=0));<br />
       if (n==8)<br />
       {<br />
                 cout&lt;&lt;"\n"&lt;&lt;"\nToo many guesses, the secret number is "<br />
                 &lt;&lt;Secret&lt;&lt;".\n";   <br />
       }<br />
  <br />
	system("PAUSE");<br />
	<br />
	return 0;<br />
<br />
}]]></description>
            <dc:creator>admin</dc:creator>
            <category>C++</category>
            <pubDate>Fri, 23 Jan 2009 16:41:10 -0700</pubDate>
        </item>
    </channel>
</rss>
