30/03/2016

Variable Declaration and Initialization in Java
Problem:- Variable declaration and initialization in java. How to initialize and declare variables in Java or declaration of variables in java or variable initialization in java. Please read all rules for Variable Declaration and Initialization carefully cause Java is a case-sensitive language so one mistake can be the cause of hundreds of error.

Rule for Variable Declaration And Initialization


1. Import All Necessary Header File Or Library Or Package What Ever You Called them.

2. Class Name Should Contain Only Alphabet ( Upper & Lower Case ) Or _ ( Underscore )

3. Class Name And Java Program Name Should Be Shame Name Ex: Class hello And When You Save The Program It Should Be hello.java

4. Use Best Editor For Write A Java Program Instead Of NOTEPAD You Can Use NOTEPAD++ or SUBLIME TEXT

5. If You Need Any Help Our Expert Always With You Here Your Java Expert Is Prashant Chaturvedi Sir.

Variable Declaration and Initialization


data type variable name;

variable name=value;

int empid;!

empid=112233

System.out.println(empid);

output 112233


Variable Declaration and Initialization in Java


class Program1
{
 public static void main(String[] args)
 {
 System.out.println("Program Started"); // Variable Declaration
 int empid;
 double empsalary;
 char empgrade; // Variable Initlization
 empid=123456;
 empsalary=50000.25;
 empgrade='z';

 System.out.println("Employee ID is "+empid);
 System.out.println("Employee Salary is "+empsalary);
 System.out.println("Employee ID is "+empgrade);
 System.out.println("Program Ended");
 }
}

Output:-

Variable Declaration and Initialization in Java

You May Also See


1. HOW TO PRINT DIFFERENT VALUE IN JAVA

2. Java Program To Find Area And Circumference Of Circle

3. Java Program To Print ASCII Value Of Character

4. Java Program To Find Area Of Triangle

5. Java Program to Convert a person's name in Abbreviated
How to Concatenation in Java Using + Operator
Problem:- How to Concatenation in Java Using + Operator or concatenation in java example java program for concatenating string or java program for print multiple values in one statement. String Concatenation in Java. using + operator.

Check This:- HackerRank solution for C++ Domain.


Explanation:- Concatenation means adding two or more values, Java we have plus ( + ) operator for Concatenation two same and different type of values. The need of Concatenation and why we use?. The simple answer is when we need to add the values and printing the multiple the values in a single line we use Concatenation. Below is the example of Concatenation so you can understand very well.

Example:- Suppose you want to print the output of Factorial of number 5 or any other number if you don't use Concatenation then you need multiple print statement for printing the output of Factorial check the below two examples for printing the output of Factorial. factorial of 5 is 120.

Without using Concatenation


System.out.println("Factorial of  ");
System.out.println(number);
System.out.println(" is ");
System.out.println( fact );

So without using Concatenation your output will be 

Factorial of
5
is
120

Using Concatenation


System.out.println( "Factorial of  " + number + " is " + fact );

Now the output of the program will be 

Factorial of  5 is 120

Here number and fact are variable. You notice that both the output of the program.

How to Concatenation in Java Using + Operator


class Program3
{
public static void main(String[] args)
{
System.out.println(20+20);
System.out.println("java "+"developer");
System.out.println("Number is"+20);
System.out.println("Number is"+20+20);
System.out.println("Number is"+(20+20));
System.out.println("20+ is the Number");
System.out.println(20+20+"is the Number");
}
}


Output:-

How to Concatenation in Java Using + Operator

You May Also See


1. Java Program To Print ASCII Value Of Character

2. Java Program To Find Area Of Triangle

3. Java Program to Convert a person's name in Abbreviated

4. Java Program For Calculate A Simple Interest

5. Java Program For Find The Gross Salary Of An Employee
How to Print Different Type of Values in Java
Problem:- How to Print Different Type of Values in Java or Displaying Information using print() and println() Methods or Using generic methods to print array of different types or Data types in Java Learn about integer character float double long etc or Returning Multiple values in Java or how to print different type of values in java. java program for printing an integer, float, string, character and boolean values in java. string printing in java.

Check This:- HackerRank solution for C++ Domain.


Explanation:- As we know that we have different types of variable in Java such as Integer character float double long string and boolean, now in this problem we have to print these different type of variable. We also know that each variable has a different type of printing pattern like when we have to print character we use single quotes ( ' ' )and for string, we use double quotes ( " " ).


