PHP – Entering Comments

There are two main types of PHP comments. The fi rst type is for commenting a single line or partial line. The comment starts with a // and ends at the end of the line. The second type of comment is a block comment. The block comment starts with a /* and ends with a…

PHP – Output in Browser

To create this very simple script, open your text editor once more and enter the following: <html> <head> <title>My PHP Example 1 </title> </head> <body> <?php echo “Hello!! Good Morning”; ?> </body> </html> Save this file as hello.php in your document root folder, and view the results in your browser by visiting http://localhost/hello.php Print current…

Classes and Objects

Define a class student with the following specification Private members of class student admno                        integer sname                        20 character math, science       float total                            float ctotal()                        a function to calculate eng + math + science with float return type. Public member function of class student Takedata()                   Function to accept values for admno, sname, eng, science and invoke ctotal()…

Function Overloading in C++

Function Overloading is an example of polymorphism feature. It is a feature in C++ where two or more functions can have the same name but different parameters. void test1(){ } int test1(int a) { } float test1(int a,float b){ } All three functions are overloaded functions because argument(s) passed to these functions are different. Overloaded…

Virtual Functions Question

Create three classes Person, Professor and Student. The class Person should have data members name and age. The classes Professor and Student should inherit from the class Person. The class Professor should have two integer members: publications and cur_id. There will be two member functions: getdata and putdata. The function getdata should get the input…

C Language

#include<stdio.h> /* Program to print Hello World */ int main() { printf(“Hello World”); return 0; } A C program basically consist of following parts:: Pre-processor Commands Comment Functions variables Statements and expressions Pre-processor Commands : First line of the program #include is a pre-processor commands.  Preprocessor directives are lines included in the code of programs preceded…

7. Floyd’s Triangle C Language

1 2 3 4 5 6 7 8 9 10 int main() { int n, i, c, a =1; printf(“Enter the number of rows :: \n”); scanf(“%d”,&n); for(i =1; i <= n; i++) { for(c =1; c <= i; c++) { printf("%d ",a); a++; } printf("\n"); } return0; }

7. Floyd’s Triangle C++

#include<iostream> using namespace std; int main() { int n, i, c, a =1; cout<<“Enter the number of rows :: “; cin>>n; for(i =1; i<= n; i++) { for(c =1; c<= i; c++) { cout<<a<<” “; a++; } cout<<endl; } return 0; }

Pyramid and Pattern in C Language

Pyramid and Pattern 1) * ** *** **** ***** #include<stdio.h> int main(){ int i, j,rows; printf(“Enter number of rows: “); scanf(“%d”,&rows); for(i=1;i<=4;i++) { for(j=1;j<=i;j++) { printf(“*”); } printf(“\n”); } return 0; } 2) 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 #include<stdio.h> int main(){ int i, j,rows; printf(“Enter…

Pyramid and Pattern in C++

1) * ** *** **** ***** #include<iostream> using namespace std; int main(){ int i, j,rows; cout<<“Enter number of rows: “; cin>>rows; for(i=1;i<=rows;i++) { for(j=1;j<=i;j++) { cout<<“*”; } cout<<“\n”; } return 0; } 2) 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 #include<iostream> using namespace std; int main(){ int…

9. Write a program to enter the numbers till the user wants and at the end it should display the count of positive, negative and zeros entered.

#include<iostream> using namespace std; int main() { int num, cpos=0, cneg=0, czero=0; char opt; do{ cout<<“Enter any num”; cin>>num; if(num==0) czero++; else if(num<0) cneg++; else cpos++; cout<<“Do you want to continue Y/N “; cin>>opt; }while(opt==’Y’|| opt==’y’); cout<<“Positive = “<<cpos<<endl; cout<<“Negative = “<<cneg<<endl; cout<<“Zero = “<<czero<<endl; } or #include<iostream> using namespace std; int main() { int…

8. Write a program to calculate HCF of Two given number.

#include<iostream> using namespace std; int main() { int i, num1, num2, min, hcf=1; cout<<“Enter any two numbers to find HCF: “; cin>>num1>>num2; // Find minimum between two numbers min = (num1<num2) ? num1 : num2; for(i=1; i<=min; i++) { if(num1%i==0 && num2%i==0) { hcf = i; } } cout<<“HCF = “<<hcf; return 0; }