Escolar Documentos
Profissional Documentos
Cultura Documentos
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
clrscr();
int option;
start:
//Display the menu to the user
displayMenu();
//Get 'option’ from the user
cout<<"Enter an option:";
cin>>option;
switch(option){
case 1:
int V,R;
cout<<"Enter voltage:";
cin>>V;
cout<<"Enter resistance:";
cin>>R;
cout<<"The current in the electrical signal is "<<current(V,R)<<"\n\n";
getch();
clrscr();
goto start;
case 2:
float S,vel,t;
Page 1 of 7
cout<<"Enter Distance:";
cin>>S;
cout<<"Enter velocity:";
cin>>vel;
cout<<"Enter Time:";
cin>>t;
cout<<"Acceleration of the car is "<<acceleration(S,vel,t)<<"\n\n";
getch();
clrscr();
goto start;
case 3:
float x,y;
cout<<"Enter a value for x coordinates:";
cin>>x;
cout<<"Enter a value for y coordinates:";
cin>>y;
cout<<"Intercept of the graph is "<<intercept(x,y)<<"\n\n";
getch();
clrscr();
goto start;
case 4:
exit(0);
break;
default:
cout<<"Invalid option!\n\n";
getch();
clrscr();
goto start;
}
getch();
}
Page 2 of 7
//Calculating the current in an electrical circuit
float current (float vol,float res){
return vol/res;
}
#include<iostream.h>
#include <conio.h>
Page 3 of 7
}
#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
void main()
{
clrscr();
char f_name[20];
char l_name[40];
char full_name[60];
char u_name[20];
char password[15];
char rentered_password[15];
Page 4 of 7
//Get user details
cout<<"Enter your first name:";
gets(f_name);
cout<<"Enter your last name:";
gets(l_name);
getch();
}
Page 5 of 7
Question 4-Model Answer (25 marks)
#include <iostream.h>
#include<conio.h>
class Account {
//current account balance
long balance;
public:
void deposit(long amount) {
balance =balance+amount;
}
void status () {
cout<<"Bank Balance: Rs."<<balance<<endl;
if(balance<0)
cout<<"You have a debit balance!"<<endl;
else if (balance==0)
cout<<"You have a zero balance"<<endl;
}
//Destructor
~Account () {
}
};
void main ()
{
clrscr();
Page 6 of 7
//object creation
Account Nimal, Kamal(100),Saman(-400);
getch();
}
Page 7 of 7