Computer & Information Sciences

The HomeWork Arhiv
CIS 15 B Spring 2001


 

 

 

 

HomeWork #4    

HomeWork #5    

HomeWork #6    

HomeWork #7    

                           

HomeWork #9    

HomeWork #10  

HomeWork #11  

HomeWork #12 

HomeWork #13  

HomeWork #14  

----------------#15  

----------------#16  

----------------#17  

HomeWork #18

Problem #0

Problem #1

Problem #2

Problem #3

Problem #4

Problem #5

Problem #6

Problem #7

Problem #8

Problem #9

Problem #10

Problem #11

Problem #12

Problem #13

Problem #14

Problem #15

Problem #16

Problem #17

Problem #18


HW #4:

$ atrium41:/users2/st/user_name> x4|grep "Your_last_name"|wc
  45231  271381 2442430
$ atrium41:/users2/st/user_name> x4|uniq|grep "Your_last_name"|wc
  13335   80005  720046
$ atrium41:/users2/st/user_name> x4|wc
 3458735 3684885 220906686
answer:
45231 13335 3458735



HW #5:

my_name.c:

    #include <stdio.h>
    void main (void) {
    printf("Your_last_name\n");
    printf("user_name\r\n");
    exit(0);
    }

$ atrium41:/users2/st/user_name>acc  my_name.c
$ atrium41:/users2/st/user_name>mv  a.out my_name.x
$ atrium41:/users2/st/user_name>acc  my_name.x > my_name.OUT
$ atrium41:/users2/st/user_name>toteach 5  my_name.*



HW #6

runcode:

    #!/bin/ksh
    acc $1.c
    mv a.out $1.x
    $1.x >$1.OUT

$ atrium41:/users2/st/user_name>chmod 777 runcode
$ atrium41:/users2/st/user_name>runcode my_name           check it !
$ atrium41:/users2/st/user_name>toteach 6 runcode



HW #7

my_compare:

    #!/bin/ksh
    cmp $1 $2 > junk
    if [ $? = "0" ]; then
    print "These files are identical:" $1 $2
    else
    print "These files are different:" $1 $2
    fi

$ atrium41:/users2/st/user_name>chmod 777 my_compare
$ atrium41:/users2/st/user_name>my_compare any_file1 any_file2        check it !
$ atrium41:/users2/st/user_name>my_compare any_file1 any_file1        check it !
$ atrium41:/users2/st/user_name>toteach 7 my_compare



HW #9

File nv.h:

typedef struct {
 char name[40];
 int  value;
} NameValue;

File nv_countCommon.c:

#include "nv.h"
#include <string.h>
int nv_countCommon(NameValue A[],int ANumber,NameValue B[],int BNumber){
int i,j,y = 0;
for (i=0;i<ANumber;i++)
  for (j=0;j<BNumber;j++)
  if (strcmp(A[i].name,B[j].name)==0) y++;
 return y;
}
 

File test_nv_countCommon.c:

#include <stdio.h>
#include "nv.h"
int nv_countCommon(NameValue[],int,NameValue[],int);
int main(){
int value;
NameValue c[10]={{"dddd",120},
   {"dddd",121},
   {"dddd",122},
   {"dddd",124},
   {"dddd",125},
   {"bbbb",126},
   {"bbbb",127},
   {"bbbb",128},
   {"bbbb",128},
   {"bbbb",129}};

NameValue d[10]={{"zzzz",120},
   {"bbbb",121},
   {"zzzz",122},
   {"zzzz",124},
   {"bbbb",125},
   {"bbbb",126},
   {"zzzz",127},
   {"kkkk",127},
   {"gggg",128},
   {"zzzz",129}};

value = nv_countCommon(c,10,d,10);
printf("\n -C- %d -D- \n",value);
exit(0);
}

$ atrium41:/users2/st/user_name>acc test_nv_countCommon.c
$ atrium41:/users2/st/user_name>a.out                                          check it !

$ atrium41:/users2/st/user_name>toteach 9 test_nv_countCommon.c nv.h nv_countCommon.c


HW 10  < THIS HOMEWORK WAS NOT PASSED > ( I have version, wich was passed in this page too)
file timekeeper.h:

struct Time {
 int hr;
 int min;
 int sec;
 };
typedef struct Time Time;

void Time_set(Time *,int ,int, int);
Time Time_clr(Time *);
int Time_cmp(Time,Time);
void Time_fprintf(FILE *,Time);
void Time_fscanf(FILE *, Time *);
int Time_hoursOf(Time);
int Time_minutesOf(Time);
int Time_secondsOf(Time);
Time Time_between(Time,Time);
Time Time_endOf(Time,Time);
 

