kiki009 Publish time 11-8-2010 07:03 PM

aku pakai capital sbb tgh wat keje pakai capital la...huhuh

otai_g Publish time 11-8-2010 09:44 PM

Post Last Edit by otai_g at 11-8-2010 21:46

nah ni cth soalan assignment c++ degree level.
bleh kot wat jd soalan pertandingan.


6. Given a series of x and y co-ordinates it is possible to plot a straight line through these points, the equations for which is the standard equation for a straight line :
y = mx +c
Given a number of pairs of x and y values, m can be calculated as :
m = nΣxi yi – (Σxi)( Σ yi) / nΣxi² - (Σ xi)²

and c can be calculated as :
c = Σ yi - mΣxi
         n       n
where n is the number of sets of x and y values, and xi and yi are individual pairs.
Write a program that,

a) Asks the user how many sets of x and y values are to be entered and then reads these sets of values from the keyboard . These values should be stored in an array of floats
A minimum of three and a maximum of ten sets of x and y values must be entered in order for the program to run. If a value for the number of pairs x and y selected is outside this range, an error message should be displayed.

b) using suitable functions, calculate the values of m and c from the values enterd and displays these on the screen

c) For each value of x entered, calculate a value for y obtained using the value of m and c. This value should then be displayed on the screen , together with the value of x used an the original value of y entered.

juwaini Publish time 12-8-2010 02:38 AM

nah ni cth soalan assignment c++ degree level.
bleh kot wat jd soalan pertandingan.
otai_g Post at 11-8-2010 21:44 http://mforum.cari.com.my/images/common/back.gif

Ni soalan tugasan pertama subjek C++ aku masa zaman u dulu... :lol:

adlismel Publish time 14-8-2010 12:48 PM

susahnya

kiki009 Publish time 14-8-2010 09:49 PM

nah ni cth soalan assignment c++ degree level.
bleh kot wat jd soalan pertandingan.
otai_g Post at 11-8-2010 21:44 http://mforum.cari.com.my/images/common/back.gif


    memang susah....:dizzy:

otai_g Publish time 15-8-2010 12:54 AM

nah ni jawapannya.
mcm x caya i done this questions.
tp zaman student dulu la...
rindu nak jd student balik :lol:
if time can turning back.....


/*
program ni dah jd mcm progam paria
program ni blh dipendekkan lg kalo nak
*/

#include <iostream.h>
#include <math.h>

int total,a;
double x,y;
void kiraan();

void main()
{
        cout<<"How many sets of data points are to be entered : ";
        cin>>total;
        cout<<endl;

        if (total < 3 || total > 10)
        {
                cout<<"Error!minimum 3 and maximum 10"<<endl;
                main();
        }

        for (a=0;a<total;a++)
        {
                cout<<"Please enter x("<<a<<") : ";
                cin>>x;
                cout<<"Please enter y("<<a<<") : ";
                cin>>y;
        }

        kiraan();       
}

/*
temp1 = hasil tambah x darab y
temp2 = hasildarab hasil tambahx dgn hasiltambahy
temp3 = hasiltambah setiap x kuasa2
temp4 = hasiltambah x dikuasa2
*/
void kiraan()
{
        int b;
        double temp1=0,temp2=0,htambahx=0,htambahy=0,temp3=0,temp4=0,ceky;
        double matas,mbawah,m;
        double c1,c2,c;

        for (b=0;b<total;b++)
        {
          htambahx = htambahx + x;
                htambahy = htambahy + y;
                temp1 = temp1 + (x * y);
                temp3 = temp3 + pow(x,2);
        }

        temp2 = htambahx * htambahy;
        temp4 = pow(htambahx,2);

        matas = (total * temp1) - temp2;
        mbawah = (total * temp3) - temp4;
        m = matas / mbawah;

        c1 = htambahy / total;
        c2 = (m * htambahx) / total;
        c = c1 - c2;

        cout<<"Calculated gradient (m) = "<<m<<endl;
        cout<<"Calculated intercept (c) = "<<c<<endl;

        for (a=0;a<total;a++)
        {
                ceky = (m * x) + c;
                cout<<"\nx = "<<x<<", y = "<<y<<", Calculated y = "<<ceky;
        }
        cout<<endl;
}

sepulnuar Publish time 21-8-2010 10:55 PM

if (total < 3 || total > 10)
{
      cout<<"Error!minimum 3 and maximum 10"<<endl;
      main();
}
aik, panggil main() dlm if? wat happen to the initial main()? disposed? recurcived?
how about this?
while(total < 3 || total > 10){
      cout<<"How many sets of data points are to be entered : ";
      cin>>total;
      cout<<endl;
}

otai_g Publish time 25-8-2010 07:14 PM

Reply 27# sepulnuar

biasa la ni coding zaman bdk2 mentah dulu.
mmg byk lack sbb dlm pala pikir asal siap sudah...
u are welcome to upgrade this coding :lol:

otai_g Publish time 14-9-2010 07:09 PM

aku jumpa soalan ni kat internet.
bleh kot wat soalan pertandingan.


1) write a program to calculate class attendance.
2) how the program work:-
* lecturer prepare a attendance file for each class.
* Let say 14 week class, so each file should be
      classattendanceweek1.txt, classattendanceweek2.txt ...
      classattendanceweek14.txt
* The format content for classattendanceweek1.txt..classattendanceweek14.txt will be
      matrix, name
* After the files above are ready, the program will open all the files and generate a summary
    class attendance output summaryattendance.txt
* The format for summaryattendance.txt will be
         matrix, name , total attended, Total attended in percent
Pages: 1 [2]
View full version: Apakah soalan std utk pertandingan programming - C++


ADVERTISEMENT