Question: Write a program in Qbasic W-loop to print "Highest Scorers" amongst 4 students with 3 subjects per student.

Date Posted: Oct 24th, 2011

Requester: Kousik Das

Solution

LET STUDENT = 4

LET I = 1

LET SC = 1

LET HIGHSC = 0

DO WHILE (I < STUDENT)

INPUT "ENTER STUDENT NAME"; N\$

LET SUM = 0

INPUT "ENTER THE SCORE FOR SUBJECT1"; S1

INPUT "ENTER THE SCORE FOR SUBJECT2"; S2

INPUT "ENTER THE SCORE FOR SUBJECT3"; S3

LET SUM = S1 + S2 + S3

PRINT ""

PRINT N\$, SUM

IF SUM > HIGHSC THEN

LET WINNER\$ = N\$

LET HIGHSC = SUM

END IF

I = I + 1

LOOP

PRINT ""

PRINT "THE LEADER IS "; WINNER\$

PRINT "SCORE IS "; HIGHSC

Question:  How these equation in fortran language {1} ax^2+bx+c=0 {2} almighty formular consider b^2<4ac

Date Posted: August 17,2011

Requester:  Seidu seun

Solution

Question: Write a Visual Basic program to convert from Decimal to binary:

Date Posted:   June 11, 2011

Requester: Vivian A.

Solution

Public Class Form1

'This sub convert from decimal to Binary

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

Dim r As Integer  'For storing remainder

Dim ans As Integer  'for storing division answer

Dim ss As String    ' string for storing binary answer

Dim cc As Char()    'character array

ss = ""

binAns.Text = ""

If Val(dec.Text) > 0 Then      'make sure the user enter value greater than 0

Dim n As Integer = Val(dec.Text)

' convertion

If n > 1 Then

Do

ans = Math.DivRem(n, 2, r)

ss += r.ToString

n = ans

Loop While ans > 1

ss += "1"

'Re-arranging the characters

Dim i As Integer = ss.Length

cc = ss.ToCharArray()

For j = cc.Length - 1 To 0 Step -1

binAns.Text += cc(j)

Next

Else

binAns.Text = 1

End If

Else

MessageBox.Show("Enter value Greater than 0")

End If

End Sub

'This is sub to convert from Binary to Decimal

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click

Dim cc As Char() = bin.Text.ToCharArray

Dim ans As Integer = 0

decAns.Text = ""

For j = 0 To bin.Text.Length - 1

If Val(cc(j)) > 1 Then

MessageBox.Show("This is not a binary value")

Exit Sub

Else

Dim rCount As Integer = bin.Text.Length - 1 - j

ans += Val(cc(j)) * 2 ^ rCount

End If

' MessageBox.Show("no.:" + test.ToString)

Next

decAns.Text = ans

End Sub

End Class

Question:    Write a program to compute Average of numbers. -Adelabu Lukman, University of Ado-Ekiti

Solution

 QBASIC Input "How many Nos?", N S=0For I=1 to NInput "Enter a No."; KLet S=S + Knext ILet A = S/NPrint "Average = ",A C- Language #includemain(){int n,i,k,s,a;s=0;printf("How many Nos?");scanf("%d",&n);for (i=1; i<=n; i++){printf("\nEnter a no.?");scanf("%d",&k);s+=k;}a=s/n;printf("\nAverage = %d", a);Return 0;} FORTRAN INTEGER N, I, K, S, ARead (*,*) NDO 10 I=1, NRead(*,*) KS=S + K10 CONTINUEA= S/N Write(*,*) 'Average = ',A End

Using Visual solutions  (Visual Basic and Visual C++)

Enter The Number Here

Average is

Note: names of Textboxes are m_no and m_av respectively

Having the form designed as above, Then insert the following code on clicking each command button:

 Visual Basic ModulePublic s, ns=0: n=0 Sub Okbutton()s = s + m_no.textn= n + 1m_no.text= 0End sub Sub Onsolve()m_av.text =  s / nEnd sub Sub Onrefresh()s=0: n=0: m_no.text=0: m_av.text=0End sub Visual C++ global int n, s;n=0;s=0; Okbutton(){UpdateData(True);s+=m_no;n++;m_no=0;UpdateData(False);} Onsolve(){m_av = s /n;UpdateData(False);} Onrefresh(){m_av=0: m_no=0: s=0: n=0;UpdateData(False);  }

Question:    Write a program to Calculate the Roots of a Quadratic Equation    -

Requester: Adepoju Akeem, Federal Polytechnics Offa, Nigeria

Solution

X2 + X +  = 0

1st Root is    2nd Root is
Textboxes are A, B, C, X1, X2 respectively.

Using Almighty Formula X = (-B+-SQR(B2 - 4AC))/(2A)

 VISUAL BASIC Sub onsolve()a1= A.textb1=B.textc1=C.textD=b1*b1 - 4 * a1 * c1if D<0 Then'Complex RootX1.text = -b1/(2*a1)X2.text = (-SQR(-D)) & "i"Elseif D=0 ThenX1.text = b1/(2*a1)X2.text=X1.textElseX1.text=(-b1+SQR(D))/(2*a1)X2.text=(-b1-SQR(D))/(2*a1)End ifEnd sub C-Language #include #include int main(){int a,b,c,x1,x2;printf("\nEnter the value of A, B, C");scanf("%d %d %d", &a, &b, &c);d = b**2-4*a*c;if (d<0){//Complex Rootx1= -b/(2*a);x2= (-d)**0.5;}if (d=0){//Equal rootsx1= -b/(2*a);x2=x1;    }if (d>0){//Normal Quadratic x1= (-b + sqrt(d))/(2*a);x2= (-b-+ sqrt(d))/(2*a);  }printf("\n The 1st root is %d\n2nd root is %di",x1,x2);return 0;} FORTRAN INTEGER A, B,C, X1, X2READ(*,*) A, B, CD= B*B -4*A*CIF (D .LT. 0) THENX1= -B/(2*A)X2 = SQRT(-D)ELSE IF (D .EQ. 0) THENX1 = -B/(2*A)X2 = X1ELSEX1 = (-B+SQRT(D))/(2*A)X2 = (-B-SQRT(D))/(2*A)END IFWRITE(*,10) X1, X210 FORMAT('1ST ROOT IS ',I2,' 2ND ROOT IS ',I2)END

In case if you try any of the solution above and it doesn't work, do not shake, are you sure you did not make any syntax Error while typing the code?
Are you sure you are using the right compiler for the correct code? For example, Visual Basic coding may not work with QBasic Compiler/interpreter.