You are on page 1of 6

3rd program sign up }

2nd program simple calculator


JAVA-Code JAVA Code for SignUp activity });
package com.example.simplecalculator; package com.example.myapplication11;
}
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; Pattern lowerCase = Pattern.compile("^.*[a-z].*$");
import android.view.View; import android.content.Intent;
import android.widget.EditText; Pattern upperCase = Pattern.compile("^.*[A-Z].*$");
import android.widget.TextView; import android.os.Bundle;
Pattern number = Pattern.compile("^.*[0-9].*$");
public class MainActivity extends AppCompatActivity { import android.view.View;
EditText e1,e2; Pattern specialCharacter = Pattern.compile("^.*[^a-zA-Z0-9].*$");
TextView tv; import android.widget.Button;
@Override private Boolean isValidPassword(String password)
protected void onCreate(Bundle savedInstanceState) { import android.widget.EditText;
{
super.onCreate(savedInstanceState); import android.widget.Toast;
setContentView(R.layout.activity_main); if (password.length() < 8)
e1=(EditText)findViewById(R.id.editText1); import java.util.regex.Pattern;
e2=(EditText)findViewById(R.id.editText2); {
public class MainActivity extends AppCompatActivity {
tv=(TextView)findViewById(R.id.tv1); return false;
} EditText emailEditText, passwordEditText;
}
public void add(View V) Button signUpBtn;
{ if (!lowerCase.matcher(password).matches())
int a1=Integer.parseInt(e1.getText().toString()); @Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); {
int a2=Integer.parseInt(e2.getText().toString());
int res=a1+a2; return false;
tv.setText(""+res); emailEditText = findViewById(R.id.emailEditText); passwordEditText =
} findViewById(R.id.passwordEditText); }
public void sub(View V) signUpBtn = findViewById(R.id.signUpBtn); signUpBtn.setOnClickListener(new if (!upperCase.matcher(password).matches())
{
View.OnClickListener()
int a1=Integer.parseInt(e1.getText().toString()); {
int a2=Integer.parseInt(e2.getText().toString()); { @Override public void onClick(View v)
int res=a1-a2; return false;
tv.setText(""+res); {
}
} String email = emailEditText.getText().toString();
public void mul(View V) if (!number.matcher(password).matches())
{ String password = passwordEditText.getText().toString();
int a1=Integer.parseInt(e1.getText().toString()); {
int a2=Integer.parseInt(e2.getText().toString()); if (!isValidPassword(password)) { Toast.makeText(MainActivity.this, "Password
doesn't match rules", Toast.LENGTH_SHORT).show(); return false;
int res=a1*a2;
tv.setText(""+res); }
return;
}
public void div(View V) } if (!specialCharacter.matcher(password).matches())
{
Intent intent = new Intent(MainActivity.this, LoginActivity.class); {
int a1=Integer.parseInt(e1.getText().toString());
int a2=Integer.parseInt(e2.getText().toString()); return false;
intent.putExtra("email", email);
double res=(double)(a1/a2);
tv.setText(""+res); intent.putExtra("password", password); }
}
startActivity(intent); return true;
}

} } }
});
} }
JAVA Code for LoginSuccessActvity private void setWallpaper()
JAVA Code for LoginActivity
package com.example.myapplication11; package com.example.myapplication11; {
import androidx.appcompat.app.AppCompatActivity; mytimer.schedule(new TimerTask() {
import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; @Override
public class LoginSuccessActivity extends AppCompatActivity public void run() {
import android.content.Intent; if(prev==1)
{
import android.os.Bundle; @Override protected void onCreate(Bundle savedInstanceState) {
{ drawable=getResources().getDrawable(R.drawable.w1);
import android.view.View; prev=2;
super.onCreate(savedInstanceState); setContentView(R.layout.activity_login_success); }
import android.widget.Button; else if(prev==2)
} {
import android.widget.EditText;
} drawable=getResources().getDrawable(R.drawable.w2);
import android.widget.Toast; prev=3;
4th program Wallpaper }
public class LoginActivity extends AppCompatActivity else if(prev==3)
JAVA Code:
{ package com.example.myapplication; {
EditText emailEditText, passwordEditText; import androidx.appcompat.app.AppCompatActivity; drawable=getResources().getDrawable(R.drawable.w3);
Button loginBtn; import android.app.WallpaperManager; prev=4;
@Override protected void onCreate(Bundle savedInstanceState) import android.graphics.Bitmap; }
{ import android.graphics.drawable.BitmapDrawable; else
super.onCreate(savedInstanceState); import android.graphics.drawable.Drawable; {
setContentView(R.layout.activity_login); import android.os.Bundle; drawable=getResources().getDrawable(R.drawable.w4);
emailEditText = findViewById(R.id.emailEditText); passwordEditText = import android.view.View; prev=1;
findViewById(R.id.passwordEditText); import android.widget.Button; }
loginBtn = findViewById(R.id.loginBtn); import java.io.IOException; Bitmap wallpaper=((BitmapDrawable)drawable).getBitmap();
String registeredEmail = getIntent().getStringExtra("email"); String import java.util.Timer; try {
registeredPassword =getIntent().getStringExtra("password"); import java.util.TimerTask; wpm.setBitmap(wallpaper);
loginBtn.setOnClickListener(new View.OnClickListener() public class MainActivity extends AppCompatActivity }
{ { catch (IOException e)
@Override public void onClick(View v) Button chngwallpaper; {
{ Timer mytimer; e.printStackTrace();
String email = emailEditText.getText().toString(); Drawable drawable; }
String password = passwordEditText.getText().toString(); WallpaperManager wpm; }
if (registeredEmail.equals(email) && registeredPassword.equals(password)) int prev=1; },0,30000);
{ }
Intent intent = new Intent(LoginActivity.this, LoginSuccessActivity.class); @Override }
startActivity(intent); protected void onCreate(Bundle savedInstanceState) {
} super.onCreate(savedInstanceState); 5th program counter value
Else setContentView(R.layout.activity_main);
{ mytimer=new Timer(); JAVA Code:
Toast.makeText(LoginActivity.this, "Invalid Credentials", wpm=WallpaperManager.getInstance(this); package com.example.lbp3;
Toast.LENGTH_SHORT).show(); chngwallpaper=findViewById(R.id.button); import androidx.appcompat.app.AppCompatActivity;
} chngwallpaper.setOnClickListener(new View.OnClickListener() { import android.os.Bundle;
} @Override import android.os.Handler;
}); public void onClick(View v) { import android.view.View;
} setWallpaper(); import android.widget.Button;

import android.widget.TextView; import org.w3c.dom.Node; }


public class MainActivity extends AppCompatActivity { import org.w3c.dom.NodeList; }
Button b1,b2; import java.io.InputStream; public void parseJson(View V)
TextView tc1; import java.nio.charset.StandardCharsets; {
int i=1; import javax.xml.parsers.DocumentBuilder; String json;
Handler h1=new Handler(); import javax.xml.parsers.DocumentBuilderFactory; StringBuilder stringBuilder=new StringBuilder();
@Override public class MainActivity extends AppCompatActivity { try
protected void onCreate(Bundle savedInstanceState) { TextView display; {
super.onCreate(savedInstanceState); @Override InputStream is=getAssets().open("city.json");
setContentView(R.layout.activity_main); int size=is.available();
b1=findViewById(R.id.bt1); protected void onCreate(Bundle savedInstanceState) { byte[] buffer=new byte[size];
b2=findViewById(R.id.bt2); super.onCreate(savedInstanceState); is.read(buffer);
setContentView(R.layout.activity_main); json=new String(buffer, StandardCharsets.UTF_8);
tc1=findViewById(R.id.tv1); display=findViewById(R.id.display); JSONArray jsonArray=new JSONArray(json);
b1.setOnClickListener(new View.OnClickListener() { } stringBuilder.append("JSON DATA");
@Override public void parseXml(View V) stringBuilder.append("\n-----");
public void onClick(View v) { for (int i=0;i<jsonArray.length();i++)
{ try { {
h1.postDelayed(updateTimerThread,0); InputStream is=getAssets().open("city.xml"); JSONObject jsonObject=jsonArray.getJSONObject(i);
} DocumentBuilderFactory
}); documentBuilderFactory=DocumentBuilderFactory.newInstance(); stringBuilder.append("\n Name").append(jsonObject.getString("name"));
b2.setOnClickListener(new View.OnClickListener() { DocumentBuilder documentBuilder = stringBuilder.append("\n Latitude").append(jsonObject.getString("lat"));
@Override documentBuilderFactory.newDocumentBuilder(); stringBuilder.append("\n Longitude").append(jsonObject.getString("long"));
public void onClick(View v) { Document document=documentBuilder.parse(is); stringBuilder.append("\n
h1.removeCallbacks(updateTimerThread); StringBuilder stringBuilder=new StringBuilder(); Temperature").append(jsonObject.getString("temperature"));
} stringBuilder.append("XML DATA"); stringBuilder.append("\n Humidity").append(jsonObject.getString("humidity"));
}); stringBuilder.append("\n-------"); stringBuilder.append("\n-----");
} NodeList nodeList=document.getElementsByTagName("place"); }
private final Runnable updateTimerThread=new Runnable() { for (int i=0;i<nodeList.getLength();i++) display.setText(stringBuilder.toString());
@Override { is.close();
public void run() { Node node=nodeList.item(i); }
tc1.setText(""+i); if(node.getNodeType()==Node.ELEMENT_NODE) catch (Exception e)
h1.postDelayed(this,1000); { {
i++; Element element=(Element)node; e.printStackTrace();
} stringBuilder.append("\n Lame").append(getValue("name",element)); Toast.makeText(MainActivity.this,"Error in reading json
}; stringBuilder.append("\n Lattitude").append(getValue("lat",element)); file",Toast.LENGTH_SHORT).show();
} stringBuilder.append("\n Longitude").append(getValue("long",element)); }
}
6th program json stringBuilder.append("\n Temperature").append(getValue("temperature",element)); private String getValue(String tag,Element element)
JAVA Code stringBuilder.append("\n Humidity").append(getValue("humidity",element)); {
package com.example.myapplication; stringBuilder.append("\n------"); return
import androidx.appcompat.app.AppCompatActivity; } element.getElementsByTagName(tag).item(0).getChildNodes().item(0).getNodeValue();
import android.os.Bundle; } }
import android.view.View; display.setText(stringBuilder.toString()); }
import android.widget.TextView; } json
import android.widget.Toast; catch (Exception e)
import org.json.JSONArray; { [
import org.json.JSONObject; e.printStackTrace();
import org.w3c.dom.Document; Toast.makeText(MainActivity.this,"Error in reading xml {
import org.w3c.dom.Element; file",Toast.LENGTH_SHORT).show(); "name": "HASSAN",
"lat": "12.295", import android.os.Bundle;
import android.provider.ContactsContract;
"long": "76.639", </place> import android.view.View;
"temperature": "22", </records> import android.widget.Button;
import android.widget.EditText;
"humidity": "92%" 7th program Text to speech public class MainActivity extends AppCompatActivity {
EditText editText;
}, JAVA Code Button clearBtn,callBtn,saveBtn;
package com.example.lb7; @Override
{ import androidx.appcompat.app.AppCompatActivity; protected void onCreate(Bundle savedInstanceState) {
"name": "MANDYA", import android.os.Bundle; super.onCreate(savedInstanceState);
import android.speech.tts.TextToSpeech; setContentView(R.layout.activity_main);
"lat": "12.97165", import android.view.View; editText=findViewById(R.id.editText);
import android.widget.Button; clearBtn=findViewById(R.id.clearBtn);
"long": "77.5946", import android.widget.EditText; callBtn=findViewById(R.id.callBtn);
"temperature": "25", import java.util.Locale; saveBtn=findViewById(R.id.saveBtn);
public class MainActivity extends AppCompatActivity { clearBtn.setOnClickListener(new View.OnClickListener() {
"humidity": "74%" EditText e1; @Override
TextToSpeech t1; public void onClick(View v) {
@Override editText.setText("");
} protected void onCreate(Bundle savedInstanceState) }
{ });
] super.onCreate(savedInstanceState); callBtn.setOnClickListener(new View.OnClickListener() {
setContentView(R.layout.activity_main); @Override
XML e1=findViewById(R.id.editText); public void onClick(View v) {
<?xml version="1.0" ?> t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { String phnum=editText.getText().toString();
@Override Intent intent=new Intent(Intent.ACTION_DIAL);
<records> public void onInit(int status) intent.setData(Uri.parse("tel:"+phnum));
{ startActivity(intent);
<place> if(status!=TextToSpeech.ERROR) }
<name>Mysore</name> { });
t1.setLanguage(Locale.UK);
<lat>12.295</lat> } saveBtn.setOnClickListener(new View.OnClickListener() {
} @Override
<long>76.639</long>
}); public void onClick(View v) {
<temperature>22</temperature> } String phnum=editText.getText().toString();
Intent intent=new Intent(Intent.ACTION_INSERT);
<humidity>90%</humidity> public void convert(View V) intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
{ intent.putExtra(ContactsContract.Intents.Insert.PHONE,phnum);
</place> String tospeak=e1.getText().toString(); startActivity(intent);
t1.speak(tospeak,TextToSpeech.QUEUE_FLUSH,null); }
<place>
} });
<name>Bangalore</name> } }
8th program call and save public void inputNumber(View V)
<lat>12.97165</lat>
{
<long>77.5946</long> JAVA Code Button btn=(Button)V;
package com.example.myapplication; String digit=btn.getText().toString();
<temperature>25</temperature> import androidx.appcompat.app.AppCompatActivity; String phnum=editText.getText().toString();
import android.content.Intent; editText.setText(phnum + digit);
<humidity>74%</humidity>
import android.net.Uri; }}

FS LABORATORY fstream ifile,ofile; s.std_io();


1st program REVERSE ORDER READ cout<<"enter the filename which contain list of names"<<endl; break;
#include<iostream.h> cin>>input; case 2:
#include<stdio.h> ifile.open(input,ios::in); s.file_io();
#include<string.h> if(!ifile) break;
#include<fstream.h> { default:
#include<conio.h> cout<<"file doesnot exist"; exit(0);
#include<iomanip.h> exit(0); }
#include<stdlib.h> getch(); }
class std_file } }
{ cout<<"enter the filename to store names in reverse order"<<endl; 2nd program fixed length records
private: cin>>output; #include<iostream.h>
char name[10][20]; ofile.open(output,ios::out); #include<fstream.h>
char input[20],output[20],str[20]; while(!ifile.eof()) #include<process.h>
public: { #include<string.h>
void std_io(); ifile.getline(str,20); #include<conio.h>
void file_io(); ofile<<strrev(str)<<endl; //to reverse string characters class student
}; } {
void std_file::std_io(){ } private:
int n,i; void main() char buf[45], name[10], sem[10], branch[10];
cout<<"enter the number of names to read "<<endl; { public:
cin>>n; int i,num,len; void read()
cout<<"enter the names"<<endl; std_file s; {
for(i=0;i<n;i++) clrscr(); cout<<"Name: "<<endl;
gets(name[i]); for(;;) cin>>name;
cout<<"the reversed names are"<<endl; { cout<<"Semester: "<<endl;
for(i=0;i<n;i++) cout<<"1:file i/o\n2:standard i/o\noany other to exit\n"; cin>>sem;
cout<<strrev(name[i])<<endl; cin>>num; cout<<"Branch: "<<endl;
} switch(num){ cin>>branch;
void std_file::file_io(){ case 1: }

void pack(fstream &ofile) while(!ifile.eof()) void main()


{ { {
read(); ifile.getline(name,10,'|'); int n,i,ch;
strcpy(buf,""); ifile.getline(sem,10,'|'); student stu;
strcat(buf,name); ifile.getline(branch,10,'|'); fstream ofile;
strcat(buf,"|"); ifile.getline(extra,45,'\n'); ofile.open("student.txt",ios::trunc|ios::app);
strcat(buf,sem); if(strcmp(name,key)==0) ofile.close();
strcat(buf,"|"); { clrscr();
strcat(buf,branch); cout<<"Record found and details are:"<<endl; for(;;)
strcat(buf,"|"); cout<<"Name: "<<name<<endl; {
while(strlen(buf)<45) cout<<"Semester: "<<sem<<endl; clrscr();
strcat(buf,"!"); cout<<"Branch: "<<branch<<endl; cout<<"1. Insert\n2. Display all\n3. Search\n4. Modify\n5.
strcat(buf,"\n"); return 1; Exit\n";
ofile.write(buf,strlen(buf)); }
} } cout<<"Enter your choice"<<endl;
void unpack(fstream &ifile) return 0; cin>>ch;
{ } switch(ch)
char extra[45]; void modify(fstream &iofile,char key[]) {
while(!ifile.eof()) { case 1: fstream ofile;
{ ofile.open("student.txt",ios::out|ios::app);
ifile.getline(name,10,'|'); if(search(iofile,key)) cout<<"Enter the no. of students"<<endl;
ifile.getline(sem,10,'|'); { cin>>n;
ifile.getline(branch,10,'|'); cout<<"Record found,enter modification details:"<<endl; for(i=0;i<n;i++)
ifile.getline(extra,45,'\n'); iofile.seekp(-47,ios::cur); {
cout<<name<<"\t"<<sem<<"\t"<<branch<<"\n"; pack(iofile); stu.pack(ofile);
} } }
} else ofile.close();
int search(fstream &ifile,char key[]) cout<<"Sorry!No such record\n"; break;
{ } case 2: fstream infile;
char extra[45]; }; infile.open("student.txt",ios::in);
stu.unpack(infile); #include<string.h> {
getch(); #include<conio.h> char extra[45];
infile.close(); class student while(!ifile.eof())
break; { {
case 3: cout<<"Enter the record name to be searched"<<endl; private: char buf[45],name[10],sem[10],branch[10]; ifile.getline(name,10,'|');
char key[10]; int pos; ifile.getline(sem,10,'|');
cin>>key; public: ifile.getline(branch,10,'|');
fstream ifile; void read() ifile.getline(extra,45,'\n');
ifile.open("student.txt",ios::in); { cout<<name<<"\t";
if(stu.search(ifile,key)==0) cout<<"name:"<<endl; cout<<sem<<"\t";
cout<<"record not found\n"; cin>>name; cout<<branch<<"\n";
getch(); cout<<"semester:"<<endl; }
ifile.close(); cin>>sem; }
break; cout<<"branch:"<<endl; int search(fstream &ifile,char key[])
case 4: fstream iofile; cin>>branch; {
iofile.open("student.txt",ios::in|ios::out); } char extra[45];
cout<<"Enter the record name to be modified"<<endl; void pack(fstream &ofile) while(!ifile.eof())
cin>>key; { {
stu.modify(iofile,key); read(); ifile.getline(name,10,'|');
getch(); strcpy(buf,""); ifile.getline(sem,10,'|');
iofile.close(); strcat(buf,name); ifile.getline(branch,10,'|');
break; strcat(buf,"|"); ifile.getline(extra,45,'\n');
default: exit(0); strcat(buf,sem); if(strcmp(name,key)==0)
} strcat(buf,"|"); {
} strcat(buf,branch); cout<<" "<<"record found and details are:"<<endl;
} strcat(buf,"|"); cout<<" "<<"name"<<name<<endl;
3rd program VARIABLE LENGTH strcat(buf,"\n"); cout<<" "<<"semester"<<sem<<endl;
#include<iostream.h> ofile.write(buf,strlen(buf)); cout<<" "<<"branch"<<branch<<endl;
#include<fstream.h> } return 1;
#include<process.h> void unpack(fstream &ifile) }

} cout<<"enter the sem;"<<endl; student stu;


return 0; cin>>s[j].sem; fstream ifile,ofile;
} cout<<"enter the branch"<<endl; ofile.open("student.txt",ios::trunc|ios::app);
void modify(fstream &ifile,char key[]) cin>>s[j].branch; ofile.close();
{ } for(;;)
student s[10]; } {
char extra[50]; if(flag==0) clrscr();
int i=0; { cout<<"1.insert\n 2.display\n 3.search\n 4.modify\n 5.exit\n";
while(!ifile.eof()) cout<<"Record not found\n"; cout<<"enter your choice"<<endl;
{ return; cin>>ch;
ifile.getline(s[i].name,10,'|'); } switch(ch)
ifile.getline(s[i].sem,10,'|'); ifile.open("student.txt",ios::trunc|ios::app); {
ifile.getline(s[i].branch,10,'|'); for(int k=0;k<i;k++) case 1: fstream ofile;
ifile.getline(extra,45,'\n'); { ofile.open("student.txt",ios::out|ios::app);
i++; strcpy(buf,""); cout<<"enter the no of students";
} strcat(buf,s[k].name); cin>>n;
ifile.close(); strcat(buf,"|"); for(i=0;i<n;i++)
int flag=0; strcat(buf,s[k].sem); {
for(int j=0;j<i;j++) strcat(buf,"|"); stu.pack(ofile);
{ strcat(buf,s[k].branch); }
if(strcmp(key,s[j].name)==0) strcat(buf,"|"); ofile.close();
{ strcat(buf,"\n"); break;
flag=1; ifile.write(buf,strlen(buf)); case 2: fstream infile;
cout<<"record found details are:"<<endl; } infile.open("student.txt",ios::in);
cout<<s[j].name<<endl; } stu.unpack(infile);
cout<<s[j].sem<<endl; }; getch();
cout<<s[j].branch<<endl; void main() infile.close();
cout<<"enter the modification details"<<endl; { break;
cout<<"enetr the name"<<endl; int n,i,ch; case 3:cout<<"enter the record name to be searched"<<endl;
cin>>s[j].name; char key[10]; cin>>key;

fstream ifile; public: ifile.getline(rrn,10,'|');


ifile.open("student.txt",ios::in); void read() ifile.getline(name,10,'|');
if(stu.search(ifile,key)==0) { ifile.getline(sem,10,'|');
cout<<"record not found\n"; cout<<"Name: "<<endl; ifile.getline(branch,10,'|');
getch(); cin>>name; ifile.getline(extra,40,'\n');
ifile.close(); cout<<"Semester: "<<endl; if(strcmp(key,rrn)==0)
break; cin>>sem; {
case 4: fstream iofile; cout<<"Branch: "<<endl; cout<<"Record found and details are:"<<endl;
iofile.open("student.txt",ios::in|ios::out); cin>>branch; cout<<"Name: "<<name;
cout<<"enter the record name to be modified\n"<<endl; } cout<<"Semester: "<<sem;
cin>>key; void insert(fstream &ofile,char rrn[]) cout<<"Branch: "<<branch;
stu.modify(iofile,key); { return 1;
getch(); read(); }
iofile.close(); strcpy(buf,""); }
break; strcat(buf,rrn); return 0;
default:exit(0); strcat(buf,"|"); }
} strcat(buf,name); };
} strcat(buf,"|"); void main()
} strcat(buf,sem); {
th
4 program RRN strcat(buf,"|"); int n,i,ch,k=0;
#include<stdio.h> strcat(buf,branch); char key[10];
#include<conio.h> strcat(buf,"|"); student stu;
#include<string.h> strcat(buf,"\n"); fstream ofile;
#include<stdlib.h> ofile.write(buf,strlen(buf)); ofile.open("student2.txt",ios::trunc|ios::app);
#include<iostream.h> } ofile.close();
#include<fstream.h> int search(fstream &ifile,char key[]) clrscr();
class student { for(;;)
{ char rrn[10]; {
private: while(!ifile.eof()) cout<<"1.Insert\n2.Search\n3.Exit\n";
char buf[40],name[10],sem[10],branch[10],extra[40]; { cout<<"Enter your choice: ";
cin>>ch; #include<stdlib.h> {
switch(ch) #include<conio.h> int i,x;
{ int n=0,index=0; for(i=1;i<=n;i++)
case 1: fstream ofile; class student {
ofile.open("student2.txt",ios::out|ios::app); { f1>>x>>usn;
cout<<"Enter the no. of students: "; public: char name[20],usn[20],branch[5]; if(strcmp(usn,key)==0)
cin>>n; int sem; return i;
for(i=0;i<n;i++) void insert(fstream &f1,fstream &f2)
{ { }
itoa(++k,key,10); cout<<"Enter Name: "; cout<<"Record not found\n";
stu.insert(ofile,key); cin>>name; return 0;
} cout<<"Enter USN: "; }
ofile.close(); cin>>usn; int remove(fstream &f1,char key[20])
break; cout<<"Enter Sem: "; {
case 2: cout<<"Enter the RRN to search: "; cin>>sem; int i;
cin>>key; cout<<"Enter Branch: "; i=search(f1,key);
fstream ifile; cin>>branch; return i;
ifile.open("student.txt",ios::in); write(f1,f2); }
if(stu.search(ifile,key)==0) } };
cout<<"Record not found\n"; void write(fstream &f1,fstream &f2) void main()
ifile.close(); { {
break; f1<<++index<<"\t"<<usn<<"\n"; fstream f1,f2;
default:exit(0); f2<<name<<"\t"<<usn<<"\t"<<sem<<"\t"<<branch<<"\n"; student s[20],p;
} } int ch,k=0,i;
} void display(fstream &f2) clrscr();
} { f1.open("m1.txt",ios::trunc);
5th program primary indecx f2>>name>>usn>>sem>>branch; f2.open("mn1.txt",ios::trunc);
#include<iostream.h> cout<<name<<"\t"<<usn<<"\t"<<sem<<"\t"<<branch<<"\n"; f1.close();
#include<string.h> } f2.close();
#include<fstream.h> int search(fstream &f1,char key[20]) for(;;)

{ cout<<"Name="<<s[j].name<<"\n"<<"USN="<<s[j].usn<<"\n" }
cout<<"1.Insert 2.Display 3.Search 4.Delete 5.Exit\n"; <<"Sem="<<s[j].sem<<"\n"<<"Branch="<<s[j].branch<<"\n"; }
cout<<"Enter choice: "; } }
cin>>ch; f1.close(); 6th secondary index
switch(ch) f2.close(); #include<iostream.h>
{ break; #include<string.h>
case 1: f1.open("m1.txt",ios::app); case 4: f1.open("m1.txt",ios::in); #include<fstream.h>
f2.open("mn1.txt",ios::app); f2.open("mn1.txt",ios::in); #include<stdlib.h>
cout<<"Enter no. of students: "; cout<<"Enter USN to delete: "; #include<conio.h>
cin>>k; cin>>usn; int n=0,index=0;
n=n+k; j=p.remove(f1,usn); class student
for(int i=1;i<=k;i++) if(j!=0) {
s[i].insert(f1,f2); { public: char name[20],usn[20],branch[5];
f1.close(); for(i=j;i<n;i++) int sem;
f2.close(); s[i]=s[i+1]; void insert(fstream &f1,fstream &f2)
break; cout<<"Deletion successfull\n"; {
case 2: f2.open("mn1.txt",ios::in); } cout<<"Enter Name: ";
for(i=1;i<=n;i++) n--; cin>>name;
s[i].display(f2); index--; cout<<"Enter USN: ";
f2.close(); f1.close(); cin>>usn;
break; f2.close(); cout<<"Enter Sem: ";
case 3: char usn[20]; f1.open("m1.txt",ios::trunc|ios::app); cin>>sem;
cout<<"Enter USN to search: "; f2.open("mn1.txt",ios::trunc|ios::app); cout<<"Enter Branch: ";
cin>>usn; index=0; cin>>branch;
f1.open("m1.txt",ios::in); for(i=1;i<=n;i++) write(f1,f2);
f2.open("mn1.txt",ios::in); s[i].write(f1,f2); }
int j=p.search(f1,usn); f1.close(); void write(fstream &f1,fstream &f2)
if(j!=0) f2.close(); {
{ break; f1<<++index<<"\t"<<name<<"\n";
cout<<"Record found & Details are\n"; default:exit(0); f2<<name<<"\t"<<usn<<"\t"<<sem<<"\t"<<branch<<"\n";

} clrscr(); f1.open("m.txt",ios::in);
void display(fstream &f2) f1.open("m.txt",ios::trunc); f2.open("mn.txt",ios::in);
{ f2.open("mn.txt",ios::trunc); int j=p.search(f1,name);
f2>>name>>usn>>sem>>branch; f1.close(); if(j!=0)
cout<<name<<"\t"<<usn<<"\t"<<sem<<"\t"<<branch<<"\n"; f2.close(); {
} for(;;) cout<<"Record found & Details are\n";
int search(fstream &f1,char key[20]) { cout<<"Name="<<s[j].name<<"\n"<<"USN="<<s[j].usn<<"\n"
{ cout<<"1.Insert 2.Display 3.Search 4.Delete 5.Exit\n"; <<"Sem="<<s[j].sem<<"\n"<<"Branch="<<s[j].branch<<"\n";
int i,x; cout<<"Enter choice: "; }
for(i=1;i<=n;i++) cin>>ch; f1.close();
{ switch(ch) f2.close();
f1>>x>>name; { break;
if(strcmp(name,key)==0) case 1: f1.open("m.txt",ios::app); case 4: f1.open("m.txt",ios::in);
return i; f2.open("mn.txt",ios::app); f2.open("mn.txt",ios::in);
} cout<<"Enter no. of students: "; cout<<"Enter name to delete: ";
cout<<"Record not found\n"; cin>>k; cin>>name;
return 0; n=n+k; j=p.remove(f1,name);
} for(int i=1;i<=k;i++) if(j!=0)
int remove(fstream &f1,char key[20]) s[i].insert(f1,f2); {
{ f1.close(); for(i=j;i<n;i++)
int i; f2.close(); s[i]=s[i+1];
i=search(f1,key); break; cout<<"Deletion successfull\n";
return i; case 2: f2.open("mn.txt",ios::in); }
} for(i=1;i<=n;i++) n--;
}; s[i].display(f2); index--;
void main() f2.close(); f1.close();
{ break; f2.close();
fstream f1,f2; case 3: char name[20]; f1.open("m.txt",ios::trunc|ios::app);
student s[20],p; cout<<"Enter name to search: "; f2.open("mn.txt",ios::trunc|ios::app);
int ch,k=0,i; cin>>name; index=0;
for(i=1;i<=n;i++) cin>>m; if((!out3)||(!out1)||(!out2))
s[i].write(f1,f2); cout<<"\nEnter the names in assending order \n"; {
f1.close(); for(i=0;i<m;i++) cout<<"Unable to open one of the file";
f2.close(); { getch();
break; cin>>name; exit(0);
default:exit(0); out1<<name; }
} out1<<'\n'; clrscr();
} } m=0;
} cout<<"Enter the number of names you want to enter in file2 "; n=0;
th
7 program list and match the names in single loop cin>>n; while(!out1.eof())
#include<stdio.h> cout<<"\nEnter the names in assending order \n"; {
#include<stdlib.h> for(i=0;i<n;i++) out1.getline(list1[m],20,'\n');
#include<string.h> { cout<<list1[m]<<"\t";
#include<conio.h> cin>>name; m++;
#include<fstream.h> out2<<name; }
#include<iostream.h> out2<<'\n'; cout<<endl;
void writeLists() } while(!out2.eof())
{ out1.close(); {
fstream out1,out2; out2.close(); out2.getline(list2[n],20,'\n');
int i,m,n; } cout<<list2[n]<<"\t";
char name[20]; void main() n++;
out1.open("file1.txt",ios::out); { }
out2.open("file2.txt",ios::out); char list1[100][20],list2[100][20]; m--;
if( (!out1) || (!out2) ) int i,j,m,n; n--;
{ clrscr(); i=0;
cout<<"Unable to open one of the list files\n"; fstream out1,out2,out3; j=0;
getch(); writeLists(); cout<<"\nElements common to both files are\n";
exit(0); out1.open("file1.txt",ios::in); while(i<m&&j<n)
} out2.open("file2.txt",ios::in); {
cout<<"Enter the number of names you want to enter in file1 "; out3.open("file3.txt",ios::out); if(strcmp(list1[i],list2[j])==0)

{ void merge_file(char* file1,char* file2,char* filename) for(t=1;t<k-1;t++)


out3<<list1[i]; { temp1<<recd[t].name<<"|"<<recd[t].usn<<"\n";
cout<<list1[i]<<"\n"; record recd[20]; f1.close();
out3<<'\n'; int i,k; f2.close();
i++; k=0; temp1.close();
j++; fstream f1,f2; return;
} f1.open(file1,ios::in); }
else if(strcmp(list1[i],list2[j])<0) f2.open(file2,ios::in); void kwaymerge()
i++; while(!f1.eof()) {
else { int i,k;
j++; f1.getline(recd[k].name,20,'|'); k=0;
} f1.getline(recd[k++].usn,20,'\n'); char
filename[7][20]={"11.txt","22.txt","33.txt","44.txt","111.txt","222.txt","1111.txt"};
getch(); }
for(i=0;i<8;i+=2)
} while(!f2.eof())
{
8th program read list and merge the name using kway merge {
merge_file(fname[i],fname[i+1],filename[k++]);
#include<stdio.h> f2.getline(recd[k].name,20,'|');
}
#include<conio.h> f2.getline(recd[k++].usn,20,'\n');
k=4;
#include<string.h> }
for(i=0;i<4;i+=2)
#include<fstream.h> int t,y;
{
#include<iostream.h> record temp;
merge_file(filename[i],filename[i+1],filename[k++]);
#include<stdlib.h> for(t=0;t<k-2;t++)
}
class record for(y=0;y<k-t-2;y++)
merge_file(filename[4],filename[5],filename[6]);
{ if(strcmp(recd[y].name,recd[y+1].name)>0)
return;
public: {
}
char name[20]; temp=recd[y];
int main()
char usn[20]; recd[y]=recd[y+1];
{
}rec[20]; recd[y+1]=temp;
int i;
fstream file[8]; }
clrscr();
int no; fstream temp1;
cout<<"enter no of records\n";
char fname[8][8]={"1.txt","2.txt","3.txt","4.txt","5.txt","6.txt","7.txt","8.txt"}; temp1.open(filename,ios::out);
cin>>no;

cout<<"\nenter the details\n"; Software testing laboratory int c1,c2,c3,temp;


int locks,stocks,barrels,totallocks,totalstocks,totalbarrels;
for(i=0;i<8;i++) 1st program triangle problem(bva) float lockprice,stockprice,barrelprice,locksales,stocksales,barrelsales,sales,com;
file[i].open(fname[i],ios::out); #include<stdio.h> lockprice=45.0;
#include<conio.h> stockprice=30.0;
for(i=0;i<no;i++) int main( ) barrelprice=25.0;
{ totallocks=0;
{ totalstocks=0;
int a,b,c,c1,c2,c3;
cout<<"Name:"; do totalbarrels=0;
{ clrscr();
cin>>rec[i].name; printf("enter the sides of triangle\n"); printf("Enter the number of locks and to exit press -1\n");
scanf("%d%d%d",&a,&b,&c); scanf("%d",&locks);
cout<<"Usn:"; while(locks != -1)
c1=((a>=1) && (a<=10));
cin>>rec[i].usn; c2=((b>=1) && (b<=10)); {
c3=((c>=1) && (c<=10)); c1=(locks<=0 || locks>70);
file[i%8]<<rec[i].name<<"|"<<rec[i].usn<<"\n"; if(!c1) printf("\nEnter the number of stocks and barrels\n");
} printf("value of a is out of range"); scanf("%d %d",&stocks,&barrels);
if(!c2) c2=(stocks<=0 || stocks>80);
for(i=0;i<8;i++) printf("value of b is out of range"); c3=(barrels<=0 || barrels>90);
file[i].close(); if(!c3) if(c1)
printf("value of c is out of range"); printf("\nValue of locks are not in the range of 1....70\n");
kwaymerge(); }while(!c1 || !c2 || !c3); else
if((a+b)>c && (b+c)>a && (c+a)>b) {
fstream result;
{ temp=totallocks+locks;
result.open("1111.txt",ios::in); if(a==b && b==c) if(temp>70)
printf("Triangle is equilateral\n"); printf("New totallocks = %d not in the range of 1....70\n",temp);
cout<<"sorted records\n"; else
else if(a!=b && b!=c && c!=a)
printf("Triangle is scalene\n"); totallocks=temp;
char name[20],usn[20];
else }
for(i=0;i<no;i++) printf("Triangle is isosceles\n"); printf("Total locks = %d",totallocks);
} if(c2)
{ printf("\n Value of stocks not in the range of 1....80\n");
else
printf("Triangle cannot be formed \n"); else
result.getline(name,20,'|');
getch( ); {
result.getline(usn,20,'\n'); return 0; temp=totalstocks+stocks;
} if(temp>80)
cout<<"\nName:"<<name<<"\nUsn:"<<usn<<"\n";
Variables Min Min+ Nom Max- Max printf("\nNew total stocks = %d not in the range of 1....80",temp);
} else
a 1 2 5 9 10
b 1 2 5 9 10 totalstocks=temp;
getch();
c 1 2 5 9 10 }
return 0; printf("\nTotal stocks = %d",totalstocks);
if(c3)
} printf("\n Value of barrels not in the range of 1....90\n");
2nd program commission problem(bva) else
#include<stdio.h> {
#include<conio.h> temp=totalbarrels+barrels;
int main() if(temp>90)
{ printf("\nNew total barrels = %d not in the range of 1....90\n",temp);
else
totalbarrels=temp; } flag='n';
} int isleap(int year) }
printf("\nTotal barrels=%d", totalbarrels); { }
printf("\nEnter the number of locks and to exit press -1\n"); if((year%4==0 && year%100!=0) || year%400==0)
scanf("%d",&locks); return 1; }while(flag=='n');
} else switch (month)
printf("\n Total locks = %d",totallocks); return 0; {
prin tf("\n Total stocks = %d",totalstocks); } case 1:
printf("\n Total barrels = %d",totalbarrels); case 3:
int main() case 5:
locksales=totallocks*lockprice; { case 7:
stocksales=totalstocks*stockprice; int day,month,year,tomm_day,tomm_month,tomm_year; case 8:
barrelsales=totalbarrels*barrelprice; char flag; case 10:if(day<31)
sales=locksales+stocksales+barrelsales; do tomm_day=day+1;
printf("\n Total sales = %f",sales); { else
if(sales>1800) flag='y'; {
{ printf("\nenter the today's date in the form of dd mm yyyy\n"); tomm_day=1;
com=0.10*1000; scanf("%d%d%d",&day,&month,&year); tomm_month=month+1;
com=com+(0.15*800); tomm_month=month; }
com=com+0.20*(sales-1800); tomm_year= year; break;
} if(day<1 || day>31) case 4:
else if(sales>1000) { case 6:
{ printf("value of day, not in the range 1...31\n"); case 9:
com=0.10*1000; flag='n'; case 11: if(day<30)
com=com+0.15*(sales-1000); } tomm_day=day+1;
} if(month<1 || month>12) else
else {
com=0.10*sales; printf("value of month, not in the range 1....12\n"); {
printf("\nCommission = %f",com); flag='n'; tomm_day=1;
getch(); } tomm_month=month+1;
return 0; else if(check(day,month)) }
} break;
{ case 12: if(day<31)
Input variables printf("value of day, not in the range day<=30"); tomm_day=day+1;
flag='n'; else
Range of value for locks= 1-70, stocks= 1-80 and barrels= 1-90 } {
Variables Min Min+ Nom Max- Max if(year<=1812 || year>2015) tomm_day=1;
locks 1 2 35 69 70 { tomm_month=1;
stocks 1 2 40 79 80 printf("value of year, not in the range 1812.......2015\n"); if(year==2015)
barrels 1 2 45 89 90 flag='n'; {
} printf("the next day is out of boundary value of year\n");
if(month==2) tomm_year=year+1;
3rd program next date problem(bva) { }
if(isleap(year) && day>29) else
#include<stdio.h> { tomm_year=year+1;
int check(int day,int month) printf("invalid date input for leap year"); }
{ flag='n'; break;
if((month==4||month==6||month==9 ||month==11) && day==31) } case 2:
return 1; else if(!(isleap(year))&& day>28)
else { if(day<28)
return 0; printf("invalid date input for not a leap year"); tomm_day=day+1;

else if(isleap(year)&& day==28) printf("triangle is equilateral\n"); return 0;


tomm_day=day+1; else if (a!=b && b!=c && c!=a) }
else if(day==28 || day==29) printf("triangle is scalene\n");
{ else 11 program Quick sort
tomm_day=1; printf("triangle is isosceles\n"); #include<stdio.h>
tomm_month=3; } A. 1 void quicksort(int x[10],int first,int last)
} B. 2 {
break; else
printf("triangle cannot be formed\n"); 3 int temp,pivot,i,j;
} C. 4 if(first<last)
printf("next day is : %d %d %d",tomm_day,tomm_month,tomm_year); return 0;
} D. 5 {
return 0; 6 pivot=first;
} Program 10 binary search 7 i=first;
8 j=last;
Considering Date program, we have three variables day, month and year. #include<stdio.h> E. 9 while(i<j)
Variables Min Min+ Nom Max- Max A. 1 int binsrc(int x [ ],int low,int high,int key) F. 10 {
day 1 2 15 30 31 2{ G. 11 while(x[i]<=x[pivot] && i<last)
month 1 2 6 11 12 3 int mid; H. 12 i++;
year 1812 1813 1914 2014 2015 B. 4 while(low<=high) I. 13 while(x[j]>x[pivot])
C. 5 { J. 14 j--;
4th program triangle(equivalence clas testing) 6 mid=(low+high)/2; K. 15 if(i<j)
R1={<a,b,c>:the triangle with sides a,b and c is Equilateral} D. 7 if(x[mid]==key)
R2={<a,b,c>:the triangle with sides a,b and c is Isosceles} I. 8 return mid; L. 16 {
R3={<a,b,c>:the triangle with sides a,b and c is Scalene} E. 9 elseif(x[mid]<key) 17 temp=x[i];
R4={<a,b,c>:sides a,b and c do not form a Triangle} G. 10 low=mid+1; 18 x[i]=x[j];
F. 11 else 19 x[j]=temp;
5th program commission(equivalence clas testing) 12 high=mid-1; 20 }
H. 13 } M. 21 }
Equivalence Classes are as follows: J. 14 return -1; N. 22 temp=x[pivot];
L1={ locks: 1<=locks<=70} K. 15 } 23 x[pivot]=x[j];
L2={ locks=-1} 24 x[j]=temp;
S1={ stocks: 1<=stocks<=80} int main() 25 quicksort(x,first,j-1);
B1={ barrels: 1<=barrels<=90} { P. 26 quicksort(x,j+1,last);
int a[20],key,i,n,succ; Q. 27 }
6th program next date (equivalence clas testing) printf("Enter the n value up to max of 20"); O. 28 }
Equivalence Classes are as follows: scanf("%d",&n); int main()
D1= { Day/DD : 1<=DD<=31 } if(n>0) {
M1= { Month/MM : 1<=MM<=12 } { int a[20],i,key,n;
Y1= { Year /YY: 1812<=YY<=2015 } printf("enter the elements in ascending order\n"); printf("enter the size of the array max of 20 elements");
for(i=0;i<n;i++) scanf("%d",&n);
7th program triangle(decision table ) scanf("%d",&a[i]); if(n>0)
printf("enter the key element to be searched\n"); {
#include<stdio.h> scanf("%d",&key);
#include<conio.h> printf("enter the elements of the array");
succ=binsrc(a,0,n-1,key); for(i=0;i<n;i++)
int main() if(succ>=0)
{ printf("Element found in position = %d\n",succ+1); scanf("%d",&a[i]);
int a,b,c; else quicksort(a,0,n-1);
printf("enter the sides of triangle\n"); printf("Element not found \n"); printf("the elements in the sorted array is:\n");
scanf("%d%d%d",&a,&b,&c); } for(i=0;i<n;i++)
if((a+b)>c && (b+c)>a && (c+a)>b) else print f("%d\t",a[i]);
{ printf("Number of element should be greater than zero\n"); }
if(a==b && b==c)

else 31 }
\ Cyclomatic Complexity
} V(G) =e-n+2p
Where,
Cyclomatic Complexity e is number of edges in DD-Path graph.
V(G) =e-n+2p n is number of nodes in DD-Path graph.
or p is number of regions connected.(always 1)
V(G) =e-n+p (for closed closed graph) Number of linearly independent paths (Test cases) for a given graph G = 26-19+2(1)
Where, = 7+2
e is number of edges in DD-Path graph. = 9 Test cases
n is number of nodes in DD-Path graph.
p is number of regions connected.(always 1)
Number of linearly independent paths (Test cases) for a given graph G = 23-17+(1)
= 6+1
= 7 Test cases
12 th program absolute letter grading
#include<stdio.h>
#include<conio.h>
A. 1 int main()
2{
3 float per;
4 char grade;
5 printf("enter the percentage\n");
6 scanf("%f",&per);
B. 7 if(per>=90)
C. 8 grade='a';
D. 9 else if((per>=80) && (per<90))
E. 10 grade='b';
F. 11 else if((per>=70) && (per<80))
G. 12 grade='c';
H. 13 else if((per>=60) && (per<70))
I. 14 grade='d';
J. 15 else grade='e';
K. 16 switch(grade)
L. 17 {
M. 18 case 'a':printf("excellent\n");
19 break;
N. 20 case 'b':printf("very good\n");
21 break;
O. 22 case 'c':printf("good\n");
23 break;
P. 24 case 'd':printf("above average\n");
25 break;
Q. 26 case 'e':printf("satisfactory\n");
27 break;
R. 28 }
S. 29 printf("the percentage is %f and the grade is %c\n",per,grade);
30 return 0;

You might also like