Also check- Geeksforgeeks solution for School Domain in C++.

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.

How to Print Different Type of Values in Java


class Program2
{
public static void main(String[] args)
{
System.out.println(123456789);
System.out.println(235.254);
System.out.println('P');
System.out.println(true);
System.out.println("Prashant");
}
}



Output:-

How to Print Different Type of Values in Java

You May Also See


1. Java Program To Find Area And Circumference Of Circle

2. Java Program To Print ASCII Value Of Character

3. Java Program To Find Area Of Triangle

4. Java Program to Convert a person's name in Abbreviated

5. Java Program For Calculate A Simple Interest
How To Print Message " HELLO JAVA " In Java
Hello Reader This Is A First Program In Java To Print A Given Massage. Here Remember One Thing Java Is Very Case Sensitive Language So Be Careful. This is a simple example or this is the first program in Java or we can say with the help of this program we learn about printing a string on display while printing a message on the screen below are some useful tips read all tips.


Some Useful Tips


1. Import All Necessary Header File Or Library Or Package What Ever You Called them.

2.Class Name Should Contain Only Alphabet ( Upper & Lower Case ) Or _ ( Underscore )

3.Class Name And Java Program Name Should Be Shame Name Ex: Class hello And When You Save The Program It Should Be hello.java

4.Use Best Editor For Write A Java Program Instead Of NOTEPAD You Can Use NOTEPAD++ or SUBLIME TEXT

5.If You Need Any Help Our Expert Always With You Here Your Java Expert Is Prashant Chaturvedi Sir


Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.


How To Print Message " HELLO JAVA " In Java




import java.util.*;

class hello
{
    public static void main(String[] args)
    {
    System.out.println("HELLO JAVA");
    }
}

Output:-

28/03/2016

C++ Program to Sort Elements in Lexicographical Order (Dictionary Order) Using For Loop
#include<iostream>
#include <cstring>
using namespace std;
int main()
{
    int i,j,n;
    char str[10][50],temp[50];
 
    cout << "Enter The No. Of Words: " << endl;
    cin>>n;
    for(i=0;i<n;++i)
        cin.getline(str[i], 50);
     
    for(i=0;i<n-1;++i)
       for(j=i+1;j<n ;++j)
  {
          if(strcmp(str[i],str[j])>0)
          {
            strcpy(temp,str[i]);
            strcpy(str[i],str[j]);
            strcpy(str[j],temp);
          }
    }
    cout << "In lexicographical order: " << endl;
    for(i=0;i<n;++i){
       cout << str[i] << endl;
    }
return 0;
}

Output:-

www.programmingwithbasics.com

C++ Program to Calculate Standard Deviation Using Function
#include <iostream>
#include <cmath>
using namespace std;
float standard_deviation(float data[], int n);
int main()
{
    int n, i;
    float data[100];
    cout << "Enter number of data: ";
    cin >> n;
    while (n>100 || n<=0)
    {
        cout << "Error! number should in range of (1 to 100)." << endl;
        cout << "Enter the number of data again: ";
        cin >> n;
    }
    cout << "Enter elements: " << endl;
    for(i=0; i<n; ++i)
        cin >> data[i];
    cout << endl;
    cout << "Standard Deviation = " << standard_deviation(data,n);
    return 0;
}
float standard_deviation(float data[], int n)
{
    float mean=0.0, sum_deviation=0.0;
    int i;
    for(i=0; i<n;++i)
    {
        mean+=data[i];
    }
    mean=mean/n;
    for(i=0; i<n;++i)
    sum_deviation+=(data[i]-mean)*(data[i]-mean);
    return sqrt(sum_deviation/n);          
}

Output:-

www.programmingwithbasics.com

27/03/2016

Nth Term of Fibonacci Series in C++ | Nth Term
Nth Term of Fibonacci Series in C++. In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterized by the fact that every number after the first two is the sum of the two preceding ones.

Fibonacci Series: 1 ,1 ,2 ,3 ,5 ,8 ,13 ,21 ,34.

Often, especially in modern usage, the sequence is extended by one more initial term.

Fibonacci Series: 0 ,1 ,1 ,2 ,3 ,5 ,8 ,13 ,21 ,34.

Nth Term of Fibonacci Series in C++