file timekeeper.c:

#include <stdio.h>
#include "timekeeper.h"

main () {
Time t1, t2, t3, t4;

Time_set(&t1,14,12,3);
Time_set(&t2,0,5,2);
t3=Time_between(t2,t1);
Time_fprintf(stdout,t3);
t4=Time_between(t1,t2);
Time_fprintf(stdout,t4);
Time_fscanf(stdin, &t3);
Time_fprintf(stdout, t3);
exit(0);
}
 
 

void Time_set(Time *t,int hr,int min, int sec){
(*t).hr=hr;
(*t).min=min;
(*t).sec=sec;
}

Time Time_clr(Time *t){
(*t).hr=0;
(*t).min=0;
(*t).sec=0;
return (*t);
}

int Time_cmp(Time t1,Time t2){
double x1,x2;
x1=t1.hr*3600+t1.min*60+t1.sec;
x2=t2.hr*3600+t2.min*60+t2.sec;
if (x1<x2) return -1;
if (x1==x2) return 0;
if (x1>x2) return 1;
}

void Time_fprintf(FILE *f,Time t){
if (t.hr<10) fprintf(f,"0");
fprintf(f,"%d:",t.hr);
if (t.min<10) fprintf(f,"0");
fprintf(f,"%d:",t.min);
if (t.sec<10) fprintf(f,"0");
fprintf(f,"%d\n",t.sec);
}

void Time_fscanf(FILE *f, Time *t){
fscanf(f,"%d",&(*t).hr);
fscanf(f,"%d",&(*t).min);
fscanf(f,"%d",&(*t).sec);
}

int Time_hoursOf(Time t){
return t.hr;
}

int Time_minutesOf(Time t){
return t.min;
}

int Time_secondsOf(Time t){
return t.sec;
}

Time Time_between(Time t1,Time t2){
double x1,x2,x3;
Time x;
x1=t1.hr*3600+t1.min*60+t1.sec;
x2=t2.hr*3600+t2.min*60+t2.sec;

x3=x2-x1;
if (x3<0) x3=-x3;
x.hr=x3/3600;
x.min=(x3-x.hr*3600)/60;
x.sec=x3-x.hr*3600-x.min*60;
return x;
}

Time Time_endOf(Time t1,Time t2){
double x1,x2,x3;
Time x;
x1=t1.hr*3600+t1.min*60+t1.sec;
x2=t2.hr*3600+t2.min*60+t2.sec;

x3=x2+x1;
x.hr=x3/3600;
x.min=(x3-x.hr*3600)/60;
x.sec=x3-x.hr*3600-x.min*60;
return x;

}



HW 10  < PASSED >
file timekeeper.h:

struct Time {
 int hr;
 int min;
 int sec;
 };
typedef struct Time Time;

void Time_set(Time *,int ,int, int);
Time Time_clr(Time *);
int Time_cmp(Time,Time);
void Time_fprintf(FILE *,Time);
void Time_fscanf(FILE *, Time *);
int Time_hoursOf(Time);
int Time_minutesOf(Time);
int Time_secondsOf(Time);
Time Time_between(Time,Time);
Time Time_endOf(Time,Time);
void Time_chk(Time *);
int timeinsec(int,int,int);

file timekeeper.c:

#include <stdio.h>
#include "timekeeper.h"
 

void Time_set(Time *t,int hr,int min, int sec){
t -> hr=hr;
t -> min=min;
t -> sec=sec;

Time_chk(t);
return;
}

Time Time_clr(Time *t){
t -> hr=0;
t -> min=0;
t -> sec=0;
return *t;
}

int Time_cmp(Time t1,Time t2){
int time1, time2;
time1 = timeinsec(t1.hr, t1.min, t1.sec);
time2 = timeinsec(t2.hr, t2.min, t2.sec);
if (time1 == time2)
  return 0;
if (time1 < time2)
  return -1;
return 1;
}

void Time_fprintf(FILE *f,Time t){
fprintf(f,"%02d:%02d:%02d",t.hr,t.min,t.sec);
return;
}

/* start of my programm */

void Time_fscanf(FILE *f, Time *t){
int hr, min, sec;

fscanf(f,"%d",&hr);
fscanf(f,"%d",&min);
fscanf(f,"%d",&sec);

t -> hr = hr;
t -> min = min;
t -> sec = sec;

Time_chk(t);
return;
}

/* end of my programm */

int Time_hoursOf(Time t){
return (t.hr);
}

int Time_minutesOf(Time t){
return (t.min);
}

