[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

C++ Sample Program

Asked by ExpExchHelp in C++ Programming Language

Tags: sample, program

Today will be the first evening for an engineering class... I've already previewed tonight's lecture material that includes some sample C++ code.

I took C++ ~10 years ago.   Haven't used it since and am very rusty.   I still have Borland's C++ v5.02 compiler.   When plugging the teacher's code in the "old" compiler, none of them work.

Obviously, I'll get more info tonight.   I was wondering if someone already could tell me what I'm missing.  Has the language since and I could not use v5.02 for the suggested code?    Are the progams (between ***s below) all separate sample program?  

EEH


Sample Code
==========

// pe02-01.cpp
#include <iostream>
using namespace std;

int main()
{
  cout << "Replace this with your code.\n";
  return 0;

}

*******************************************************************

// yourcat.cpp -- input and output
#include <iostream>
using namespace std;
int main()
{
    int fleas;

    cout << "How many fleas does your cat have?\n";
    cin >> fleas;               // C++ input
// next line concatenates output
    cout << "Well, that's " << fleas << " fleas too many!\n";

    return 0;
}

*******************************************************************

// sqrt.cpp -- use a square root function
#include <iostream>
using namespace std;
#include <cmath>        // or math.h
int main()
{
    double cover, side;       // use double for real numbers
    cout << "How many square feet .. do you have?\n";
    cin >> cover;
    side = sqrt(cover); // call function, assign return value
    cout << "Your square has sides of " << side;
    cout << " feet << \n";
    return 0;
}

*******************************************************************

// forloop.cpp -- introducing the for loop
#include <iostream>
using namespace std;
int main()
{
    int i;  // create a counter
    //   initialize; test ; update
    for (int i = 0; i < 5; i++)
      {
        cout << "C++ knows loops.\n";
      } //Use braces if >1 statement
    cout << "C++ knows when to stop.\n";
    return 0;
}

*******************************************************************

// uniform random number generator
#include <iostream>
#include <cmath>
using namespace std;
//function prototypes (if any)


int main()
{
//  initializations
const int N=1024 ;
int  i, tst;
float r, avg, x2, sum, var ;
r = 0.0 ;
tst = 1 ;
while (tst >= 0 ) // while loop
      {
      cout << "continue?  ;
      cin >> tst;
//test for termination condition
      if (tst >= 0)


{
      float max = pow(2.0,15.0); // math fcn.
      max=max-1; // want 2 **15 - 1
      cout<< "\n";
      avg=0;
      x2=0;
      sum=0;
      int init=-1;
      for ( i=0; i<N;  i++ )
            {      
            r = rand() / max; // normalize {0-1}
            x2=x2 + r*r; // accum. xi^2 and xi
             sum = sum + r;
            } // end for


//  compute sample variance and average
      
      var = ( N * x2 - sum*sum ) / ( N *( N-1) );
      cout << "average =  < sum / N << "Sample   var. =  << var << "\n";
      
    }// end if
}// end while
return(0); /*end */
}
//   end Example

*******************************************************************
[+][-]08/28/07 08:03 AM, ID: 19783668Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: C++ Programming Language
Tags: sample, program
Sign Up Now!
Solution Provided By: Kdo
Participating Experts: 6
Solution Grade: A
 
[+][-]08/28/07 08:07 AM, ID: 19783713Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/28/07 08:29 AM, ID: 19783991Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/28/07 08:55 AM, ID: 19784266Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/28/07 09:00 AM, ID: 19784323Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/28/07 09:24 AM, ID: 19784564Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/28/07 10:30 AM, ID: 19785104Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/30/07 02:40 AM, ID: 19798591Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 / EE_QW_1_20070628