#include <iostream>
using namespace std;
int main()
{
	int range, first = 0, second = 1, fibonicci;
	cout << "Enter the Range for Terms of Fibonacci Sequence " << endl;
	cin >> range;
	cout << "Fibonacci Series upto " << range << " Terms  " << endl << endl;
	for (int c = 0; c < range; c++)
	{
		if (c <= 1)
			fibonicci = c;
		else
		{
			fibonicci = first + second;
			first = second;
			second = fibonicci;
		}

		cout << fibonicci << "  ";
	}

	return 0;
}

Nth Term of Fibonacci Series Output


Nth Term of Fibonacci Series Output

Similar to the Nth Term of Fibonacci Series


24/03/2016

C Program to Check Prime or Armstrong Number Using Function
#include <stdio.h>

int prime(int n);
int armstrong(int n);

int main()
{
    char c;
    int n,temp=0;
    printf("Eneter a positive integer: ");
    scanf("%d",&n);
    printf("Enter P to check prime and  A to check Armstrong number: ");
    c=getche();
    if (c=='p' || c=='P')
    {
        temp=prime(n);
        if(temp==1)
           printf("\n%d is a prime number.", n);
        else
           printf("\n%d is not a prime number.", n);
    }
    if (c=='a' || c=='A')
    {
        temp=armstrong(n);
        if(temp==1)
           printf("\n%d is an Armstrong number.", n);
        else
           printf("\n%d is not an Armstrong number.",n);
    }
    return 0;
}

int prime(int n)
{
    int i, flag=1;
    for(i=2; i<=n/2; ++i)
    {
       if(n%i==0)
       {
          flag=0;
          break;
       }
    }
    return flag;
}

int armstrong(int n)
{
    int num=0, temp, flag=0;
    temp=n;
    while(n!=0)
    {
        num+=(n%10)*(n%10)*(n%10);
        n/=10;
    }
    if (num==temp)
       flag=1;
    return flag;
}

Output:-

www.programmingwithbasics.com

C Program to Display Prime Numbers Between Intervals Using Using Function
#include<stdio.h>

int check_prime(int num);

int main()
{
   int n1,n2,i,flag;
   printf("Enter two numbers(intervals): ");
   scanf("%d %d",&n1, &n2);
   printf("Prime numbers between %d and %d are: ", n1, n2);
   for(i=n1+1;i<n2;++i)
   {
      flag=check_prime(i);
      if(flag==0)
         printf("%d ",i);
   }
   return 0;
}

int check_prime(int num) /* User-defined function to check prime number*/
{
   int j,flag=0;
   for(j=2;j<=num/2;++j){
        if(num%j==0){
            flag=1;
            break;
        }
   }
   return flag;
}

Output:-

www.programmingwithbasics.com

C Program For Convert Binary to Octal and Vice Versa Using Function
#include <stdio.h>
#include <math.h>
int binary_octal(int n);
int octal_binary(int n);
int main()
{
    int n;
    char c;
    printf("Instructions:\n");
    printf("1. Enter alphabet 'o' to convert binary to octal.\n");
    printf("2. Enter alphabet 'b' to convert octal to binary.\n");
    scanf("%c",&c);
    if ( c=='o' || c=='O')
    {
        printf("Enter a binary number: ");
        scanf("%d",&n);
        printf("%d in binary = %d in octal", n, binary_octal(n));
    }
    if ( c=='b' || c=='B')
    {
        printf("Enter a octal number: ");
        scanf("%d",&n);
        printf("%d in octal = %d in binary",n, octal_binary(n));
    }
    return 0;
}
int binary_octal(int n)  /* Function to convert binary to octal. */
{
    int octal=0, decimal=0, i=0;
    while(n!=0)
    {
        decimal+=(n%10)*pow(2,i);
        ++i;
        n/=10;
    }

/*At this point, the decimal variable contains corresponding decimal value of binary number. */

    i=1;
    while (decimal!=0)
    {
        octal+=(decimal%8)*i;
        decimal/=8;
        i*=10;
    }
    return octal;
}
int octal_binary(int n)  /* Function to convert octal to binary.*/
{
    int decimal=0, binary=0, i=0;
    while (n!=0)
    {
        decimal+=(n%10)*pow(8,i);
        ++i;
        n/=10;
    }
/* At this point, the decimal variable contains corresponding decimal value of that octal number. */
    i=1;
    while(decimal!=0)
    {
        binary+=(decimal%2)*i;
        decimal/=2;
        i*=10;
    }
    return binary;
}

Output:-

www.programmingwithbasics.com

www.programmingwithbasics.com

