Posts

Student Scope Resolution Operator Program in OOP/C++

Image
Student Scope Resolution Operator in OOP/C++ The :: (scope resolution) operator is used to get hidden names due to variable scopes so that you can still use them. The scope resolution operator can be used as both unary and binary. You can use the unary scope operator if a namespace scope or global scope name is hidden by a particular declaration of an equivalent name during a block or class. For example, if you have a global variable of name my_var and a local variable of name my_var, to access global my_var, you'll need to use the scope resolution operator. For Example: #include<iostream> using namespace std; class Person{ private: string Name; string Gender; int Age; char Exam; public: Person() { cout<<"Name : "; cin>>Name; cout<<"Gender : "; cin>>Gender; cout<<"Age : "; cin>>Age; } void setData() { cout<<"...

Classes in OOP (Object Oriented Programming)

Image
Classes  and Functions   in   OOP (Object Oriented Programming) In  object-oriented programming , a class is a template definition of the methods and variable s in a particular kind of object . Thus, an object is a specific instance of a class; it contains real values instead of variables. The class is one of the defining ideas of object-oriented programming. Among the important ideas about classes are: A class can have subclasses that can inherit all or some of the characteristics of the class. In relation to each subclass, the class becomes the superclass Subclasses can also define their own methods and variables that are not part of their superclass. The structure of a class and its subclasses is called the class hierarchy. A Simple Program defining Classes using OOP (Object Oriented Programming) is given below in which i have made a class named Student : #include<iostream> using namespace std; ...

If-Else program in C/C++

Image
If-Else program in C/C++ This program is made conditional by using If-Else statement. In this program, the user can enter a number and that is checked whether it is an even or odd. #include<iostream> #include<conio.h> using namespace std; int main() { int num; cout <<"enter a number:"; cin >> num; if ((num%2)==0)     {     cout << "even number"; } else { cout << "odd number"; } }

Nested If-Else program in C/C++

Image
Nested If-Else program in C/C++ This program is a "Nested If-Else" Program. In this program, we use a If-Else loop inside an If-Else loop. This program shows that whether you are a teenager, not a teenager, child or an old man. #include<iostream> #include<conio.h> using namespace std; int main() { int age; cout << "Enter your age:";     cin >> age;          if(age>=10 && age<=50)     {     if(age>=10 && age<=18)     {     cout << "you are a teenager"; } else { cout << "you are not a teenager"; } } else { if(age<10) { cout << "you are a child"; } else { cout << "you are an old man"; } } }

Switch statement in C/C++

Image
Switch statement in C/C++ #include<iostream> using namespace std; int main() { int number; cout << "1: Play game\n"; cout << "2: load game\n"; cout << "3: multiplayer game\n"; cout << "4: LAN netwrok connection\n"; cout << "5: exit\n"; cout << "enter any number:"; cin >> number; switch(number) { case 1: cout << "play game\n"; break; case 2: cout << "Load game\n"; break; case 3: cout << "Multiplayer game\n"; break; case 4: cout << "LAN network connection\n"; break; case 5: cout << "exit game\n"; break; default: cout << "wrong selection\n"; break; } }

While Loop Program in C/C++

Image
While Loop Program in C/C++ #include<iostream> using namespace std; int main() { int i=0; while (i<=10) { cout << i << '\t'; i++; } }

Nesting of For Loop in C/C++

Image
Nesting of For Loop in C/C++ This program is "Nesting of For Loop" and it prints out "*" in a parallel way in C/C++. The program is given below: #include<iostream> using namespace std; int main() { int i, j; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { cout << "*"; } cout << "\n"; } }

Continue/Break Statement in c/c++

Image
Continue/Break Statement in c/c++ This program is for the jumping of loops. The code for this program is given below: #include<iostream> #include<stdio.h> #include<conio.h> using namespace std; int main() { int i; for(i=1;i<=10;i++) { if(i==3) { continue; } if(i==8) { break; } cout << i << '\t'; } }

Do-While Program in C/C++ to print all even numbers from 1-50

Image
Do-While Program in C/C++ to print all even numbers from 1-50 This is a Do-While Program in C/C++ to print all even numbers from 1-50. #include<iostream> #include<conio.h> #include<math.h> using namespace std; int main() { int num=0; do{ cout << num << "\t"; num=num+2; } while(num<=50); }

Write a function that accepts a salary and returns the tax.

Image
Write a function that accepts a salary and returns the tax. This is a function that will accept a salary from the user and return the output tax according to the following rules: No Tax for first Rs.1000 5% for the second Rs.1000 4% for third Rs.1000 3% for the remain untaxed salary For Example: If the salary is Rs.4000, then the tax is Rs.120. The program is given below: #include<iostream> #include<math.h> using namespace std; int main() { int sal, Tax = 0; cout << "Enter  your salary: "; cin >> sal; while (sal !=0) { if(sal == 0) { break; } else if(sal >= 1000 && sal <=2000) { Tax += (sal*0.04); } else if(sal >= 2000 && sal <= 3000) { Tax += (sal*0.04); } else if(sal >= 3000) { Tax += (sal*0.03); } sal/= 1000; } cout << "Tax: " << Tax <...

If Statement Program in C/C++

Image
If Statement Program in C/C++ This Program is for " IF Statement ", which prints out numbers from 1-10. #include<iostream> using namespace std; int main() { int i; for( i=1;i<=10;i++) { cout << "no." << i <<endl; } }

The For Loop Program in C/C++

Image
The For Loop Program in C/C++ #include<iostream> using namespace std; int main() { int i; for(i=0;i<=5;i++) { cout << i << endl; } }

Hello World Program in C/C++ for Beginners

Image
C/C++ Program for Beginners #include<iostream> using namespace std; int main() {  cout << "hello world" << endl; }

Book-Shop Program using C++

Image
C++ Program for Book-Shop #include<iostream> #include<string.h> #include<stdlib.h> using namespace std; class book{ private: char *author,*title,*publisher; float *price; int *stock; public: book(){ author= new char[20]; title= new char[20]; publisher= new char[20] price= new float; stock= new int; } void feeddata(); void editdata(); void showdata(); int search(char[],char[]); void buybook(); }; void book::feeddata(){ cin.ignore(); cout << "\nEnter author name: "; cin.getline(author,20); cout << "Enter Title Name: "; cin.getline(title,20); cout << "Enter Price: ";    cin>>*price; cout << "Enter stock position: "; cin>>*stock; } void book::editdata(){ cout << "\nEnter author name: "; cin.getline(author,20); cout << "Enter Title Name: "; cin.getline(title,20);...

A small airline has just purchased a computer for its new automated reservations system. You’ve been asked to program the new system. You are to write a program to assign seats on each flight of the air line’s only plane (capacity: 10 seats).

Image
A small airline has just purchased a computer for its  new  automated  reservations system. You’ve  been  asked  to program the  new  system. You are to  write  a program to assign  seats  on  each flight  of  the air line ’s  only plane (capacity:  10  seats). #include<iostream> using namespace std; int option_select(); bool availibility_checking(int); void reserve_boarding(int); void next_flight(); int capacity][10] = {0} int main(){ int option; bool availibility = false; bool availibility_other = false; for(int x=0;x<12;x++){ //option select option = option_select(); //check seats availibility in selected section availibility = availibility_checking(option); if(availibility == 1){ //if there is available place print boarding pass reserve_boarding(option); } else //if there is no available place, check seats availability...