SlideShare a Scribd company logo
1 of 13
Download to read offline
#include
#include
using namespace std;
//global variable declaration
int a[10];
int active, size;
void menu() {//prints menu
cout << "menu" << endl;
cout << "1.Insert "Insert" key" << endl; //code 45
cout << "2.Delete "Delete" key" << endl; //code 46
cout << "3.Sort "F2" key" << endl; //code 113
cout << "4.Select "Down Arrow" key" << endl; //code 40
cout << "5.Move Right "Right Arrow" key" << endl; //code 39
cout << "6.Move Left "Left Arrow" key" << endl; //code 37
cout << "7.Exit "F1" key" << endl; //code 112
cout << "press the required key or number to continue" << endl;
}
//reads the data from file
void readdata() {
ifstream f;
f.open("F://MyFile.txt");
if (f.is_open()) {
f>>size;
f>>active;
if (size > 10) {
cout << "Numbers exceeds array limit";
return;
} else {
for (int i = 0; i < size; i++) {
f >> a[i];
}
}
f.close();
}
}
//sorts the data
void sort() {
//sorting using bubble sort
int pass = 0, so = 0, t, i;
while ((pass <= size - 1) && (so == 0)) {
so = 1;
for (i = 0; i < size - 1 - pass; i++) {
if (a[i] > a[i + 1]) {
t = a[i];
a[i] = a[i + 1];
a[i + 1] = t;
so = 0;
}
}
pass = pass + 1;
}
}
//prints the data
void print() {
cout<<" ";
for (int i = 0; i < size; i++) {
cout << a[i] << "t";
}
cout << "Active=" << active << endl;
}
//writes the data into the file
void writedata() {
ofstream f;
f.open("F://MyFile.txt");
f << size << endl;
f << active << endl;
for (int i = 0; i < size; i++) {
f << a[i] << " ";
}
f.close();
}
//inserts an element in array and makes it active
void insert() {
if (size == 10)//checks if the list is full
cout << "list is full";
else {
int x, i;
cout << "Enter a number to insert: ";//takes user input
cin>>x;
for (i = 0; i < size; i++) {
if (a[i] == active)//finds active index
break;
}
size++;//increment the size
int y = size;
while (y != i) {//shifting
a[y] = a[y - 1];
y--;
}
a[i] = x;//insert
active = x;//sets active
}
}
//deletes the active value and sets the next one as active
void del() {
int i;
for (i = 0; i < size; i++) {//finds active index
if (a[i] == active)
break;
}
active = a[i + 1]; //sets the next one as active
while (i < size - 1) {//shifting
a[i] = a[i + 1];
i++;
}
size--;//decrements the size
}
//changes the active value
void select() {
int i;
for (i = 0; i < size; i++) {
if (a[i] == active)//finds active index
break;
}
if (i == size - 1)
active = a[0]; //selects the first one as active
else
active = a[i + 1]; //sets the next one as active
}
//moves the active value to its left
void moveleft() {
int i;
for (i = 0; i < size; i++) {
if (a[i] == active)
break;
}
if (i == 0)
cout << "moving left is not possible"; //selects the first one as active
else
{ int temp = a[i - 1];
a[i-1]=a[i];
a[i]=temp;
//moves the active value to the left of the previous element by swapping
}
}
//moves the active value to its right
void moveright() {
int i;
for (i = 0; i < size; i++) {
if (a[i] == active)
break;
}
if (i == size - 1)
cout << "moving right is not possible"; //selects the first one as active
else
{ int temp = a[i + 1];
a[i+1]=a[i];
a[i]=temp;
//moves the active value to the right of the next element by swapping
}
}
int main() {
int ch;
readdata();
print();
menu();
while (1) {
// switch (getchar()) {//keyboard key input
// case 45:
// insert();
// print();
// break;
// case 46:
// del();
// print();
// break;
// case 113:
// sort();
// print();
// break;
// case 40:
// down();
// print();
// break;
// case 39:
// right();
// print();
// break;
// case 37:
// left();
// print();
// break;
// case 112:
// print();
// writedata();
// return 0;
// break;
// default:
// cout << "Invalid key" << endl;
// }
cin>>ch;
switch (ch) {//numeric input
case 1:
insert();
print();
break;
case 2:
del();
print();
break;
case 3:
sort();
print();
break;
case 4:
select();
print();
break;
case 5:
moveright();
print();
break;
case 6:
moveleft();
print();
break;
case 7:
print();
writedata();
return 0;
break;
default:
cout << "Invalid key" << endl;
}
menu();
}
return 0;
}
Solution
#include
#include
using namespace std;
//global variable declaration
int a[10];
int active, size;
void menu() {//prints menu
cout << "menu" << endl;
cout << "1.Insert "Insert" key" << endl; //code 45
cout << "2.Delete "Delete" key" << endl; //code 46
cout << "3.Sort "F2" key" << endl; //code 113
cout << "4.Select "Down Arrow" key" << endl; //code 40
cout << "5.Move Right "Right Arrow" key" << endl; //code 39
cout << "6.Move Left "Left Arrow" key" << endl; //code 37
cout << "7.Exit "F1" key" << endl; //code 112
cout << "press the required key or number to continue" << endl;
}
//reads the data from file
void readdata() {
ifstream f;
f.open("F://MyFile.txt");
if (f.is_open()) {
f>>size;
f>>active;
if (size > 10) {
cout << "Numbers exceeds array limit";
return;
} else {
for (int i = 0; i < size; i++) {
f >> a[i];
}
}
f.close();
}
}
//sorts the data
void sort() {
//sorting using bubble sort
int pass = 0, so = 0, t, i;
while ((pass <= size - 1) && (so == 0)) {
so = 1;
for (i = 0; i < size - 1 - pass; i++) {
if (a[i] > a[i + 1]) {
t = a[i];
a[i] = a[i + 1];
a[i + 1] = t;
so = 0;
}
}
pass = pass + 1;
}
}
//prints the data
void print() {
cout<<" ";
for (int i = 0; i < size; i++) {
cout << a[i] << "t";
}
cout << "Active=" << active << endl;
}
//writes the data into the file
void writedata() {
ofstream f;
f.open("F://MyFile.txt");
f << size << endl;
f << active << endl;
for (int i = 0; i < size; i++) {
f << a[i] << " ";
}
f.close();
}
//inserts an element in array and makes it active
void insert() {
if (size == 10)//checks if the list is full
cout << "list is full";
else {
int x, i;
cout << "Enter a number to insert: ";//takes user input
cin>>x;
for (i = 0; i < size; i++) {
if (a[i] == active)//finds active index
break;
}
size++;//increment the size
int y = size;
while (y != i) {//shifting
a[y] = a[y - 1];
y--;
}
a[i] = x;//insert
active = x;//sets active
}
}
//deletes the active value and sets the next one as active
void del() {
int i;
for (i = 0; i < size; i++) {//finds active index
if (a[i] == active)
break;
}
active = a[i + 1]; //sets the next one as active
while (i < size - 1) {//shifting
a[i] = a[i + 1];
i++;
}
size--;//decrements the size
}
//changes the active value
void select() {
int i;
for (i = 0; i < size; i++) {
if (a[i] == active)//finds active index
break;
}
if (i == size - 1)
active = a[0]; //selects the first one as active
else
active = a[i + 1]; //sets the next one as active
}
//moves the active value to its left
void moveleft() {
int i;
for (i = 0; i < size; i++) {
if (a[i] == active)
break;
}
if (i == 0)
cout << "moving left is not possible"; //selects the first one as active
else
{ int temp = a[i - 1];
a[i-1]=a[i];
a[i]=temp;
//moves the active value to the left of the previous element by swapping
}
}
//moves the active value to its right
void moveright() {
int i;
for (i = 0; i < size; i++) {
if (a[i] == active)
break;
}
if (i == size - 1)
cout << "moving right is not possible"; //selects the first one as active
else
{ int temp = a[i + 1];
a[i+1]=a[i];
a[i]=temp;
//moves the active value to the right of the next element by swapping
}
}
int main() {
int ch;
readdata();
print();
menu();
while (1) {
// switch (getchar()) {//keyboard key input
// case 45:
// insert();
// print();
// break;
// case 46:
// del();
// print();
// break;
// case 113:
// sort();
// print();
// break;
// case 40:
// down();
// print();
// break;
// case 39:
// right();
// print();
// break;
// case 37:
// left();
// print();
// break;
// case 112:
// print();
// writedata();
// return 0;
// break;
// default:
// cout << "Invalid key" << endl;
// }
cin>>ch;
switch (ch) {//numeric input
case 1:
insert();
print();
break;
case 2:
del();
print();
break;
case 3:
sort();
print();
break;
case 4:
select();
print();
break;
case 5:
moveright();
print();
break;
case 6:
moveleft();
print();
break;
case 7:
print();
writedata();
return 0;
break;
default:
cout << "Invalid key" << endl;
}
menu();
}
return 0;
}