C Program For Convert Octal Number to Decimal and Vice Versa Using Function
#include <stdio.h>
#include <math.h>
int decimal_octal(int n);
int octal_deciaml(int n);
int main()
{
   int n;
   char c;
   printf("Instructions:\n");
   printf("1. Enter alphabet 'o' to convert decimal to octal.\n");
   printf("2. Enter alphabet 'd' to convert octal to decimal.\n");
   scanf("%c",&c);
   if (c =='d' || c == 'D')
   {
       printf("Enter an octal number: ");
       scanf("%d", &n);
       printf("%d in octal = %d in decimal", n, octal_decimal(n));
   }
   if (c =='o' || c == 'O')
   {
       printf("Enter a decimal number: ");
       scanf("%d", &n);
       printf("%d in decimal = %d in octal", n, decimal_octal(n));
   }
   return 0;
}

int decimal_octal(int n) /* Function to convert decimal to octal */
{
    int rem, i=1, octal=0;
    while (n!=0)
    {
        rem=n%8;
        n/=8;
        octal+=rem*i;
        i*=10;
    }
    return octal;
}

int octal_decimal(int n) /* Function to convert octal to decimal */
{
    int decimal=0, i=0, rem;
    while (n!=0)
    {
        rem = n%10;
        n/=10;
        decimal += rem*pow(8,i);
        ++i;
    }
    return decimal;
}

Output:-

www.programmingwithbasics.com

www.programmingwithbasics.com

C Program For Convert Binary Number to Decimal or Decimal Number to Binary Using Function
#include <stdio.h>
#include <math.h>
int bin_to_dec(int n);
int dec_to_bin(int n);
int main()
{
   int n;
   char c;
   printf("Instructions:\n");
   printf("1. Enter alphabet 'd' to convert binary to decimal.\n");
   printf("2. Enter alphabet 'b' to convert decimal to binary.\n");
   scanf("%c",&c);
   if (c =='d' || c == 'D')
   {
       printf("Enter a binary number: ");
       scanf("%d", &n);
       printf("%d in binary = %d in decimal", n, bin_to_dec(n));
   }
   if (c =='b' || c == 'B')
   {
       printf("Enter a decimal number: ");
       scanf("%d", &n);
       printf("%d in decimal = %d in binary", n, dec_to_bin(n));
   }
   return 0;
}

int dec_to_bin(int n)  /* Function to convert decimal to binary.*/
{
    int rem, i=1, binary=0;
    while (n!=0)
    {
        rem=n%2;
        n/=2;
        binary+=rem*i;
        i*=10;
    }
    return binary;
}

int bin_to_dec(int n) /* Function to convert binary to decimal.*/

{
    int decimal=0, i=0, rem;
    while (n!=0)
    {
        rem = n%10;
        n/=10;
        decimal += rem*pow(2,i);
        ++i;
    }
    return decimal;
}

Output:-

programmingwithbasics.com

22/03/2016

C Program to Count Vowels, Consonants, Digits and Spaces in Given String
Problem:- C program to count the number of vowels, consonants and so on or C Program to Count Vowels, Consonants, Digits and Spaces in Given String or Find Number of Vowels, Consonants, Digits and White Space Characters or C Programming Notes: Counting vowels, consonants, digits, special character or C Program to Count words, vowels, letters, digits, spaces, Characters or Program to Find the Number of Vowels, Consonants, Digits and Whitespace in a String in C or Count the number of vowels, consonants, digits etc or C program to Count Vowels, Consonants, Digits, Spaces from String.

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.

Explanation:- for Counting the vowels, constant, digits and white space in c is very simple we have to just put an if else condition for each query. As we can see that there are 4 query(vowels, constant, digits and white space) so we have 4 counter separate for each of them and for finding the vowels in a string or sentence if simple just put the 5 character in lower and upper case and compare with the input string if any character matches then increase the vowels counter and same for constant and digit, for a single iteration of a string any one of the counters should be increased. last counter for white space, and at the end print the all 4 counters values, total counter values is equal to the size of the string.


Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page.


Solution:-

#include<stdio.h>

