Skip to main content

Posts

Program to find Number of Digits in a Number's Factorial

#include <math.h> #include <stdio.h> void main() //can be replaced with int main, i prefer void main {     int i =1,j;     printf("Enter the Number: ");     scanf("%d",&j);     double k = 0,l = log(10);     for(;i<=j;i++)   {         k = k + (log(i)/l);     }     k = (int) (k+0.5);     printf("\n NOD: %f",k+1); } Source:   http://inder-gnu.blogspot.com/2009/09/find-number-of-digits-in-number.html

Exception Handling

/* Problem Statement: Create a class named Television that has data members to hold the model number and the screen size in inches,and the price.Member functions include overloaded insertion and extraction operators. If more than four digits are entered for the model,if the screen size is smaller than 12 or greater than 70 inches, or if the price is negative or over $5000 then throw an integer. Write a main() function that instantiates a television object,allows user to enter data and displays the data members.If an exception is caught ,replace all the data member values with zero values. */ #include #include class television { int model; float size; float price; public: television(); friend void operator friend void operator >> (istream &i,television &t); }; television::television() { model=0; size=0; price=0; } void operator { o o o } void operator >> (i...

Graphics Editor

#include #include #include void main() { int gm,gd=DETECT; int ch,draw,paint,text;//choices int x1,y1,x2,y2,r,sa,ea,xr,yr,poly[10],v,i,midx,midy,res[10],year[10]; char str[10]; initgraph(&gd,&gm,"c:\\tc\\bgi"); while(1) { x: cleardevice(); printf("\nGraphics Editor"); printf("\n1.DRAW\n2.TEXT\n3.PAINT\n4.EXIT\nEnter choice:"); scanf("%d",&ch); switch(ch) { case 1: while(1) { cleardevice(); printf("\nDrawing Different Polygons"); printf("\n1.Pixel\n2.Line\n3.Circle\n4.Ellipse\n5.Polygon"); printf("\n6.Line Styles\n7.Bar Graphs\n8.Pai Charts\n9.Histogram\n0.Main Menu\nEnter Choice: "); scanf("%d",&draw); switch(draw) { case 1://pixel printf("\nenter x1,y1: "); scanf("%d%d",&x1,&y1); putpixel(x1,y1,15)...

Matrix - template

/* Problem Statement: Write a program in C++ using function template to read two matrices of different data types such as integers and floating point values and perform simple arithmetic operations on these matrices separately and display it. */ #include #include #include template //Template Definition class matrix { int m,n; T a[10][10]; public: matrix() //Default Constructor { m=n=0; } matrix(int x,int y,T c[10][10]); //Parameterised Constructor void insert(); void display(); matrix operator +(matrix ); matrix operator -(matrix ); matrix operator *(matrix ); }; //------------------- Constructor ---------- template matrix ::matrix(int x,int y,int z[10][10]) { int i,j; m=x; n=y; for(i=0;i for(j=0;j a[i][j]=z[i][j]; } //------------------ Insertion -------------- template void matrix ::ins...

weather report

/* Problem Statement: Create a class named weather report that holds a daily weather report with data members day_of_month,hightemp,lowtemp,amount_rain and amount_snow. The constructor initializes the fields with default values: 99 for day_of_month, 999 for hightemp,-999 for low temp and 0 for amount_rain and amount_snow. Include a function that prompts the user and sets values for each field so that you can override the default values. Write a program that creates a monthly report. */ #include #include class weather { public: int day_of_month[50]; int high_temp[50]; int low_temp[50]; int amount_rain[50]; int amount_snow[50]; weather() //defination { day_of_month[0]=99; high_temp[0]=999; low_temp[0]=-999; amount_rain[0]=amount_snow[0]=0; } void get_data(int n); void put_data(int n); void average(int n); }; void weather:: average(int n) { int min ,max,total_rainfall,total_snowfall; total_rainfall=0; tot...

Virtual

/* Problem Statement: Design a base class consisting of the data members such as name of the student,roll number and subject.The derived class consists of the data members subject code ,internal assessment and university examination marks.Construct a virtual base class for the item name of the student and roll number. The program should have these facilities:- i) Build a master table ii) List a table iii) Insert a new entry iv) Delete old entry v) Edit an entry vi) Search for a record */ Include: iostream.h conio.h fstream.h iomanip.h class base1 { public: char name[10],sub[10]; int rno; }; class derived: public base1 { protected: int subco,umark,iass; public: void getdata(derived ); void putdata(derived ); void insert(derived); derived edit(derived); void delet(derived); int search(int,derived); }; void derived::getdata(derived d) { fstream file; file.open(...

Complex Nos

Include: iostream.h conio.h stdlib.h class complex { float x,y; public: complex() { } complex(float real,float imaginary) { x=real; y=imaginary; } complex operator+(complex c); complex operator-(complex c); complex operator*(complex c); complex operator/(complex c); void display() { cout } }; // Overloading Operator " - " complex complex::operator-(complex c) { complex temp; temp.x=x-c.x; temp.y=y-c.y; return temp; } // Overloading Operator " * " complex complex::operator*(complex c) { complex temp; temp.x=x*c.x; temp.y=y*c.y; return temp; } // Overloading Operator " + " complex complex::operator+(complex c) { complex temp; ...