More Related Content

Similar to #includeiostream #includefstreamusing namespace std; glo.pdf

Given the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfGiven the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfillyasraja7
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfHIMANSUKUMAR12
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdfanujmkt
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)Ankit Gupta
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignmentsreekanth3dce
 
Can you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfCan you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfarorasales234
 
COA_remaining_lab_works_077BCT033.pdf
COA_remaining_lab_works_077BCT033.pdfCOA_remaining_lab_works_077BCT033.pdf
COA_remaining_lab_works_077BCT033.pdfJavedAnsari236392
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docxajoy21
 
#include -iostream- #include -fstream- #include -cctype- #include -cst.docx
#include -iostream- #include -fstream- #include -cctype- #include -cst.docx#include -iostream- #include -fstream- #include -cctype- #include -cst.docx
#include -iostream- #include -fstream- #include -cctype- #include -cst.docxNathanyXJSharpu
 
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docxPiersRCoThomsonw
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfJUSTSTYLISH3B2MOHALI
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfravikapoorindia
 
#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docxajoy21
 
the following code should print essential prime implicant but i does.pdf
the following code should print essential prime implicant but i does.pdfthe following code should print essential prime implicant but i does.pdf
the following code should print essential prime implicant but i does.pdfadwitanokiastore
 

Similar to #includeiostream #includefstreamusing namespace std; glo.pdf (20)

