C++ Programming Exercise Help

Collapse

Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • EagleOne
    Honorary DSA

    C++ Programming Exercise Help

    So I need to write a program for my C++ class but am needing help. If you are able to write this program there is a free copy of either P90x, Zumba (DVD's) or a 3 month MS Live Gold Card. I need this by tomorrow (21st) noon time. I hope someone can come through for me.

    Here is the problem:

    7.41 (Polling) The Internet and the web are enabling more people to network, join a cause, voice opinions, and so on. The presidential candidates in 2008 used the Internet intensively to get out their messages and raise money for their campaigns. In this exercise, you’ll write a simple polling program that allows users to rate five social-consciousness issues from 1 (least important) to 10 (most important). Pick five causes that are important to you (e.g., political issues, global environmental issues). Use a one-dimensional array topics (of type string) to store the five causes. To summarize the survey responses, use a 5-row, 10-column two-dimensional array responses (of type
    int), each row corresponding to an element in the topics array. When the program runs, it should ask the user to rate each issue. Have your friends and family respond to the survey. Then have the program display a summary of the results, including:
    a) A tabular report with the five topics down the left side and the 10 ratings across the top, listing in each column the number of ratings received for each topic.
    b) To the right of each row, show the average of the ratings for that issue.
    c) Which issue received the highest point total? Display both the issue and the point total.
    d) Which issue received the lowest point total? Display both the issue and the point total.
    Again, I am seriously needing the help due to being behind because of work.


  • #2
    RaTix
    Emperor

    If it was PHP I could do it pretty easily for you. C++ is not really my forte though. What are you stuck on though? Maybe I could help you through it. Programming is similar in all languages.

    One-dimensional array is a single set of information stored in an array. Like,

    Array = (A,B,C,D)
    Which in PHP is the same as
    Array[1] = A, Array[2] = B, etc..

    Where it is stored, is what the index number of it is. So to call the data, you can call Array[1] to get A, Array[2] to get B, and so on.

    Two-Dimensional array has two sets of info or arrays stored (Which in PHP is the same as a multi-dimensional array I think).

    Ok hold up.... Researching this a bit. ...

    I can't do the whole thing for you, but maybe give you some insight.

    String ArrayQuestion [5] = { Question1, Question2, Question3, Question4, Question5 }; //Creates the array of 5 strings, each with the corresponding question.

    Int Array2DAnswers [5] [10]; //This makes a 5 X 10 box or grid array, aka 2 dimensional array. Think 5 boxes high x 10 boxes long

    From here I guess you can assign each as needed.

    Array2D [1] [1] = 0 (for no reponse) 1 (for yes response) //this is the top left most box of that grid.

    So if they answer the first poll question with a reply of 1 out of 10, this would get "yes" or "1". The other [1] [x] arrays would get "0".

    So to pull the data you would simply query which arrays have 1 or Yes, and display that as the answer.

    That's retarded if I am understanding it right. Not sure why you need 10 boxes for the responses in each question. Because in PHP it would be easier to just store as,

    (ArraySurvey (Question1 => X [whatever number they answer with], Question2 => X, etc..)
    Then just explode the array and populate into variables to display.



    Not sure if this helps you at all, or just confused the fuck out of you. I;m gonna go grab a beer and forget that you made me do programming on a friday night when there's Minecraft that needs to played. lol.
    "POWER!!! UNLIMITED POOWWWEEEER!!!!!!

    "Tell me what you regard as your greatest strength, so I will know how best to undermine you; tell me of your greatest fear, so I will know which I must force you to face; tell me what you cherish most, so I will know what to take from you; and tell me what you crave, so that I might deny you."
    ?Darth Plagueis

    "Peace is a lie, there is only passion. Through passion, I gain strength. Through strength, I gain power. Through power, I gain victory. Through victory, my chains are broken. The Force shall free me."

    Comment

    • #3
      EagleOne
      Honorary DSA

      Well thanks for the help Ratix, I was able to figure out about 70% of the code but that was all. I turned in the assignment and hopefully the instructor cuts me some slack since I am one of her top students. Stupid arrays.


      Comment

      • #4
        MellowYellow989
        Civilian

        Quick Program

        Code:
        /*I know its late(I hadnt seen the post), 
        but perhaps you can learn a bit or still use it if you want. 
        This doesnt do the averages or the high and low, and I 
        wrote it so it repeats itself until you are done as opposed 
        to writing to a database, hope it helps a bit, it should compile
         for you*/
        
        #include <iostream>
        #include <fstream>
        #include <cstdlib>
        #include <cstring>
        #include <stdio.h>
        
        
        
        using namespace std;
        
        int main () 
        {
         string issues[]={"Health care     ","Social Security ","Trade Deficit   ","Immigration     ","Poverty         "};     
         int ans[5][10];
         int temp;
         char c='y';
         for  (int i=0;i<5;i++)
            {
               for (int j=0;j<10;j++)
               {
                  ans[i][j]=0;
                }
            }
        
        while (c!='n')
        {
         system("cls");
         cout<<"Thank you for taking our survey, Please let us know on a scale of 1-10\nhow you would rate these issues in importance\n\n";system("pause");
         int rate;
         char input [20];
         for (int i=0;i<5;i++)
             {
         
                  system("cls");   
                  cout<<issues[i]<<": ";
                  cin>>input;
                  while (!isdigit(input[0]))
                        {
                         cout<<"Please enter a number between 1-10\n";
                         cin>>input;
                        }
                  rate= atoi(input);
                  while (rate>10||rate<1)
                        {
                         cout<<"Please enter a number between 1-10\n";
                         cin>>rate;
                        }
                  ans[i][rate-1]++;
             }        
         system("cls");
         float avg=0;
         cout<<"Ratings          1  2  3  4  5  6  7  8  9  10 Avg\n";
         for  (int i=0;i<5;i++)
             { 
                   cout<<issues[i];
                   for (int j=0;j<10;j++)
                      {
                           avg+=ans[i][j];
                           cout<<" "<<ans[i][j]<<" ";
                      }
                      
                      cout<<" "<<avg;
                      avg=0;
                   cout<<"\n";
             }
         cout<<"\n\nWould you like to go again? y/n: ";
         cin>>c;
              }
         system("pause");
         return 0;
        }
        Last edited by MellowYellow989; 01-29-2012, 12:00 AM. Reason: One of the few times I can test out the CODE tags :)


        The first requisite of a good citizen in this republic of ours is that he shall be able and willing to pull his own weight.

        Comment

        • #5
          MellowYellow989
          Civilian

          when i wrote that during lunch today it worked on my computer fairly well, got home and copied and pasted it, the spacing is off on the output, but its all still there.


          The first requisite of a good citizen in this republic of ours is that he shall be able and willing to pull his own weight.

          Comment

          • #6
            RaTix
            Emperor

            Edited your post mellow. Honestly I just wanted to test out the CODE tags. Not often it gets used around here.
            "POWER!!! UNLIMITED POOWWWEEEER!!!!!!

            "Tell me what you regard as your greatest strength, so I will know how best to undermine you; tell me of your greatest fear, so I will know which I must force you to face; tell me what you cherish most, so I will know what to take from you; and tell me what you crave, so that I might deny you."
            ?Darth Plagueis

            "Peace is a lie, there is only passion. Through passion, I gain strength. Through strength, I gain power. Through power, I gain victory. Through victory, my chains are broken. The Force shall free me."

            Comment

            • #7
              MellowYellow989
              Civilian

              cool, you know the part with the /* and the */ could have gone in there as well

              edit, also i didnt know we could edit our post, fixed
              Last edited by MellowYellow989; 01-28-2012, 11:58 PM.


              The first requisite of a good citizen in this republic of ours is that he shall be able and willing to pull his own weight.

              Comment

              Ad

              Collapse
              Working...