C++ has no generic graphics capability whatsoever. Graphics are platform-specific, and every C++ implementation provides its own API and libraries specific to the intended platform.
For instance, the following user-defined Visual C++ MFC function will centre any text (t) within a given rectangle (r) relative to the given device context (dc):
void centre_text(CString& t, CRect& r, CDC& dc)
{
CRect b; // bounding rectangle.
// Calculate the bounding rectangle of the text:
dc.DrawText( t, b, DT_CALCRECT );
// Position the bounding rectangle in the centre of the given rectangle:
b.MoveToXY(
r.left + (( r.Width() - b.Width() ) / 2 ),
r.top + (( r.Height() - b.Height() ) / 2 ));
// Draw the text in the bounding rectangle:
dc.DrawText( t, b, DT_NOCLIP );
}
Note that the above code is non-generic and therefore cannot be ported to other platforms. It will only work in Visual C++ MFC applications. However, the principal will be largely the same on other platforms: calculate the bounding rectangle, move it to the centre of the intended rectangle and then print the text in the bounding rectangle.
Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.
It means that python will print(or write out) a value you input.
#include<stdio.h> Void main() { int a,b; printf("Enter a Number: "); // for print function as an out-put scanf("%d",&a); //for scan function as in input /* Here we can use print function once again as: */ a=a++; printf("%d",a); }
input number print number + 1
input price calc tip = price*0.15 print tip
Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.
Write a function that print a triangle of stars.
It means that python will print(or write out) a value you input.
#include<stdio.h> Void main() { int a,b; printf("Enter a Number: "); // for print function as an out-put scanf("%d",&a); //for scan function as in input /* Here we can use print function once again as: */ a=a++; printf("%d",a); }
Center is at (Xc, Yc ). Radius = R. ======================================= Print "Input the coordinates of point 'P', separated by a comma." Input A, B D = (Xc - A)2 + (Yc - B)2 If D < R2 then print "'P' is inside the circle." If D = R2 then print "'P' is on the circle." If D > R2 then print "'P' is outside the circle." by arup nandy
(ab)*b
USING STRING LITERAL VALUES TO ADD 2 NUMBERS If you just want to show the outcome of two numbers you have: PRINT 4 + 5 This will print '9' the answer to 4 + 5. If you want to show the addition: PRINT "4 + 5 = "; 4 + 5 This will show the question and then calculate the answer. If you want the user to input numbers to add, use variables and then add them the same way. ====== COLLECTING USER INPUT FROM THE KEYBOARD/USING NUMERIC VARIABLES In the following example, the end user can get to interact with the program by typing in their numbers at the keyboard; then, pressing the [Enter] key. CLS PRINT "PROGRAM: Add 2 numbers" PRINT INPUT "Enter the 1st number: ", number1 INPUT "Enter the 2nd number: ", number2 PRINT sumTotal=number1+number2 PRINT "The sum total is: "; sumTotal PRINT INPUT "Again, Y/N"; yesNo$ IF UCASE$(LEFT$(yesNo$,1))="Y" THEN RUN END ====== CREATE FUNCTION/THEN, MAKE A FUNCTION CALL TO ADD 2 NUMBERS Another way to write this program is to create a function/then, make a function call... '*** PROGRAM: Add 2 numbers... '*** Variable declaration list... number1=7 '...initialise numeric variable 1 number2=3 '...initialise numeric variable 2 '*** Main program... CLS '...(CL)ear the (S)creen PRINT add(number1,number2) '...make function call/passing in 2 numbers to add END '...END of program/halt program code execution '*** Function(s)... FUNCTION add(num1,num2) '...this line marks the start of the Function add=num1+num2 '...this line returns the sum total of the 2 numbers END FUNCTION '...this line marks the end of the Function
input number print number + 1
input price calc tip = price*0.15 print tip
input number for loop = 1 to 3 inclusive print number end for
"print" will output a value onto the screen for a user to see. "input" or "raw_input" gets a user's input.
PRINT "Give me the rectangle's length.": Input L PRINT "Give me the rectangle's width.": Input W PRINT "The rectangle's area is "; L x W PRINT "The rectangle's perimeter is "; 2 x (L + W) PRINT "You've been a great audience. I'm here til Thursday. Don't forget to tip your waiter. Have a nice day."