|
Apakah soalan std utk pertandingan programming - C++
[Copy link]
|
|
aku pakai capital sbb tgh wat keje pakai capital la...huhuh |
|
|
|
|
|
|
|
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. |
|
|
|
|
|
|
|
nah ni cth soalan assignment c++ degree level.
bleh kot wat jd soalan pertandingan.
otai_g Post at 11-8-2010 21:44
Ni soalan tugasan pertama subjek C++ aku masa zaman u dulu... |
|
|
|
|
|
|
|
nah ni cth soalan assignment c++ degree level.
bleh kot wat jd soalan pertandingan.
otai_g Post at 11-8-2010 21:44
memang susah.... |
|
|
|
|
|
|
|
nah ni jawapannya.
mcm x caya i done this questions.
tp zaman student dulu la...
rindu nak jd student balik
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[9],y[9];
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<<"lease enter x("<<a<<") : ";
cin>>x[a];
cout<<"lease enter y("<<a<<") : ";
cin>>y[a];
}
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[9];
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[a] = (m * x[a]) + c;
cout<<"\nx = "<<x[a]<<", y = "<<y[a]<<", Calculated y = "<<ceky[a];
}
cout<<endl;
} |
|
|
|
|
|
|
|
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;
} |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
| |
|