int main()
{
/*Visit - www.programmingwithbasics.com*/
   
    printf("=====================================");
    printf("\nVisit - www.programmingwithbasics.com");
    printf("\n=====================================");
    
    char line[1000];
    int i, v, c, ch, d, s, o;
 
    o = v = c = ch = d = s = 0;
    printf("\n\nEnter a Line of String: \n\n");
 
    gets(line);
    
    for(i=0;line[i]!='\0';++i)
    {
        if(line[i]=='a' || line[i]=='e' || line[i]=='i' || line[i]=='o' || line[i]=='u' || line[i]=='A' || line[i]=='E' || line[i]=='I' || line[i]=='O' || line[i]=='U')
            ++v;
        else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
            ++c;
        else if(line[i]>='0'&&c<='9')
            ++d;
        else if (line[i]==' ')
            ++s;
    }
    printf("\n\nOutput Is Below\n\n");

    printf("\n\nTotal Number of Vowels Are: %d",v);
    printf("\nTotal Number of Consonants Are: %d",c);
    printf("\nTotal Number of Digits Are: %d",d);
    printf("\nTotal Number of White spaces Are: %d\n\n",s);
    return 0;
}

Output:-

C Program to Count Vowels, Consonants, Digits and Spaces in Given String


You May Also See


1. C Program For Remove All Vowels From A String




C++ Program to Display String From Backward
Problem:- C++ Program to Display String From Backward or Write A C++ Program To Display String From Backward or C++ program to Reverse a String or C++ Program to Reverse String or Display A String Backwards in c++ or c++ - Printing input string words in reverse order or Loop to print string backward or printing a string backwards or Displaying an input backwards or How can I print a string backwards? or Different methods to reverse a string in C/C++ or Write a program to reverse an array or string.

Explanation:- Reading a string form backward is similar to reverse the string here I use a For Loop for finding the length of the string or we can use string.length() function depend upon your choice. After calculating the size of the string with the second For Loop printing the string from last-1 index to greater or equal to zero indexes. this is a simple way for reading a string from backward or we can use a simple inbuilt function for made program easier but using an inbuilt library function for beginners is not a good practice. First beginners know how they can build a logic and implement the existing problem after that for saving the time and space beginners can use an inbuilt library function.


Solution:-

#include<iostream>
using namespace std;

int main()
{
/*Visit - www.programmingwithbasics.com*/
   
    printf("=====================================");
    printf("\nVisit - www.programmingwithbasics.com");
    printf("\n=====================================");

    char str[80];
  int l, i;
    
cout<<"\n\nEnter a String: ";
    cin.getline(str, 80);
    for(l = 0; str[l] != '\0'; l++);// finding the length of a string
    
    cout<<"\n\nString From Backward is below\n\n";
    
    for(i = l - 1; i >= 0; i--)
    {
        cout << str[i];
    }   
    return 0;
}

Output:-

C++ Program to Display String From Backward



You May Also See


1. C++Program To Calculate Factorial Of A Given Number Using Loop

2. C++ Program To Print A Message Multiple Times Using Loop

3. C++ Program To Print A Table Of Given Number Using Loop

4. C Program For Calculator Using Switch Case

5. Java Program To Check Number Is Positive Or Negative

6. Java Program To Find Character Is Vowel Or Not

7. C Program For Find A Grade Of Given Marks Using Switch Case

8. C Program For Finding Radius Circumference Using Switch Case

9.C Program For Remove All Vowels From A String Using Switch Case

10. C++ Program To Print A Reverse Order Of Any Number Using Loop

21/03/2016

C++ Program For School Management System ( SMS Project ) With source Code
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<fstream.h>
#include<dos.h>
using namespace std;

struct marks_criteria
{
int sc_min,com_min,arts_min, seat_sc, seat_com, seat_arts;
} crit;

struct administrator
{
char user_name[10];
char password[10];
}admin;

struct  student
{
char name[20];
int regno,m_eng,m_math,m_sc,m_sst,m_lang;
int pref_code, stream;
// Sc=1, Com=2; Arts=3;


public:
void new_file();
void input_data();
void allot_stream();
int get_stream();
void display();
int show_per()
{
return((m_eng+m_math+m_sc+m_sst+m_lang)/5);
}

};
void welcome();
void menu();
int verify_password();
void assign_user();
void clear();
void input_criteria();
void read_criteria();
void read_student();
void create_eligible_sc();
void create_eligible_com();
void create_eligible_arts();
void read_eligible_sc();
void read_eligible_com();
void read_eligible_arts();
char * stream_name(int strm);
void select_list( char *in_file, char *out_file);
void thanks();