Qprgs
QprgsQprgs
Qprgs
 
Given the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfGiven the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdf
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)
 
week-15x
week-15xweek-15x
week-15x
 
Ds program-print
Ds program-printDs program-print
Ds program-print
 
Hw3
Hw3Hw3
Hw3
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
Can you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfCan you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdf
 
Data structures
Data structuresData structures
Data structures
 
COA_remaining_lab_works_077BCT033.pdf
COA_remaining_lab_works_077BCT033.pdfCOA_remaining_lab_works_077BCT033.pdf
COA_remaining_lab_works_077BCT033.pdf
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docx
 
#include -iostream- #include -fstream- #include -cctype- #include -cst.docx
#include -iostream- #include -fstream- #include -cctype- #include -cst.docx#include -iostream- #include -fstream- #include -cctype- #include -cst.docx
#include -iostream- #include -fstream- #include -cctype- #include -cst.docx
 
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
week-16x
week-16xweek-16x
week-16x
 
#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx
 
the following code should print essential prime implicant but i does.pdf
the following code should print essential prime implicant but i does.pdfthe following code should print essential prime implicant but i does.pdf
the following code should print essential prime implicant but i does.pdf
 

More from krram1989

a)Notesb)Equity income accrual—2015 ($181,500 × 30)$54450Amorti.pdf
a)Notesb)Equity income accrual—2015 ($181,500 × 30)$54450Amorti.pdfa)Notesb)Equity income accrual—2015 ($181,500 × 30)$54450Amorti.pdf
a)Notesb)Equity income accrual—2015 ($181,500 × 30)$54450Amorti.pdfkrram1989
 
(1) Euclids Elements was used as the primary math textbook fro.pdf
(1) Euclids Elements was used as the primary math textbook fro.pdf(1) Euclids Elements was used as the primary math textbook fro.pdf
(1) Euclids Elements was used as the primary math textbook fro.pdfkrram1989
 
A unicellular green alga somehow failed to separate into two daughte.pdf
A unicellular green alga somehow failed to separate into two daughte.pdfA unicellular green alga somehow failed to separate into two daughte.pdf
A unicellular green alga somehow failed to separate into two daughte.pdfkrram1989
 
5 cap and polyadenylationPost-transcriptional mRNA modification.pdf
5 cap and polyadenylationPost-transcriptional mRNA modification.pdf5 cap and polyadenylationPost-transcriptional mRNA modification.pdf
5 cap and polyadenylationPost-transcriptional mRNA modification.pdfkrram1989
 
