C program for storage representation of 2-D array?
Wright a 'C' program for storage representation of 2-D array.
The following example sets up a two-dimensional array, initialises it with some pseudo-random data, and then prints the table and the averages.
#include<iostream>
#include<time.h>
int main()
{
const int max_students = 7;
const int max_student_grades = 5;
const int max_grades = 6;
const char grade[max_grades]={'A','B','C','D','E','F'};
srand((unsigned) time(NULL));
// Initialise the array with pseudo-random grades:
int table[max_students][max_student_grades];
for(int student=0; student<max_students; ++student)
{
for(int student_grade=0; student_grade<max_student_grades; ++student_grade)
{
table[student][student_grade] = rand()%max_grades;
}
}
// Print the table and average the results.
int overall=0;
for(int student=0; student<max_students; ++student)
{
int average=0;
std::cout<<"Student #"<<student+1;
for(int student_grade=0; student_grade<max_student_grades; ++student_grade)
{
std::cout<<" Grade #"<<student_grade+1<<": "<<grade[table[student][student_grade]]<<", ";
average+=table[student][student_grade];
}
std::cout<<" Average: "<<grade[average/max_grades]<<std::endl;
overall+=average;
}
std::cout<<"Overall average: "<<grade[overall/max_grades/max_students]<<std::endl;
return(0);
}
Example output:
Student #1 Grade #1: A, Grade #2: E, Grade #3: D, Grade #4: E, Grade #5: F, Average: C
Student #2 Grade #1: E, Grade #2: D, Grade #3: E, Grade #4: E, Grade #5: E, Average: D
Student #3 Grade #1: D, Grade #2: A, Grade #3: D, Grade #4: B, Grade #5: A, Average: B
Student #4 Grade #1: C, Grade #2: B, Grade #3: A, Grade #4: A, Grade #5: B, Average: A
Student #5 Grade #1: E, Grade #2: D, Grade #3: C, Grade #4: F, Grade #5: E, Average: D
Student #6 Grade #1: C, Grade #2: D, Grade #3: A, Grade #4: F, Grade #5: A, Average: B
Student #7 Grade #1: B, Grade #2: D, Grade #3: F, Grade #4: B, Grade #5: C, Average: C
Overall average: C
Abstract data types (ADTs) are defined by base class designers. An ADT differs from an ordinary base class in that it has a pure-virtual interface. As with all base classes, the protected interface is intended for use by class implementers while the public interface is intended for all programmers (consumers).
All member data should be declared private. Even if there is no invariant associated with the data, declaring it private and providing a public interface ensures that any changes to the class representation will not affect consumers. Member data is an implementation detail that should be of no concern to either the class implementer or the consumer. Protected member data should always be treated with suspicion as this essentially exposes an implementation detail to implementers that could undermine encapsulation. Abstract data types in particular should have few data members, preferably none at all.
Class implementers are only concerned with the protected and public interfaces of their bass classes. Protected interfaces should be fully-documented as the implementer needs to know which methods need to be overridden and for what reason. A common convention is to place the protected interface default implementations in a separate translation unit, typically with a "_impl" suffix. This helps implementers examine the implementation details and thus eliminate redundant/duplicate code from their overrides. Nevertheless, a well-defined interface should be self-documenting and intuitive; the class header file should provide all the documentation necessary for an implementer or consumer to use the class without the need to examine the implementation details.
piping critical , non critical critical piping : where temperature ,pressure are high and sizes of pipe are big and piping connected to critical equipment( such pump,turbine compressor etc) non critical : other than criti
What is traverse technique used in chain survey?
1. pre-order b-tree traversal.
2. in-order b-tree traversal.
3. post-order b-tree traversal
What is the meaning of code has no effect in function main in c language?
When the compiler says "code has no effect", it is saying that it does not matter if the code is executed or not - the end result will be the same. The compiler, if in optimizing mode, can and should delete the code. An example of code that has no effect is a = a;
How many different versions of the Bantu language are there?
Other Bantu languages include
* in Central and Eastern Africa o Swahili o Lingala o Luganda o Gĩkũyũ o Bukusu o Lusoga o Kikongo o Chichewa o Chiyao o Kihaya o Kichagga o Kinyarwanda o Kirundi * in Southern Africa o Shona o Ndebele (Sindebele) o Tswana (Setswana) o Sesotho o Zulu (isiZulu) o Xhosa o Sepedi o Swazi * in West Africa o Ngumba (Cameroon) o Kako (Cameroon) o Basaa (Cameroon)
Some are usually known in English without the class prefix (Swahili instead of Kiswahili, etc.), and some others vary (Setswana or Tswana, Sindebele or Ndebele, etc.). The bare form typically does not occur in the language: in the country of Botswana the people are the Batswana, one person is a Motswana, and the language is Setswana.
Today most linguists see the center of the Bantu expansion, that started about 2000 years before present in eastern Nigeria and Cameroon.[edit]
(Narrow) Bantu languages
* Bemba * Songa * Northwest o Zone A o Zone B o Zone C * Central o Zone D (Lengola, Enya, Mbole, Mituku, Bembe, Buyu, Nyanga, Bhele (Piri), Bila, Bodo, Bera (Bira), Budu, Homa, Kaiku, Komo, Kango, Ndaka, Nyali, Amba, Vanuma, Mbo, Kare, Bali, Beeke, Hamba, Holoholo, Kanu, Kwami, Shabunda-Lega, Mwenga-Lega, Lika, Songoora (Dialects: Gengele, North Binja, South Binja), Zimba) o Zone E (Gweno, Kahe, Chaga (Chaga languages: Machame Mochi, Rombo, Vunjo), Rusa, Malakote, Chonyi, Digo, Duruma, Giryama (Nyika), Segeju, Pokomo (Upper and Lower), Taita, Sagalia, Logoli, Kabwa, Gusii, Ikizu, Kuria, Ngurimi, Ikoma (Nata), Temi (Sonjo), Suba, Sizaki, Ware, Zanaki, Dhaiso, Embu, Gikuyu, Chuka, Meru, Tharaka, Mwimbi, Muthambi) o Zone F (Bende, Fipa, Mambwe, Lungu, Pimbwe, Rungwa, Tongwe, Konongo, Kimbu, Nyamwezi, Sukuma, Sumbwa, Bungu, Langi, Mbugwe, Nilamba, Nyaturu (Rimi), Mbugu) o Zone G o Zone H o Zone J o Zone K o Zone L (Bwile, Kaonde, Nkoya, Mbwera, Bangubangu, Binji, Kete, Luna, Songe, Mbagani, Budya, Hemba, Kanyok, Luba-Kasai, Luba-Katanga, Lwalu, Sanga) o Zone M o Zone N (Manda, Mantengo, Ngoni, Tonga, Mpoto, Nyanja, Tumbuka, Nsenga, Barwe, Kunda, Nyungwe, Phimbi, Sena, Malawi Sena, Podzo, Rue) o Zone P (Yao, Mwera, Makonde, Machinga, Nyasa, Mabiha, Ndonde Hamba, Ndendeule, Matumbi, Mbunga, Ndengereko, Ngindo, Nindi, Rufiji, Chuwabu, Maindo, Koti, Kokola, Lolo, Manyawa, Lomwe, Ngulu, Marenje, Takwane, Makua, Makhuwa-Meetto, Makhuwa-Moniga, Makhuwa-Shirima, Makhuwa-Marrevone, Makhuwa-Saka) o Zone R (Herero, Zemba, Yeyi, Umbundu (South Mbundu), Ndombe, Nyaneka, Nkhumbi, Kwanyama, Ndonga, Kwambi, Ngandyera, Mbalanhu) o Zone S (Dema, Kalanga, Manyika, Ndau, Nambya, Shona, Zezuru, Tawara, Tewe, Chopi, Tonga-Inhambane, Ronga Tsonga, Tonga, Tswa, Venda, Swati (Swazi), Xhosa, Zulu, Zimbabwe Ndebele, North Transvaal Ndebele, South Transvaal Ndebele, Northern Sotho, Southern Sotho, Birwa, Kgalagadi, Lozi, Tswana, Tswapong) o Unclassified (Boguru, Gbati-ri, Isanzu, Ngbee, Kari, Mayeka, Ngbinda, Nyanga-li, Songo)
[edit]
Some Bantu words in popular Western culture
* Samba * Banjo * Rumba * Conga * Mambo * Zombie * Bongos * Gumbo * Jumbo * La Bamba * Marimba
Program to display multiplication table for given number?
#include<stdio.h>
main()
{
int i,n;
clrscr();
printf("enter the value");
scanf("%d", &n);
while(i<=10)
{
printf("\n %d*%d=%d",n,i,(i*n));
i++;
}
getch();
}
What is the C plus plus Algorithm for Knapsack Problem?
#include<iostream>
#include<vector>
#include<cassert>
template<typename _Ty>
class subset
{
public:
using value_type = typename _Ty::const_iterator;
using container_type = std::vector<value_type>;
using iterator = typename container_type::iterator;
using const_iterator = typename container_type::const_iterator;
using reverse_iterator = typename container_type::reverse_iterator;
using const_reverse_iterator = typename container_type::const_reverse_iterator;
using size_type = typename container_type::size_type;
~subset (void) {};
explicit subset (const _Ty&);
subset (const subset&) = delete;
subset (subset&&) = delete;
subset& operator= (const subset&) = delete;
subset& operator= (subset&&) = delete;
const container_type& first (size_type);
const container_type& next (void);
private:
size_type m_size; // desired size of the subset
container_type m_set; // iterators to the full set
container_type m_subset; // subset of the full set of iterators
const_iterator find (const value_type&) const;
const bool get_next (const bool = true);
};
template<typename _Ty>
inline subset<_Ty>::subset (const _Ty& set):
m_size {set.size()}, m_set {}, m_subset {}
{
for (value_type it=set.begin(); it!=set.end(); ++it)
m_set.push_back (it);
m_set.shrink_to_fit();
}
template<typename _Ty>
inline typename subset<_Ty>::const_iterator subset<_Ty>::find (
const value_type& value) const
{
const_iterator it=m_set.begin();
while (it!=m_set.end() && *it!=value) ++it;
return it;
}
template<typename _Ty>
inline const typename subset<_Ty>::container_type& subset<_Ty>::first (
size_type count)
{
assert (count <= m_set.size());
m_size = count;
m_subset.clear();
for (const_iterator it=m_set.begin(); count--; ++it)
m_subset.push_back (*it);
return m_subset;
}
template<typename _Ty>
inline const bool subset<_Ty>::get_next (
const bool pop /* = true */)
{
const_reverse_iterator sub_it = m_subset.rbegin();
const_iterator set_it = find (*sub_it);
if (pop)
m_subset.pop_back();
if (++set_it != m_set.end())
m_subset.push_back (*set_it);
return m_subset.size() 1U)
return m_subset;
const value_type value = m_set.back();
m_set.pop_back();
--m_size;
next();
m_set.push_back (value);
if (m_size++ != m_subset.size())
return m_subset;
get_next (false);
return m_subset;
}
struct item
{
size_t value {0};
size_t weight {0};
item (size_t v=0, size_t w=0): value{v}, weight{w} {}
};
using vector = std::vector<item>;
item sum (vector& v)
{
item result;
for( auto i : v)
{
result.weight += i.weight;
result.value += i.value;
}
return result;
}
vector knapsack (vector items, size_t capacity)
{
vector v;
subset<vector> set {items};
for (size_t n=items.size(); n; --n)
{
subset<vector>::container_type selection {set.first (n)};
for (; selection.size(); selection=set.next())
{
vector t;
for (auto i : selection)
{
t.push_back (*i);
}
item s = sum (t);
if (s.weight <= capacity && sum(v).value < s.value)
v = t;
}
}
return v;
}
int main()
{
size_t capacity {4};
vector items {{1,8},{2,4},{3,1},{2,5},{2,3}};
vector rucksack = knapsack (items, capacity);
std::cout << "Items:\n" << std::endl;
for (auto i : items)
std::cout << '£' << i.value << '\t' << i.weight << "kg" << std::endl;
std::cout << std::endl;
std::cout << "Optimal selection for capacity " << capacity << "kg\n" << std::endl;
for (auto r : rucksack)
std::cout << '£' << r.value << '\t' << r.weight << "kg" << std::endl;
std::cout << std::endl;
item s = sum (rucksack);
std::cout << "Total value and weight:\n" << std::endl;
std::cout << '£' << s.value << '\t' << s.weight << "kg" << std::endl;
std::cout << std::endl;
}
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main()
{
cout << "Enter name of your favorite TV show: \n";
string tvShow = "";
cin >> tvShow;
for (int i = 0; i < 15; i++)
{
cout << endl << tvShow;
}
cout << endl << endl;
system("PAUSE");
return 0;
}
Algorithm bit_count is:
Input: an integer n, such that n >= 0
Output: the minimum number of binary digits (bits) required to represent n
let count := 0;
repeat {
n := n / 2; // integer division: ignore any remainder
count := count + 1;
} until n = 0;
return count;
This works because each binary digit represents an increasing power of 2, starting from 2^0. Thus if we repeatedly divide a value by 2 until the result is 0, the total number of divisions tells us the minimum number of bits required to represent the value.
Take the value 42 as an example:
42 / 2 = 21
21 / 2 = 10 (r 1)
10 / 2 = 5
5 / 2 = 2 (r 1)
2 / 2 = 1
1 / 2 = 0 (r 1)
That's 6 divisions in total so we need at least 6 binary digits to represent 42 in binary. Given that 42 is 101010 in binary, this is correct.
Let's try 31:
31 / 2 = 15 (r 1)
15 / 2 = 7 (r 1)
7 / 2 = 3 (r 1)
3 / 2 = 1 (r 1)
1 / 2 = 0 (r 1)
5 divisions so 5 bits. 31 in binary is 11111, so that's also correct. 11111 is also the maximum value we can represent with just 5 bits so it follows that 32 would need 6 bits:
32 / 2 = 16
16 / 2 = 8
8 / 2 = 4
4 / 2 = 2
2 / 2 = 1
1 / 2 = 0 (r 1)
QED
What do you mean by searching technique?
"Searching technique" defines the way in which we look for a given value within a set of values. We define these techniques using algorithms.
Searching is always quicker when the data is in sorted order. We start in the middle of the set. If that's our value, we're done. Otherwise, we compare the middle value with the value we seek to determine which side of the set contains our value. We then discard the other half and repeat the process with the remaining half. If the remaining half is empty, the value does not exist.
This technique is known as a binary search and can be performed efficiently on any container that permits constant-time random-access, such as an array. Balanced binary trees can also be used. Lists do not support constant-time random-access so the benefit of binary search is often outweighed by added complexity of identifying the middle element of a range.
If the data is unsorted, we must use a linear search. Typically we start at the first element and work our way through to the last element, stopping when we find the value or reach the end of the sequence. Linear search can be performed on any container that allows forward traversal, including arrays and lists.
The return value of a search algorithm is typically an iterator; a pointer to the element or node that holds the value. If the value does not exist, we typically return an iterator to the one-past-the-end of the sequence. In the case of arrays we could return the zero-based index of the value, returning the count of elements when the value does not exist, however it is better to use iterators as this allows us to generalise our algorithms to cater for all container types.
Which type of data structure is used in ATM to take the printout of last 5 transactions?
stack data structure.
What is the language for zalig kerstfeest?
It is Dutch, the language spoken in The Netherlands. A dialect of Dutch is also used in the northern (Flemish) part of Belgium.
Mind storming is basically the same thing as brain storming. It sets the stage for letting your creative juices call forth suggestions for your writing as well as ways to improve your fortune and productivity.
Evaluate the expression sine 30 degree cosecant 30 degree?
Sin(30) + cosec(30) = sin(30) + 1/sin(30) = 0.5 + 1/0.5 = 0.5 + 2 = 2.5
SIC assembler pass 1 C program?
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void chk_label();
void chk_opcode();
void READ_LINE();
struct optab
{
char code[10],objcode[10];
}myoptab[3]={
{"LDA","00"},
{"JMP","01"},
{"STA","02"}
};
struct symtab{
char symbol[10];
int addr;
}mysymtab[10];
int startaddr,locctr,symcount=0,length;
char line[20],label[8],opcode[8],operand[8],programname[10];
void PASS1()
{
FILE *input,*inter;
input=fopen("input.txt","r");
inter=fopen("inter.txt","w");
printf("LOCATION LABEL\tOPERAND\tOPCODE\n");
printf("_____________________________________");
fgets(line,20,input);
READ_LINE();
if(!strcmp(opcode,"START"))
{
startaddr=atoi(operand);
locctr=startaddr;
strcpy(programname,label);
fprintf(inter,"%s",line);
fgets(line,20,input);
}
else
{
programname[0]='\0';
startaddr=0;
locctr=0;
}
printf("\n %d\t %s\t%s\t %s",locctr,label,opcode,operand);
while(strcmp(line,"END")!=0)
{
READ_LINE();
printf("\n %d\t %s \t%s\t %s",locctr,label,opcode,operand);
if(label[0]!='\0')
chk_label();
chk_opcode();
fprintf(inter,"%s %s %s\n",label,opcode,operand);
fgets(line,20,input);
}
printf("\n %d\t\t%s",locctr,line);
fprintf(inter,"%s",line);
fclose(inter);
fclose(input);
}
void READ_LINE()
{
char buff[8],word1[8],word2[8],word3[8];
int i,j=0,count=0;
label[0]=opcode[0]=operand[0]=word1[0]=word2[0]=word3[0]='\0';
for(i=0;line[i]!='\0';i++)
{
if(line[i]!=' ')
buff[j++]=line[i];
else
{
buff[j]='\0';
strcpy(word3,word2);
strcpy(word2,word1);
strcpy(word1,buff);
j=0;
count++;
}
}
buff[j-1]='\0';
strcpy(word3,word2);
strcpy(word2,word1);
strcpy(word1,buff);
switch(count)
{
case 0:strcpy(opcode,word1);
break;
case 1:strcpy(opcode,word2);
strcpy(operand,word1);
break;
case 2:strcpy(label,word3);
strcpy(opcode,word2);
strcpy(operand,word1);
break;
}
}
void chk_label()
{
int k,dupsym=0;
for(k=0;k<symcount;k++)
if(!strcmp(label,mysymtab[k].symbol))
{
mysymtab[k].addr=-1;
dupsym=1;
break;
}
if(!dupsym)
{
strcpy(mysymtab[symcount].symbol,label);
mysymtab[symcount++].addr=locctr;
}
}
void chk_opcode()
{
int k=0,found=0;
for(k=0;k<3;k++)
if(!strcmp(opcode,myoptab[k].code))
{
locctr+=3;
found=1;
break;
}
if(!found)
{
if(!strcmp( opcode,"WORD"))
locctr+=3;
else if (!strcmp(opcode,"RESW"))
locctr+=(3*atoi(operand));
else if(!strcmp(opcode,"RESB"))
locctr+=atoi(operand);
}
}
int main()
{
PASS1();
length=locctr-startaddr;
}
Write a program in c to implement scan-line polygon filling algorithm?
#include<GL/glut.h>
float x1,x2,x3,x4,y1,y2,y3,y4;
void draw_pixel(int x,int y)
{
glColor3f(0.5,0.0,1.0);
glPointSize(0.5);
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
}
void edgedetect(float x1,float y1,float x2,float y2,int *le,int *re)
{
float temp,x,mx;
int i;
if(y1>y2)
{
temp=x1,x1=x2,x2=temp;
temp=y1,y1=y2,y2=temp;
}
if(y1==y2)
mx=x2-x1;
else
mx=(x2-x1)/(y2-y1);
x=x1;
for(i=int(y1);i<=(int)y2;i++)
{
if(x<(float)le[i]) le[i]=(int)x;
if(x>(float)re[i]) re[i]=(int)x;
x+=mx;
}
}
void scanfill(float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4)
{
int le[500],re[500],i,j;
for(i=0;i<500;i++)
le[i]=500,re[i]=0;
edgedetect(x1,y1,x2,y2,le,re);
edgedetect(x2,y2,x3,y3,le,re);
edgedetect(x3,y3,x4,y4,le,re);
edgedetect(x4,y4,x1,y1,le,re);
for(j=0;j<500;j++)
{
if(le[j]<=re[j])
for(i=le[j];i<re[j];i++)
draw_pixel(i,j);
}
}
void display()
{
x1=250.0;y1=200.0;x2=150.0;y2=300.0;x3=250.0;
y3=400.0;x4=350.0;y4=300.0;
glBegin(GL_TRIANGLES);
glVertex2f(x1,y1);
glVertex2f(x2,y2);
glVertex2f(x3,y3);
glVertex2f(x4,y4);
glEnd();
scanfill(x1,y1,x2,y2,x3,y3,x4,y4);
glFlush();
}
void init()
{
glClearColor(1.0,1.0,1.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,499.0,0.0,499.0);
}
void main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutCreateWindow("scanline");
glutDisplayFunc(display);
init();
glutMainLoop();
}
put a counter in. set it to zero before the loop. add 1 to it inside the loop pick a realistic number for how many times it could possibly go through legitamately and have it exit the loop if the counter goes above that.
or if you do not have duplicate data each time through the loop save the data compare it the next time through and if it is the same 2 or 3 times in a row abort the loop.
What converts high level language to machine language?
Converting machine language to a high-level language is very difficult. It is not possible to convert machine language back to the original high-level source code because there are an infinite number of source code files that can produce any given machine language output. For example, machine language uses memory addresses or stack locations to store variables, so all variable names used in the source code are lost and cannot be regenerated.
There are some reverse compiler tools that can produce a probable high level language file from machine language. And some machine code file formats store information about source code for debugging or tracing, and when available, that information can be very useful to reverse-compile machine code.
It is also possible to generate an assembly language file that is close to the machine code, and although that is not high-level it is more human readable.
What is deference operator in c?
There is no deference operator in C or C++.
However, the language supports references, and supports accessing values through pointers. The latter is sometimes called dereferencing.
Consider P to be a pointer to V. The asterisk is used to dereference V through P, that is, to access V: *P = 5 assigns value 5 to V (again, provided P points to V).
Note that the asterisk has different meanings in the C language, depending on the context in which it is used.
Now consider P to be a pointer to a structure S with members S.A and S.B. The right arrow operator can be used to dereference members S.A and S.B through P: P->A = 5; P->B = 13; assigns 5 and 13 to S.A and S.B, respectively.
The C++ language also knows a construct called references, which supports passing of arguments by reference rather than by value, without the complication and risk of pointer operations.
To declare a function argument as a reference, use the ampersand:
void example(int& v) {
v *= 2;
}
int i = 3;
void test(void) {
example(i);
}
After calling the test() function, variable i has value 6. Notice how no "referencing" operator was required in the all to the example function, and notice how the example function used the ampersand in the prototype declaration, but did not require a dedicated dereferencing operator when modifying the argument v.
Does a clothing designer have to use pantone tpx or can the use c or you?
Yeaar I like to know too :-)