student s;
 main()
{


//     clrscr();
     welcome();

    // cout<<"welcome";
fstream fin, fout;
fstream fsc, fcom, farts;
int opt=1, ch;

while(opt!=8)
{
// clrscr();


 clear();
cout<<"\n\t======================  MAIN   MENU  =======================\n";
cout<<"\n\t[1] CREATE / MODIFY  ADMISSION  CRITERIA(Administrator only)";
cout<<"\n\n\t[2] ENTER STUDENT'S DATA ";
cout<<"\n\n\t[3] ALLOTMENT OF  STREAM";
cout<<"\n\n\t[4] DISPLAY CRITERIA FOR SELECTION";
cout<<"\n\n\t[5] DISPLAY ALLOTMENT OF  STUDENT'S STREAM";
cout<<"\n\n\t[6] DISPLAY ALL  STUDENT'S REGISTERED";
cout<<"\n\n\t[7] CREATE / DISPLAY MERIT LIST";
cout<<"\n\n\t[8] QUIT";
cout<<"\n\t=============================================================\n";
cout<<"\n\n\t\tEnter your  choice : ";
cin>>opt;
switch(opt)
{
case 1:
int p;
assign_user();
p=verify_password();
if(p==0)
{

input_criteria();
}
else
{
cout<<"\n\tU R Not a Valid User.";
cout<<"\n\tU Dont have the Authority to Create Question Bank. Bye\n\n";
}
break;

case 2:
      int option;
      //clrscr();
      cout<<"\nWhat do u want --\n\n\n\n\n\tCreate  a new student information  file or Append to the existing file?\n\n\t(press 1 for new creation and 2 for appending)";
      cin>>option;
      if(option==1)
      {
 s.new_file();
 }
 else
 {
s.input_data();
}
break;

case 3:
//clrscr();
// read_student();
fin.open("student" ,ios::in|ios::out);

fsc.open("elig_sc",ios::out);
fcom.open("eligcom",ios::out);
farts.open("eligart",ios::out);

while(fin.read((char*)& s,sizeof(s)))
{


s.allot_stream();

s.get_stream();

//if(s.get_stream()==0)
      cout<<"\nApplication Rejected. Not Eligible\n";

if(s.get_stream()==1)
fsc.write((char*)& s,sizeof(s));


if(s.get_stream()==2)
fcom.write((char*)& s,sizeof(s));

if(s.get_stream()==3)
farts.write((char*)& s,sizeof(s));



}
fin.close();
fsc.close();
fcom.close();
farts.close();
cout<<"\n*******************************************";
cout<<"\n\n\tSTREAM ALLOCATION DONE.";
cout<<"\n*******************************************";
break;
case 4:
read_criteria();
// clear();
cout<<"\n Sc : "<<crit.sc_min;
cout<<"\n Com : "<<crit.com_min;
cout<<"\n Sc : "<<crit.arts_min;


break;

case 5:

cout<<"\n Enter 1 for Sc, 2 for Com, 3 for Arts  :  ";
cin>>ch;
if (ch==1)
read_eligible_sc();

if (ch==2)
read_eligible_com();
if (ch==3)
read_eligible_arts();

break;
case 6:         //clrscr() ;
read_student();
break;
case 7:
{
char c;
int k=1;
cout<<"\n****************************************";
cout<<"\n****************************************";
cout<<"\n    M E R I T  L I S T";
cout<<"\n    ==================";
cout<<"\n\tEnter 1 for MERIT LIST SCIENCE ";
cout<<"\n\tEnter 2 for MERIT LIST COMMERCE ";
cout<<"\n\tEnter 3 for MERIT LIST ARTS \t";
cout<<"\n****************************************";
cout<<"\n****************************************"; cin>>k;
if (k==1)
{
select_list("elig_sc","sell_sc");
fin.open("sell_sc",ios::in);
}
if (k==2)
{
select_list("eligcom","sellcom");
fin.open("sellcom",ios::in);
}
if (k==3)
{
select_list("eligart","sellart");
fin.open("sellart",ios::in);
}
if(k>=1 && k<=3)
{
while(fin.read((char*)& s,sizeof(s)))
{
s.display();

cout<<"\n\t Continue (y/n)?";
cin>>c;
if(c=='n')
break;

}

}
fin.close();
fin.close();
fin.close();
break;
}
case 8:
  thanks();
   // cout<<"\nTHANKS BYE ";
       // exit(0);
break;
}

}

 }

// END OF WHILE