Ethyl 4-aminobenzoate is partially soluble in water. Generally, org.pdf
  Ethyl 4-aminobenzoate is partially soluble in water.  Generally, org.pdf  Ethyl 4-aminobenzoate is partially soluble in water.  Generally, org.pdf
Ethyl 4-aminobenzoate is partially soluble in water. Generally, org.pdfkrram1989
 
12) Urethritis is the inflammation of the urethra (tube that takes u.pdf
12) Urethritis is the inflammation of the urethra (tube that takes u.pdf12) Urethritis is the inflammation of the urethra (tube that takes u.pdf
12) Urethritis is the inflammation of the urethra (tube that takes u.pdfkrram1989
 
1. Legionnaires disease is caused by Legionella pneumophila. It is.pdf
1. Legionnaires disease is caused by Legionella pneumophila. It is.pdf1. Legionnaires disease is caused by Legionella pneumophila. It is.pdf
1. Legionnaires disease is caused by Legionella pneumophila. It is.pdfkrram1989
 
1) alkyl group, like CH3, is a better electron-releasing groupthan H.pdf
1) alkyl group, like CH3, is a better electron-releasing groupthan H.pdf1) alkyl group, like CH3, is a better electron-releasing groupthan H.pdf
1) alkyl group, like CH3, is a better electron-releasing groupthan H.pdfkrram1989
 
The effect of acid deposition is basically the ef.pdf
                     The effect of acid deposition is basically the ef.pdf                     The effect of acid deposition is basically the ef.pdf
The effect of acid deposition is basically the ef.pdfkrram1989
 
0.025L 0.75molL acid - 0.02795L 0.5 molL base used to neutrali.pdf
0.025L  0.75molL acid - 0.02795L  0.5 molL base used to neutrali.pdf0.025L  0.75molL acid - 0.02795L  0.5 molL base used to neutrali.pdf
0.025L 0.75molL acid - 0.02795L 0.5 molL base used to neutrali.pdfkrram1989
 
Amphoteric means that the substance can act as ei.pdf
                     Amphoteric means that the substance can act as ei.pdf                     Amphoteric means that the substance can act as ei.pdf
Amphoteric means that the substance can act as ei.pdfkrram1989
 
Different types of Bits, bytes, and representation of information1.pdf
Different types of Bits, bytes, and representation of information1.pdfDifferent types of Bits, bytes, and representation of information1.pdf
Different types of Bits, bytes, and representation of information1.pdfkrram1989
 
ArithmeticOperationsOnMatrix.javaimport java.util.Random; import.pdf
ArithmeticOperationsOnMatrix.javaimport java.util.Random; import.pdfArithmeticOperationsOnMatrix.javaimport java.util.Random; import.pdf
ArithmeticOperationsOnMatrix.javaimport java.util.Random; import.pdfkrram1989
 
Answer- Q2-Cancer is a disease that is caused due to several fac.pdf
Answer- Q2-Cancer is a disease that is caused due to several fac.pdfAnswer- Q2-Cancer is a disease that is caused due to several fac.pdf
Answer- Q2-Cancer is a disease that is caused due to several fac.pdfkrram1989
 
ans- Matthaei’s experiment, develped a system for synthesizing prote.pdf
ans- Matthaei’s experiment, develped a system for synthesizing prote.pdfans- Matthaei’s experiment, develped a system for synthesizing prote.pdf
ans- Matthaei’s experiment, develped a system for synthesizing prote.pdfkrram1989
 
An Assembly program to find the factorial of decimal number given by.pdf
An Assembly program to find the factorial of decimal number given by.pdfAn Assembly program to find the factorial of decimal number given by.pdf
An Assembly program to find the factorial of decimal number given by.pdfkrram1989
 
A stone tool is, in the most general sense, any t.pdf
                     A stone tool is, in the most general sense, any t.pdf                     A stone tool is, in the most general sense, any t.pdf
A stone tool is, in the most general sense, any t.pdfkrram1989
 

More from krram1989 (17)

a)Notesb)Equity income accrual—2015 ($181,500 × 30)$54450Amorti.pdf
a)Notesb)Equity income accrual—2015 ($181,500 × 30)$54450Amorti.pdfa)Notesb)Equity income accrual—2015 ($181,500 × 30)$54450Amorti.pdf
a)Notesb)Equity income accrual—2015 ($181,500 × 30)$54450Amorti.pdf
 
