Khalsa SYIT 2006 Info Blog

Name:
Location: mumbai, India

Tuesday, November 28, 2006

C++ & Java : Assignment 3

Hello friends, this is the 3rd assignment of C++. I will post the others soon.

1)Cricket


#include
#include
#include
#include
class cricket
{
char name[20];
char team[10];
float average;
public:
void read(void);
void disp(void);
};
void cricket::read()
{
cout<<"\nEnter the name of the player: ";
cin >> name;
cout << "Enter the team: ";
cin >> team;
cout << "Enter batting average: ";
cin >> average;
}
void cricket::disp()
{
cout << name << "\t" << team << "\t" << average << "\n";
}
int main()
{
cricket player[10];
int i;
for(i=1;i<11;i++)
{
player[i].read();
}
cout << "\n\n";
for(i=1;i<11;i++)
{
player[i].disp();
}
getch();
return 0;
}


2) Cricket with Constructors


#include
#include
#include
#include
class cricket
{
char name[20];
char team[10];
float average;
public:
cricket()
{
cout<<"\nEnter the name of the player: ";
cin >> name;
cout << "Enter the team: ";
cin >> team;
cout << "Enter batting average: ";
cin >> average;
}
void disp()
{
cout << name << "\t" << team << "\t" << average << "\n";
}
};
int main()
{
cricket player[8];
int i;
for(i=1;i<9;i++)
{
player[i].disp();
}
getch();
return 0;
}



3) Publication program


#include
#include
#include
#include
class publication
{
public:
char title[20];
float price;
publication()
{
cout << "\nEnter the title: ";
cin >> title;
cout << "Enter the price: ";
cin >> price;
}
void display()
{
cout << "\n\nTitle: " << title << "\nPrice: " << price;
}
};
class book:public publication
{
public:
int pagecount;
book():publication()
{
cout << "Enter the number of pages: ";
cin >> pagecount;
}
void display()
{
cout << "\n\nTitle: " << title << "\nPrice: " << price;
cout << "\nNo. of pages: " << pagecount;
}
};
class tape:public publication
{
public:
float playtime;
tape():publication()
{
cout << "Enter the playtime: ";
cin >> playtime;
}
void display()
{
cout << "\n\nTitle: " << title << "\nPrice: " << price;
cout << "\nNo. of Minutes: " << playtime;
}
};

int main()
{
book b1;
tape t1;
b1.display();
t1.display();
getch();
return 0;
}

Wednesday, November 15, 2006

C++ & Java : Assignment 2

Here are the two programs required for the 2nd assignment.


1) Program to calculate area:


#include
#include
#include
#include
void area(int a) // Square
{
int x;
x=a*a;
cout << "\nArea of square = " << x << " Sq.Units\n";
}
void area(int a, int b) //Rectangle
{
int x;
x=a*b;
cout << "\nArea of rectangle = " << x << " Sq.Units\n";
}
void area(float p, int a) //Circle
{
float x;
x=p*a*a;
cout << "\nArea of circle = " << x << " Sq.Units\n";
}
int main()
{
int choice,a,b;
float p=3.14;
cout << "Enter 1 for area of square\n";
cout << "Enter 2 for area of circle\n";
cout << "Enter 3 for area of rectangle\n";
cin >> choice;
if(choice==1)
{
cout << "\nEnter side of the square: ";
cin >> a;
area(a);
}
else if(choice==2)
{
cout << "\nEnter radius of the circle:";
cin >> a;
area(p,a);
}
else if(choice==3)
{
cout << "\nEnter length of the triangle:";
cin >> a;
cout << "\nEnter breadth of the triangle:";
cin >> b;
area(a,b);
}
else
{ cout << "\nInvalid choice"; }
getch();
return 0;
}




2) Program to create account and operate it