int Time_secondsOf(Time t){
return (t.sec);
}

/* start of my programm */

Time Time_between(Time ta,Time tb){

Time x,z,t1,t2;
z.sec=0;
z.min=0;
z.hr=0;

t1.sec=ta.sec;
t1.min=ta.min;
t1.hr =ta.hr ;
t2.sec=tb.sec;
t2.min=tb.min;
t2.hr =tb.hr ;

if (Time_cmp(t1,t2)==-1) {
  t1.sec=tb.sec;
  t1.min=tb.min;
  t1.hr =tb.hr ;
  t2.sec=ta.sec;
  t2.min=ta.min;
  t2.hr =ta.hr ;
 }

x.sec=t1.sec-t2.sec;
if (x.sec <0 ) {
  x.sec=x.sec+60;
  z.min=1;
 }

x.min=t1.min-t2.min-z.min;
if (x.min <0 ) {
  x.min=x.min+60;
  z.hr=1;
 }

x.hr=t1.hr-t2.hr-z.hr;

return x;
}

Time Time_endOf(Time t1,Time t2){
Time x,z;
z.sec=0;
z.min=0;
z.hr=0;

x.sec=t1.sec+t2.sec;
if (x.sec >=60 ) {
  x.sec=x.sec-60;
  z.min=1;
 }

x.min=t1.min+t2.min+z.min;
if (x.min >=60 ) {
  x.min=x.min-60;
  z.hr=1;
 }

x.hr=t1.hr+t2.hr+z.hr;
return x;

}

/* end of my programm */

int timeinsec(int hr, int min, int sec){
return hr * 3600 + min *60 + sec;
}

void Time_chk(Time *t){
if (t -> hr < 0)
  t -> hr *= -1;
if (t -> min < 0)
  t -> min *= -1;
if (t -> sec < 0)
  t -> sec *= -1;
while (t -> sec > 59){
  t -> min++;
  t -> sec -=60;
 }
while (t -> min > 59){
  t -> hr++;
  t -> min -=60;
 }
}

 


HW 11

file CellValue.c:

int samecell(int *X,int *Y){
int Xi,Yi;
Xi=&*X;
Yi=&*Y;
if (Xi==Yi) return 1;
return 0;
}

int samevalue(int *X,int *Y){
if (samecell(X,Y)==0){
if (*X==*Y) return 1;
}
return 0;
}

int indexcell(int A[],int K,int *X){
int i,Ai,Xi;
for (i=0;i<K;i=i+1){
  Xi=&*X;
  Ai=&A[i];
  if (Xi==Ai) return i;
 }
return -1;
}

int indexvalue(int A[],int K,int *X){
int i;
for (i=0;i<K;i=i+1){
  if (*X==A[i]) return i;
 }
return -1;
}



HW 12

file irotate.h:

void irotate(int **,int **, int **);

file irotate.c:

#include "irotate.h"
void irotate(int **a,int **b,int **c){
int temp;
temp=**a;
**a=**b;
**b=**c;
**c=temp
}



HW 13

file Isitsame:

#include <string.h>
int Isitsame(const char *, const char *);

int Isitsame(const char * A, const char * B){
int i;
char Az[1000];
char Bz[1000];
strcpy(Az,A);
strcpy(Bz,B);

i=0;
while (Az[i]!=NULL){
 if (96<Az[i] && Az[i]<123) Az[i]=Az[i]-32;
 i=i+1;
 }

i=0;
while (Bz[i]!=NULL){
 if (96<Bz[i] && Bz[i]<123) Bz[i]=Bz[i]-32;
 i=i+1;
 }
i=0;
while (Az[i]!=NULL){
 if (Az[i] != Bz[i]) return(0);
 i=i+1;
 }
return(1);
}



HW 14
file display.c:

#include <stdio.h>
#include <string.h>
main (int argc,char *argv[]){
int X=0,i=0,j=0;
char a;

X=atoi(argv[1]);

while (fscanf(stdin,"%c",&a)!=EOF){
i=i+1;
if (i<=X ) fprintf(stdout,"%c",a);

if (i>X) {
  if(a > 32) fprintf(stdout,"%c",a);

  if(a < 33) {
    fprintf(stdout,"\n");
    i=0;
   }
 }
if (a==10) i=0;
}
exit (0);
}



HW 15


HW 16


HW 17


HW 18 (toteach nor ready yet)
exprec.c:

int exprec(int a,int b){
if (a<0) return 0;
if (b<0) return 0;
if (a==0 && b==0) return 0;
if (b==0) return 1;
if (b==1) return a;
return a*exprec(a,b-1);
}