CBSE Class XI Programming in C++
-
Upload
pranav-ghildiyal -
Category
Education
-
view
122 -
download
7
description
Transcript of CBSE Class XI Programming in C++
The Programs
Sum Of MatricesSum Of Matrices
Product Of Matricescout<<"Enter second matrix row cout<<"Enter second matrix row wise";wise";for(i = 0; i<p; ++i)for(i = 0; i<p; ++i)for(j = 0; j<q; ++j)for(j = 0; j<q; ++j)cin>>B[i][j];cin>>B[i][j];cout<<“product of the given two cout<<“product of the given two matrix is : “;matrix is : “;for(i = 0; i<m; ++i)for(i = 0; i<m; ++i){ cout<<“\n”;{ cout<<“\n”;for(j = 0; j<n; ++j)for(j = 0; j<n; ++j){ C[i][j] = 0;{ C[i][j] = 0;C[i][j] = C[i][j] + A[i][k] * B[k][j];C[i][j] = C[i][j] + A[i][k] * B[k][j];cout<< C[i][j] << “ “;cout<< C[i][j] << “ “;}} }} }}else else cout<<“\n the matrices are not cout<<“\n the matrices are not compatible for multiplication “;compatible for multiplication “;getch(); getch(); }}
Linear Search
Palindrome (string)
Stats of text#include<iostream.h>#include<conio.h>#include<process.h>void textstat( char str[], int &lc, int &wc, int &cc);void main(){ clrscr();char str[255] = “ Hi how are you !! ”;int lc, wc, cc;cout<<“\n Enter any string (~ to terminate) : “;cin.getline(str, 255,’~’)textstat(str, lc, wc, cc);cout<< “number of lines in the string are: “<< lc;cout<< “number of words in the string are: “<< wc;cout<< “number of characters in the string are: “<< cc;getch();}int wordcount(char str[]){ int count = 1;for (int i = 0; str[i] ‘\0’; ++i){ if (str[i] == ‘i’ || str[i] == ‘\n’){count ++;while (str[i] ==‘ ‘)i++; }
if (str[i]==‘\0’)i--;}return count;}int charcount(char str[])int count = 0;for (int i = 0; str[i] ‘\0’; ++i)count++;return count;}int linecount(char str[]){ int count = 1;for (int i = 0; str[i] ‘\0’; ++i)if(str[i]==‘\n’)count++;return count;}void textstat( char str[], int &lc, int &wc, int &cc){ lc = linecount(str); wc = wordcount(str); cc = charcount(str);}
Nested structures#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct addr
{ int houseno;
char area[25];
char city[25];
char state[25];
};
struct emp
{
int empno;
char name[25];
char desig[25];
addr address;
float basic;
} worker;
int main ()
{ clrscr();
cout<<" \n Enter employee number:"
cin>>worker.empno;
cout<<" \n Enter name:"
gets(worker.name);
cout<<" \n Enter Designation:"
gets(worker.desig);
cout<<" \n Enter House no. :"
gets(worker.address.houseno);
cout<<" \n Enter Area"
gets(worker.address.area);
cout<<" \n Enter city
getsworker.address.city);
cout<<" \n Enter state"
gets(worker.address.state);
cout<<" \n Enter Basic pay "
cin>>worker.basic;
return0;
}
Student’s Result #include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct student
{
int rollno;
char name[25];
float marks;
char grade;
};
student learner;
void main ()
{
clrscr();
cout<<" \n Enter roll number:"
cin>>learner.rollno;
cout<<" \n Enter name:"
gets(learner.name);
cout<<" \n marks in 5 subjects:"
for (int i = 0;i < 5 ; ++i)
{
cout<<"Subject"<< i + 1 <<": ";
cin>>learner.marks[i];
}
float avg, total = 0;
for (int i = 0;i < 5 ; ++i)
total += sum[i];
avg = total/ 5;
if (avg < 50) learner.grade = 'F';
else if (avg < 60) learner.grade = 'C';
else if (avg < 80) learner.grade = 'B';
else lerner.grade = 'A'
cout<<" \n Student's Result :"
cout<<" \n roll number :"<<learner.rollno;
cout<<" \n Name :'
puts(learner.name);
cout<<" \n Total marks :"<< total;
cout<<" \n Grade :"<<learner.grade <<endl;
}
cout<<" \n Enter Basic pay "
cin>>worker.basic;
return 0;
}
Equality of strings
The later Date#include<iostream.h>#include<iostream.h>
#include<conio.h>#include<conio.h>
#include<process.h>#include<process.h>
#include<stdio.h>#include<stdio.h>
date later ( dateS1, dateS2);date later ( dateS1, dateS2);
void main()void main()
{ clrscr();{ clrscr();
struct date { int day;struct date { int day;
int month;int month;
int year;int year;
}d1, d2;}d1, d2;
cout<<"enter first date";cout<<"enter first date";
cout<<"enter day";cout<<"enter day";
gets(d1.day);gets(d1.day);
cout<<"enter month";cout<<"enter month";
gets(d1.month);gets(d1.month);
cout<<"enter year";cout<<"enter year";
gets(d1.year);gets(d1.year);
cout<<"\n";cout<<"\n";
cout<<"enter second date";cout<<"enter second date";
cout<<"enter day";cout<<"enter day";
gets(d2.day);gets(d2.day);
cout<<"enter month";cout<<"enter month";
gets(d2.month);gets(d2.month);
cout<<"enter year";cout<<"enter year";
gets(d2.year);gets(d2.year);
date later (date S1, date S2)date later (date S1, date S2)
getch();getch();
}}
date later (date S1, date S2)date later (date S1, date S2)
{{
if (S2.year > S1.year)if (S2.year > S1.year)
cout<< S2;cout<< S2;
else if (S1.year > S2.year)else if (S1.year > S2.year)
cout<< S1;cout<< S1;
else if (S1.month > S2.month)else if (S1.month > S2.month)
cout<< S1;cout<< S1;
else if (S1.month < S2.month)else if (S1.month < S2.month)
cout<< S2;cout<< S2;
else if (S2.day > S1.day)else if (S2.day > S1.day)
cout<< S2;cout<< S2;
else else
cout<< S1;cout<< S1;
}}