#include
#include
#include
#include
class account
{
char name[30];
int acc_no;
char type[5];
int balance;
public:
void init_value(void);
void deposit(void);
void withdraw(void);
void details(void);
};
void account::init_value(void)
{
cout << "Enter the name of the depositor: ";
cin >> name;
cout << "\nEnter the initial amount in the account: ";
cin >> balance;
cout << "Enter the type of account" << "\n'sav' for saving account" << "\n'sal' for salary account\n";
cin >> type;
}
void account::deposit(void)
{
int dep_amount;
cout << "\nEnter the amount you want to deposit: ";
cin >> dep_amount;
balance = balance + dep_amount;
}
void account::withdraw(void)
{
int wit_amount;
cout << "\nEnter the amount you want to withdraw: ";
cin >> wit_amount;
if(balance>wit_amount)
balance = balance - wit_amount;
else
cout << "\nYou do not have enough balance in your acount";
}
void account::details(void)
{
cout << "\nName: " << name;
cout << "\nBalance: " << balance;
cout << "\nAcc. Type: " << type;
}
int main()
{
account account1;
int choice;
account1.init_value();
do
{
cout << "\n\n\nEnter 1 to deposit money in the account";
cout << "\nEnter 2 to withdraw money from the account";
cout << "\nEnter 3 to check the details of your account";
cout << "\nEnter 4 to exit\n";
cin >> choice;
if (choice==1)
account1.deposit();
else if (choice==2)
account1.withdraw();
else if (choice==3)
account1.details();
else
exit;
}
while(choice!=4);
getch();
return 0;
}

Tuesday, November 14, 2006

C++ & Java : Assignment 1

These are the programs which are requested in assignment 1. I have executed them all and they are perfectly runnning and giving correct output. However, I am not 100% sure that these are what Miss Gauri wants.

There was a small problem while copy pasting howevr, the progtam is executable. Wile writing in assg, after every semicolon, continue on new line where it is not done so.

1) Calculator program


#include
#include
#include
#include

int sum(int a, int b)
{
int m;
m=a+b;
return m;
}
int diff(int a, int b)
{
int m;
m=a-b;
return m;
}
int prod(int a, int b)
{
int m;
m=a*b;
return m;
}
int division(int a, int b)
{
int m;
m=a/b;
return m;
}


int read()
{
int a,b;
cout << "Enter 1st operand ";
cin >> a;
cout << "Enter 2nd operand ";
cin >> b;
}

void choice()
{
int a,b,c,m;
cout << "\nEnter 1 for addition\n";
cout << "Enter 2 for sutraction\n";
cout << "Enter 3 for product\n";
cout << "Enter 4 for division\n";
cout << "Enter choice";
cin >> c;

if (c==1)
m=sum(a,b);
else if (c==2)
m=diff(a,b);
else if (c==3)
m=prod(a,b);
else if (c==4)
m=division(a,b);
else
cout << "Invalid choice";
cout << "\nSolution "<< m;
}

int main()
{

read();
choice();
getch();
return 0;
}



2) Employee Total Salary program

#include
#include
#include
#include
void getdata()
{
char name[30];
int basic_sal;
float total_sal;
cout << "Enter name of employee: ";
cin >> name;
cout << "\nEnter basic salary: ";
cin >> basic_sal;
cout << "\n\nName: " << name << "\n";
cout << "Basic Salary: " << basic_sal <<"\n";
total_sal=basic_sal + (basic_sal*0.2) + (basic_sal*0.15) + (basic_sal*0.1);
cout << "\nTotal Salary = " << total_sal;
}
int main()
{
getdata();
getch();
return 0;
}


3)Right Angled Triangle program

#include
#include
#include
#include
void triangle(int a, int b, int c)
{
int m,n;
if((a>b)&&(a>c))
{
m=a*a;
n=(b*b)+(c*c);
}
else if((b>a)&&(b>c))
{
m=b*b;
n=(a*a)+(c*c);
}
else
{
m=c*c;
n=(a*a)+(b*b);
}
if(m==n)
cout << "\nTriangle is a right angled triangle";
else
cout << "\nTriangle is not a right angled triangle";
}
int main()
{
int a,b,c;
cout << "Enter 1st of the triangle:";
cin >> a;
cout << "\nEnter 2nd of the triangle:";
cin >> b ;
cout << "\nEnter 3rd of the triangle:";
cin >> c ;
triangle(a,b,c);
getch();
return 0;
}


These are the three programs and I am sure they will help you. If you have any comments or doubts you can post here.
I will post the 2nd assignment by tommorow night.

Introduction

I have started this blog so that we all friends can share all the information about studies, activities and all other topics related to this class.