void assign_user()
{

strcpy(admin.user_name, "rimi");
strcpy(admin.password, "rimi");


}
int verify_password()
{
char u_name[10];
char u_pwd[10],temp[2];
int x=1;
cout<<"\n\n   Enter user name : ";
cin>>u_name;
cout<<"\n\n   Enter Password : ";
cin>>u_pwd;
x=strcmp(admin.user_name,u_name);
if (x==0)
{
x=strcmp(admin.password,u_pwd);

}
cin.getline(temp,2);
return(x);

}
void student::allot_stream()
{
int per=(m_eng+m_math+m_sc+m_sst+m_lang)/5;
read_criteria();

switch(pref_code)
{
case 1:
if(per>=crit.sc_min)
stream=pref_code;
else
stream=0;

break;
case 2:
if(per>=crit.com_min)
stream=pref_code;
else
stream=0;
break;
case 3:
if(per>=crit.arts_min)
stream=pref_code;
else
stream=0;
break;
}
}

int student::get_stream()
{
return(stream);
}


void input_criteria()
{
fstream fout;
fout.open("criteria" ,ios::in|ios::out);
cout<<"\nEnter  the  required marks for SCIENCE stream(in percentage)";
cin>>crit.sc_min;
cout<<"\nEnter  No. of Seats for SCIENCE stream";
cin>>crit.seat_sc;
cout<<"\nEnter  the  required marks for COMMERCE stream(in percentage)";
cin>>crit.com_min;
cout<<"\nEnter  No. of Seats for COMMERCE stream";
cin>>crit.seat_com;
cout<<"\nEnter  the  required marks for ARTS stream(in percentage)";
cin>>crit.arts_min;
cout<<"\nEnter  No. of Seats for ARTS stream";
cin>>crit.seat_arts;
fout.write((char*)& crit,sizeof(crit));
fout.close();
}

void read_criteria()
{
fstream fin;
fin.open("criteria" ,ios::in);
fin.read((char*)& crit,sizeof(crit));
fin.close();

}

void student::input_data()
{     //clrscr();
fstream fin;
fin.open("student",ios::app|ios::out);
char t[2], ans;
while(1)
{
cout<<"\nEnter  the  name of the  student  :  ";
cin>>name;
cout<<"\n\nEnter  the roll of the  student  :  ";
cin>>regno;
cout<<"\n\nEnter  marks in eng  :  ";
cin>>m_eng;
cout<<"\n\nEnter  marks in math  :  ";
cin>>m_math;
cout<<"\n\nEnter  marks in science  :  ";
cin>>m_sc;
cout<<"\n\nEnter  marks in sst  :  ";
cin>>m_sst;
cout<<"\n\nEnter  marks in language  :  ";
cin>>m_lang;
cout<<"==================STREAM  PREFERED?================ \n";
cout<<"\t"<<"[1] for SCIENCE\n";
cout<<"\t"<<"[2] for COMMERCE\n";
cout<<"\t"<<"[3] for ARTS ";
cout<<"\n================================================= \n\tENTER PREFERENCE CODE : ";
cin>>pref_code;
stream=-1;
fin.write((char*)&s,sizeof(s));
cin.getline(t,2);
cout<<"\n\tEnter More Student ? (y/n)";
cin>>ans;
if (ans=='n')
break;
}
fin.close();
}
void student::new_file()
{     //clrscr();
fstream fin;
fin.open("student",ios::out);
char t[2], ans;
while(1)
{
cout<<"\nEnter  the  name of the  student  :  ";
gets(name);
cout<<"\n\nEnter  the roll of the  student  :  ";
cin>>regno;
cout<<"\n\nEnter  marks in eng  :  ";
cin>>m_eng;
cout<<"\n\nEnter  marks in math  :  ";
cin>>m_math;
cout<<"\n\nEnter  marks in science  :  ";
cin>>m_sc;
cout<<"\n\nEnter  marks in sst  :  ";
cin>>m_sst;
cout<<"\n\nEnter  marks in language  :  ";
cin>>m_lang;
cout<<"==================STREAM  PREFERED?================ \n";
cout<<"\t"<<"[1] for SCIENCE\n";
cout<<"\t"<<"[2] for COMMERCE\n";
cout<<"\t"<<"[3] for ARTS ";
cout<<"\n================================================= \n\tENTER PREFERENCE CODE : ";
cin>>pref_code;
stream=-1;
fin.write((char*)&s,sizeof(s));
cin.getline(t,2);
cout<<"\n\tEnter More Student ? (y/n)";
cin>>ans;
if (ans=='n')
break;
}
fin.close();
}
void student::display()
{

cout<<"\n============================================\n";
cout<<"\n\tNAME : "<<name;
cout<<"\n\tREGISTRATION NO. : "<<regno;
cout<<"\n\tPERCENTAGE OF MARKS : "<<( (m_eng+m_math+m_sc+m_sst+m_lang)/5)<<"%";
cout<<"\n\tSTREAM APPLIED FOR :  "<<stream_name(pref_code);
       // cout<<"\n\tSTREAM ALLOTED : "<<stream_name(stream);
cout<<"\n============================================\n";

}