(1) Euclids Elements was used as the primary math textbook fro.pdf
(1) Euclids Elements was used as the primary math textbook fro.pdf(1) Euclids Elements was used as the primary math textbook fro.pdf
(1) Euclids Elements was used as the primary math textbook fro.pdf
 
A unicellular green alga somehow failed to separate into two daughte.pdf
A unicellular green alga somehow failed to separate into two daughte.pdfA unicellular green alga somehow failed to separate into two daughte.pdf
A unicellular green alga somehow failed to separate into two daughte.pdf
 
5 cap and polyadenylationPost-transcriptional mRNA modification.pdf
5 cap and polyadenylationPost-transcriptional mRNA modification.pdf5 cap and polyadenylationPost-transcriptional mRNA modification.pdf
5 cap and polyadenylationPost-transcriptional mRNA modification.pdf
 
Ethyl 4-aminobenzoate is partially soluble in water. Generally, org.pdf
  Ethyl 4-aminobenzoate is partially soluble in water.  Generally, org.pdf  Ethyl 4-aminobenzoate is partially soluble in water.  Generally, org.pdf
Ethyl 4-aminobenzoate is partially soluble in water. Generally, org.pdf
 
12) Urethritis is the inflammation of the urethra (tube that takes u.pdf
12) Urethritis is the inflammation of the urethra (tube that takes u.pdf12) Urethritis is the inflammation of the urethra (tube that takes u.pdf
12) Urethritis is the inflammation of the urethra (tube that takes u.pdf
 
1. Legionnaires disease is caused by Legionella pneumophila. It is.pdf
1. Legionnaires disease is caused by Legionella pneumophila. It is.pdf1. Legionnaires disease is caused by Legionella pneumophila. It is.pdf
1. Legionnaires disease is caused by Legionella pneumophila. It is.pdf
 
1) alkyl group, like CH3, is a better electron-releasing groupthan H.pdf
1) alkyl group, like CH3, is a better electron-releasing groupthan H.pdf1) alkyl group, like CH3, is a better electron-releasing groupthan H.pdf
1) alkyl group, like CH3, is a better electron-releasing groupthan H.pdf
 
The effect of acid deposition is basically the ef.pdf
                     The effect of acid deposition is basically the ef.pdf                     The effect of acid deposition is basically the ef.pdf
The effect of acid deposition is basically the ef.pdf
 
0.025L 0.75molL acid - 0.02795L 0.5 molL base used to neutrali.pdf
0.025L  0.75molL acid - 0.02795L  0.5 molL base used to neutrali.pdf0.025L  0.75molL acid - 0.02795L  0.5 molL base used to neutrali.pdf
0.025L 0.75molL acid - 0.02795L 0.5 molL base used to neutrali.pdf
 
Amphoteric means that the substance can act as ei.pdf
                     Amphoteric means that the substance can act as ei.pdf                     Amphoteric means that the substance can act as ei.pdf
Amphoteric means that the substance can act as ei.pdf
 
Different types of Bits, bytes, and representation of information1.pdf
Different types of Bits, bytes, and representation of information1.pdfDifferent types of Bits, bytes, and representation of information1.pdf
Different types of Bits, bytes, and representation of information1.pdf
 
ArithmeticOperationsOnMatrix.javaimport java.util.Random; import.pdf
ArithmeticOperationsOnMatrix.javaimport java.util.Random; import.pdfArithmeticOperationsOnMatrix.javaimport java.util.Random; import.pdf
ArithmeticOperationsOnMatrix.javaimport java.util.Random; import.pdf
 
Answer- Q2-Cancer is a disease that is caused due to several fac.pdf
Answer- Q2-Cancer is a disease that is caused due to several fac.pdfAnswer- Q2-Cancer is a disease that is caused due to several fac.pdf
Answer- Q2-Cancer is a disease that is caused due to several fac.pdf
 
ans- Matthaei’s experiment, develped a system for synthesizing prote.pdf
ans- Matthaei’s experiment, develped a system for synthesizing prote.pdfans- Matthaei’s experiment, develped a system for synthesizing prote.pdf
ans- Matthaei’s experiment, develped a system for synthesizing prote.pdf
 
An Assembly program to find the factorial of decimal number given by.pdf
An Assembly program to find the factorial of decimal number given by.pdfAn Assembly program to find the factorial of decimal number given by.pdf
An Assembly program to find the factorial of decimal number given by.pdf
 