void read_student()
{
fstream fin;
char c;
fin.open("student" ,ios::in);
while(fin.read((char*)& s,sizeof(s)))
{
s.display();
cout<<"\n\tPress any no. to continue ";
cin>>c;
cout<<"\n";
}
fin.close();

}



void read_eligible_sc()
{
char ans;
fstream fout;
fout.open("elig_sc",ios::in);
fout.seekg(0);
while(fout.read((char*)& s,sizeof(s)))
{
s.display();
cout<<"\n\t Continue (y/n)? ";

cin>>ans;

if (ans=='n')
break;

}
fout.close();

}

void read_eligible_com()
{
char ans;
fstream fout;
fout.open("eligcom",ios::in);

while(fout.read((char*)& s,sizeof(s)))
{
s.display();
cout<<"\n\t Continue (y/n)? ";

cin>>ans;

if (ans=='n')
break;

}
fout.close();
}



void read_eligible_arts()
{
char ans;
fstream fout;
fout.open("eligart",ios::in);

while(fout.read((char*)& s,sizeof(s)))
{
s.display();
cout<<"\n\t Continue (y/n)? ";

cin>>ans;

if (ans=='n')
break;

}
fout.close();
}
void clear()
{
// for(int i=1;i< =24;i++)
// cout<<"\n";
}
char * stream_name(int strm)
{
switch(strm)
{
case -1:
return("Not assigned");
   // break;
case 0:
return("Nill");
    // break;
case 1:
return("Science");
 // break;
case 2:
return("Commerce");
    // break;
case 3:
return("Arts");
   // break;
   default:
return("None");
}
}
void select_list( char *in_file, char *out_file)
{
fstream sel, fin;
int n=0, i,j;
student sl[100], t;


sel.open(out_file, ios::out);
fin.open(in_file,ios::in);

while(fin.read((char*)& sl[n],sizeof(s)))
{
n++;

}
cout<<"\nNo of Eligible Students  = "<<n<<"\n";
for(i=0;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
if ( sl[i].show_per()<sl[j].show_per())
{
t=sl[j];
sl[j]=sl[i];
sl[i]=t;
}
}
}
for(i=0;i<n;i++)
{
sel.write((char*)& sl[i],sizeof(s));
}
sel.close();
fin.close();

}
void welcome()
   {
     //clrscr();
     int z;
cout<<"\t%%      %%      ";
       cout<<"\n\t%%      %% %%%%%%% %%      %%%%%%  %%%%%% %%%%  %%%% %%%%%%%";
       cout<<"\n\t%%      %% %%      %%      %%      %%  %% %%  %%% %% %%       ";
       cout<<"\n\t%%  %%  %% %%%%%   %%      %%      %%  %% %%  %%% %% %%%%%      ";
       cout<<"\n\t%%  %%  %% %%      %%      %%      %%  %% %%      %% %%           ";
       cout<<"\n\t%%%%%%%%%% %%%%%%% %%%%%%% %%%%%%% %%%%%% %%      %% %%%%%%%     ";
       cout<<"\n\n\t\t\t        $$$$$$$$  $$$$$        ";
       cout<<"\n\t\t\t           $$     $   $      ";
       cout<<"\n\t\t\t           $$     $$$$$    ";

       cout<<"\n\n\n\tCOMPUTER   PROJECT  (********  ON STREAM ALLOCATION  *******)";
     
cout<<" \n\n\n\t\t     press any number and 'ENTER' to continue: ";
cin>>z;

    // getch();
    }
    void thanks()
{     int w;
//clrscr();
cout<<"\n\n\n\n\n\n\n\n\n\n\t**********   T H A N K   Y O U   F O R   W O R K I N G   *******";
cout<<"\n\n\n\n\n\n\n\t\t\t Press Any Number And Then 'ENTER' to exit";
cin>>w;
}


Output:-

Main Window


www.programmingwithbasics.com

Main Menu

www.programmingwithbasics.com


Result & Stream Window

www.programmingwithbasics.com