A stone tool is, in the most general sense, any t.pdf
                     A stone tool is, in the most general sense, any t.pdf                     A stone tool is, in the most general sense, any t.pdf
A stone tool is, in the most general sense, any t.pdf
 

Recently uploaded

Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Recently uploaded (20)

Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

#includeiostream #includefstreamusing namespace std; glo.pdf

  • 1. #include #include using namespace std; //global variable declaration int a[10]; int active, size; void menu() {//prints menu cout << "menu" << endl; cout << "1.Insert "Insert" key" << endl; //code 45 cout << "2.Delete "Delete" key" << endl; //code 46 cout << "3.Sort "F2" key" << endl; //code 113 cout << "4.Select "Down Arrow" key" << endl; //code 40 cout << "5.Move Right "Right Arrow" key" << endl; //code 39 cout << "6.Move Left "Left Arrow" key" << endl; //code 37 cout << "7.Exit "F1" key" << endl; //code 112 cout << "press the required key or number to continue" << endl; } //reads the data from file void readdata() { ifstream f; f.open("F://MyFile.txt"); if (f.is_open()) { f>>size; f>>active; if (size > 10) { cout << "Numbers exceeds array limit"; return; } else { for (int i = 0; i < size; i++) { f >> a[i]; } } f.close(); } }
  • 2. //sorts the data void sort() { //sorting using bubble sort int pass = 0, so = 0, t, i; while ((pass <= size - 1) && (so == 0)) { so = 1; for (i = 0; i < size - 1 - pass; i++) { if (a[i] > a[i + 1]) { t = a[i]; a[i] = a[i + 1]; a[i + 1] = t; so = 0; } } pass = pass + 1; } } //prints the data void print() { cout<<" "; for (int i = 0; i < size; i++) { cout << a[i] << "t"; } cout << "Active=" << active << endl; } //writes the data into the file void writedata() { ofstream f; f.open("F://MyFile.txt"); f << size << endl; f << active << endl; for (int i = 0; i < size; i++) { f << a[i] << " "; } f.close(); }
  • 3. //inserts an element in array and makes it active void insert() { if (size == 10)//checks if the list is full cout << "list is full"; else { int x, i; cout << "Enter a number to insert: ";//takes user input cin>>x; for (i = 0; i < size; i++) { if (a[i] == active)//finds active index break; } size++;//increment the size int y = size; while (y != i) {//shifting a[y] = a[y - 1]; y--; } a[i] = x;//insert active = x;//sets active } } //deletes the active value and sets the next one as active void del() { int i; for (i = 0; i < size; i++) {//finds active index if (a[i] == active) break; } active = a[i + 1]; //sets the next one as active while (i < size - 1) {//shifting a[i] = a[i + 1]; i++; } size--;//decrements the size }
  • 4. //changes the active value void select() { int i; for (i = 0; i < size; i++) { if (a[i] == active)//finds active index break; } if (i == size - 1) active = a[0]; //selects the first one as active else active = a[i + 1]; //sets the next one as active } //moves the active value to its left void moveleft() { int i; for (i = 0; i < size; i++) { if (a[i] == active) break; } if (i == 0) cout << "moving left is not possible"; //selects the first one as active else { int temp = a[i - 1]; a[i-1]=a[i]; a[i]=temp; //moves the active value to the left of the previous element by swapping } } //moves the active value to its right void moveright() { int i; for (i = 0; i < size; i++) { if (a[i] == active) break; } if (i == size - 1)
  • 5. cout << "moving right is not possible"; //selects the first one as active else { int temp = a[i + 1]; a[i+1]=a[i]; a[i]=temp; //moves the active value to the right of the next element by swapping } } int main() { int ch; readdata(); print(); menu(); while (1) { // switch (getchar()) {//keyboard key input // case 45: // insert(); // print(); // break; // case 46: // del(); // print(); // break; // case 113: // sort(); // print(); // break; // case 40: // down(); // print(); // break; // case 39: // right(); // print(); // break; // case 37:
  • 6. // left(); // print(); // break; // case 112: // print(); // writedata(); // return 0; // break; // default: // cout << "Invalid key" << endl; // } cin>>ch; switch (ch) {//numeric input case 1: insert(); print(); break; case 2: del(); print(); break; case 3: sort(); print(); break; case 4: select(); print(); break; case 5: moveright(); print(); break; case 6: moveleft(); print();
  • 7. break; case 7: print(); writedata(); return 0; break; default: cout << "Invalid key" << endl; } menu(); } return 0; } Solution #include #include using namespace std; //global variable declaration int a[10]; int active, size; void menu() {//prints menu cout << "menu" << endl; cout << "1.Insert "Insert" key" << endl; //code 45 cout << "2.Delete "Delete" key" << endl; //code 46 cout << "3.Sort "F2" key" << endl; //code 113 cout << "4.Select "Down Arrow" key" << endl; //code 40 cout << "5.Move Right "Right Arrow" key" << endl; //code 39 cout << "6.Move Left "Left Arrow" key" << endl; //code 37 cout << "7.Exit "F1" key" << endl; //code 112 cout << "press the required key or number to continue" << endl; } //reads the data from file void readdata() { ifstream f;
  • 8. f.open("F://MyFile.txt"); if (f.is_open()) { f>>size; f>>active; if (size > 10) { cout << "Numbers exceeds array limit"; return; } else { for (int i = 0; i < size; i++) { f >> a[i]; } } f.close(); } } //sorts the data void sort() { //sorting using bubble sort int pass = 0, so = 0, t, i; while ((pass <= size - 1) && (so == 0)) { so = 1; for (i = 0; i < size - 1 - pass; i++) { if (a[i] > a[i + 1]) { t = a[i]; a[i] = a[i + 1]; a[i + 1] = t; so = 0; } } pass = pass + 1; } } //prints the data void print() { cout<<" "; for (int i = 0; i < size; i++) {
  • 9. cout << a[i] << "t"; } cout << "Active=" << active << endl; } //writes the data into the file void writedata() { ofstream f; f.open("F://MyFile.txt"); f << size << endl; f << active << endl; for (int i = 0; i < size; i++) { f << a[i] << " "; } f.close(); } //inserts an element in array and makes it active void insert() { if (size == 10)//checks if the list is full cout << "list is full"; else { int x, i; cout << "Enter a number to insert: ";//takes user input cin>>x; for (i = 0; i < size; i++) { if (a[i] == active)//finds active index break; } size++;//increment the size int y = size; while (y != i) {//shifting a[y] = a[y - 1]; y--; } a[i] = x;//insert active = x;//sets active }
  • 10. } //deletes the active value and sets the next one as active void del() { int i; for (i = 0; i < size; i++) {//finds active index if (a[i] == active) break; } active = a[i + 1]; //sets the next one as active while (i < size - 1) {//shifting a[i] = a[i + 1]; i++; } size--;//decrements the size } //changes the active value void select() { int i; for (i = 0; i < size; i++) { if (a[i] == active)//finds active index break; } if (i == size - 1) active = a[0]; //selects the first one as active else active = a[i + 1]; //sets the next one as active } //moves the active value to its left void moveleft() { int i; for (i = 0; i < size; i++) { if (a[i] == active) break; } if (i == 0) cout << "moving left is not possible"; //selects the first one as active
  • 11. else { int temp = a[i - 1]; a[i-1]=a[i]; a[i]=temp; //moves the active value to the left of the previous element by swapping } } //moves the active value to its right void moveright() { int i; for (i = 0; i < size; i++) { if (a[i] == active) break; } if (i == size - 1) cout << "moving right is not possible"; //selects the first one as active else { int temp = a[i + 1]; a[i+1]=a[i]; a[i]=temp; //moves the active value to the right of the next element by swapping } } int main() { int ch; readdata(); print(); menu(); while (1) { // switch (getchar()) {//keyboard key input // case 45: // insert(); // print(); // break; // case 46: // del();
  • 12. // print(); // break; // case 113: // sort(); // print(); // break; // case 40: // down(); // print(); // break; // case 39: // right(); // print(); // break; // case 37: // left(); // print(); // break; // case 112: // print(); // writedata(); // return 0; // break; // default: // cout << "Invalid key" << endl; // } cin>>ch; switch (ch) {//numeric input case 1: insert(); print(); break; case 2: del(); print(); break;
  • 13. case 3: sort(); print(); break; case 4: select(); print(); break; case 5: moveright(); print(); break; case 6: moveleft(); print(); break; case 7: print(); writedata(); return 0; break; default: cout << "Invalid key" << endl; } menu(); } return 0; }