₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,346 members, 8,421,452 topics. Date: Saturday, 06 June 2026 at 12:51 PM

Toggle theme

Chukxy's Posts

Nairaland ForumChukxy's ProfileChukxy's Posts

1 2 3 4 5 (of 5 pages)

ProgrammingRe: Please Assist Me In This C Code Challenge! by chukxy(op): 12:40pm On Mar 21, 2010
Please C professionals in the house, assist me as it is urgent!
ProgrammingPlease Assist Me In This C Code Challenge! by chukxy(op): 11:20am On Mar 21, 2010
The code below is meant to calculate the magnitude and phase of the impedance of a series C-R circuit. It calculates the result over a range of frequencies, stores them in two arrays of results and then uses a two dimensional array of characters to plot a simple graph using characters on the terminal screen. This is primarily an exercise in using arrays and the program is portable, so it could be re-compiled with almost any c compiler for almost operating system. Although it would be possible to produce a much more sophisticated graph using Windows graphics, this would make the program non-portable to any other operating system.

The program should prompt the user for two frequencies instead of one. These are the start frequency and stop frequency. It should then prompt the user for the resistance(ohms), the capacitance(farads) and the inductance(henrys) and do the calculation and plot the graph.

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>

#define PI 3.1415926538979323846
#define WIDE 40
#define HIGH 20
/* This program is written by chuxy, It gets values from the user and stores them in variables*/
/* The program also calculates the magnitude of impedance and phase angle of impedance */

/* declaration of prototype functions */

void input_vals(double *Lval,double *Cval,double *Rval,double *Fval,double *Fval2);
double calc_Xc(double *Cval,double *Fval);
double calc_Xl(double *Lval,double *Fval);
double calc_ZMag(double *Rval,double *Xc,double *Xl);
double calc_ZAngle(double *Rval,double *Xc,double *Xl);
void print_results(double *Zmag,double *Zphase);
void swap(double *p,double *p1);
void find_max_val(double Zmag1[],double Zphase1[]);
void initialize_graph_array(double Zmag[],double Zphase1[],char symbol_4_Zmag[HIGH][WIDE],char symbol_4_Zphase[HIGH][WIDE]);
void print_graph(char symbol_4_Zmag[HIGH][WIDE],char symbol_4_Zphase[HIGH][WIDE]);

int main(void)
{

double L1,C1,F1,F2,R1,Xc1[40],Xl1[40],Zmag1[40],Zphase1[40],Frq[40]; /* declaration main function variables */
char symbol_4_Zmag[HIGH][WIDE],symbol_4_Zphase[HIGH][WIDE]; /* declaration of variables for graph array */
int c1,c2,c3; //declaration of counters for for loops
int cnt=0;
int freq_scale_fact=0;

input_vals(&L1,&C1,&R1,&F1,&F2);

freq_scale_fact=(F2-F1)/40; //initializes the scalefactor


for(cnt=0;cnt<40;cnt++) //initializes the array of frequencies using scale factor
{
Frq[cnt]=F1+freq_scale_fact*cnt;
}


for(c1=0;c1<40;c1++) //calculates the the inductive reactance and capacitive reactance
{

Xc1[c1]=calc_Xc(&C1,&Frq[c1]);

Xl1[c1]=calc_Xl(&L1,&Frq[c1]);
}

for(c2=0;c2<40;c2++) //calculates the magnatitude and angle of impeadance and storethe value in array
{
Zmag1[c2]=calc_ZMag(&R1,&Xc1[c2],&Xl1[c2]);

Zphase1[c2]=calc_ZAngle(&R1,&Xc1[c2],&Xl1[c2]);
}


for(c3=0;c3<40;c3++) //prints the results of the arrays
{
print_results(&Zmag1[c3],&Zphase1[c3]);
}
/* the sorts the array of result */

find_max_val(Zmag1,Zphase1);

initialize_graph_array(Zmag1,Zphase1,symbol_4_Zmag,symbol_4_Zphase);
print_graph(symbol_4_Zmag,symbol_4_Zphase);
_getche();

return 0;

}

void input_vals(double *Lval,double *Cval,double *Rval,double *Fval,double *Fval2)
{
double L1,C1,R1,F1,F2;
printf("\n Please enter the value of the inductor \n"wink;
scanf("%lf",&L1);
while(L1<0)
{
printf("\n Please enter a valid value \n"wink;

}
*Lval=L1;

printf("\n Please enter the value of the capacitor \n"wink;
scanf("%lf",&C1);
while(C1<0)
{
printf("\n Please enter a valid value \n"wink;

}
*Cval=C1;

printf("\n Please enter the value of the resistor \n"wink;
scanf("%lf",&R1);
while(R1<0)
{
printf("\n Please enter a valid value \n"wink;

}

*Rval=R1;


printf("\n Please enter the value of the frequency \n"wink;
scanf("%lf",&F1);
while(F1<0)
{
printf("\n Please enter a valid value \n"wink;

}
*Fval=F1;

printf("\n Please enter the value of the second frequency \n"wink;
scanf("%lf",&F2);
while(F1<0)
{
printf("\n Please enter a valid value \n"wink;

}
*Fval2=F2;
}

double calc_Xc(double *Cval,double *Fval)
{
double F1a,C1a,Xc;
C1a=*Cval;
F1a=*Fval;
Xc=1/(2*PI*F1a*C1a);
return Xc;
}

double calc_Xl(double *Lval,double *Fval)
{
double L1a,F1a,Xl;
L1a = *Lval;
F1a= *Fval;

Xl=2*PI*L1a*F1a;
return Xl;

}

double calc_ZMag(double *Rval,double *Xc,double *Xl)
{
double Zmag,R1,Xc1,Xl1;
R1=*Rval;
Xc1=*Xc;
Xl1=*Xl;

Zmag=sqrt(((Xl1-Xc1)*(Xl1-Xc1))+(R1*R1));
return Zmag;

}

double calc_ZAngle(double *Rval,double *Xc,double *Xl)
{
double Zphase,R1b,Xc2,Xl2,ZphaseA;
R1b=*Rval;
Xc2=*Xc;
Xl2=*Xl;

Zphase=atan((Xl2-Xc2)/R1b);
ZphaseA=(Zphase*180)/PI;
return ZphaseA;

}

void print_results(double *Zmag,double *Zphase)
{
printf("\n Zmagnitude = %lf ohms, Zphase = %lf degrees \n",*Zmag,*Zphase);

}

void swap(double *p,double *p1)
{
double tmt;
tmt=*p;
*p=*p1;
*p1=tmt;
}
void find_max_val(double Zmag1[],double Zphase1[])
{
int c4,c5;
for(c4=0;c4<39;++c4)
for(c5=39;c5>c4;--c5)
{
if(Zmag1[c5-1]>Zmag1[c5])
swap(&Zmag1[c5-1],&Zmag1[c5]);

if(Zphase1[c5-1]>Zphase1[c5])
swap(&Zphase1[c5-1],&Zphase1[c5]);
}
printf("\n\n\n The maximum impeadance and its angle after sorting is:\n\n\n"wink;
printf("\n Zmagnitude = %lf ohms, Zphase = %lf degrees \n",Zmag1[39],Zphase1[0]);


}
void initialize_graph_array(double Zmag[],double Zphase1[],char symbol_4_Zmag[HIGH][WIDE],char symbol_4_Zphase[HIGH][WIDE])
{
int cnt1, cnt2;

int scale_star[40],scale_cross[40],cnt3;
for(cnt3=0;cnt3<40;cnt3++)
{
scale_star[cnt3]=((Zmag[cnt3]/Zmag[39])*20);
scale_cross[cnt3]=(((Zphase1[cnt3]+90)/180)*20);
}
for(cnt1=0;cnt1<HIGH;cnt1++)
for(cnt2=0;cnt2<WIDE;cnt2++)
{
symbol_4_Zmag[(scale_star[cnt1])][cnt2]='*';
symbol_4_Zphase[(scale_cross[cnt1])][cnt2]='+';
}

}
void print_graph(char symbol_4_Zmag[HIGH][WIDE],char symbol_4_Zphase[HIGH][WIDE])
{
int cnt1,cnt2;
for(cnt1=0;cnt1<HIGH;cnt1++)
for(cnt2=0;cnt2<WIDE;cnt2++)
{
printf("%c",symbol_4_Zmag[cnt1][cnt2]);
printf("%c",symbol_4_Zphase[cnt1][cnt2]);
printf("\n"wink;
}
}

My current challenge in this code is that when the function to print graph is invoked, it prints disarray of characters that i did not even specify in the program. Please assist me to retify the challenge.

Thanks in anticipation.
ProgrammingRe: Abeg Guys What Is Wrong With This C Code by chukxy: 9:35am On Mar 09, 2010
@Movingcoil! How are you doing? It has been a long time I heard from you.
I would want us to be sharing our experiences in C language as i am also new in C. By so doing, we get to learn more and faster. Hope to hear from you soon.
ProgrammingRe: Abeg Guys What Is Wrong With This C Code by chukxy: 4:14pm On Feb 24, 2010
@ poster. If you have not got the solution before now, here is the corrected code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

/*string variable declaration*/
char usrname[], pass[];
char *name = "dikachi";
char *passr = "xerone";

/*variable and constant declaration*/
int rad;
const float pie = 3.142;

/*function declaration*/
int area(void);

/*main function statement*/
int main(int argc, char *argv[])
{
printf("enter the username and password to calculate the area of a circle\n"wink;
scanf("%s", usrname);
scanf("%s", pass);

/*control statement*/
if((strcmp(name,usrname)==0)&&(strcmp(passr,pass)==0)){
//if((name == usrname) && (passr == pass))
printf("the area of the circle is:%d\n ", area ());/*calling the function area*/
}
else
{
printf("ACCESS DENIED"wink;
}

system("PAUSE"wink;
return 0;
}

/*function definition*/
int area(void)
{
printf("what is the value of the radius!"wink;
scanf("%d", &rad);
return(pie * pow(rad, 2));
}


Please go through it carefully and learn where you made mistakes. Cheers!!
ProgrammingRe: So You Wanna Be A Programmer! by chukxy: 11:08am On Feb 21, 2010
Thank you guys! My interest is rekindled again. You people are too much!
ProgrammingRe: So You Wanna Be A Programmer! by chukxy: 8:59pm On Feb 20, 2010
Thanks Dueal! I appreciate.
ProgrammingRe: So You Wanna Be A Programmer! by chukxy: 4:27pm On Feb 20, 2010
@dueal. Thanks for the clarification. I also want you to give me more insight on why one should make c the first choice among other languages in terms of hardware programming.
ProgrammingRe: So You Wanna Be A Programmer! by chukxy: 11:46am On Feb 20, 2010
Good people, please I want to know why hardware programmers make C programming language as their first choice. This is because, i am currently studying digital systems and computer engineering; hence we are studying c as part of our course. What i have learnt so far about C, there is no much different with java(which i have known before now) except that it is a structured language while java is object oriented language.

Before now, my opinion about c is that it is a low level language associated with machine codes(0s and 1s) which makes it more efficient to program hardwares with it, but what we have done so far, I am yet to see that.

C professionals in the house please educate me on the capabilities of C so that I will regain my interest in it.

Thanks in anticipation!
ProgrammingRe: Scjp Exam In Nigeria by chukxy: 11:35pm On Jan 21, 2010
yes, send me your email add for me to send the one i used then, though i don't know if is out of date now.
ProgrammingRe: Scjp Exam In Nigeria by chukxy: 10:13am On Jan 20, 2010
@poster, happy to note that you are about taken a very challenging exam. In short i am very pleased with your decision . However, my experience about the exam when I took it at NIIT kaduna in 2006, you must in addition to what you have studied so far concerning the course go through Scjp dumps for you to be fully prepared. One more caution, getting the certification is not a guarantee to great achievement in IT. What matters most is the skills you have gathered through rigoruos training and personal development. With your skill, you can on your own do one unique project that will open doors or catapult you to lime light. Once you have built your potofolio through this project and can deliver, they would not even ask you of your certification.

Once again, I wish you best of luck.
Certification And Training AdvertsRe: Ccna For 65k! Did I Get A Fair Bargain? by chukxy: 9:01am On Nov 24, 2009
@Poster, to my humble opinion is not wort it as you did not get a fair bargain. One thing i know about IT from my experience with NIIT and other IT institute, you can only have the basis there, then develop yourself afterwards. You can always learn on your own if actually want to get the skill you want. Wishing good luck!
SportsRe: WCQ: Kenya vs Nigeria - (2-3) by chukxy: 6:14pm On Nov 13, 2009
Good people, I want to know if Nigeria wins their match and Tunisia draws their match, What will be the fate of Nigeria.?
ProgrammingAnother Challenge For Java Gurus by chukxy(op): 7:19am On Aug 28, 2008
I have developed some applications in java. My challenge is to set this application on the desktop
so that by just clicking on the icon on the desktop, the application would run, instead of the usual
java classname on the command prompt to run the application. Your suggestions are welcomed. Thank you in advance.
ProgrammingRe: Guru In The House, Please Help Me by chukxy(op): 7:57am On Jul 04, 2008
My good people, I'm so much pleased with your suggestions.
The problem i have now is to package the application in a jar file.
Please direct me on how to package the application.

Thank you.
ProgrammingRe: Guru In The House, Please Help Me by chukxy(op): 7:15am On Jul 03, 2008
It is meant to be a desktop application.
ProgrammingGuru In The House, Please Help Me by chukxy(op): 6:16pm On Jul 02, 2008
I developed an inventory application using microsoft access as my data base(Java based).
My problem now is to transfer this application to different users using different systems.
Do I need to creat data base in any system i want to transfer the application for its subsequent use
or is there any better way to do it?
Suggestions are welcomed.

Thank you.
Tech JobsRe: Computer Science Final Year Project by chukxy: 7:59am On Jun 26, 2008
How about developing an automated Admission process for post graduate studies.
If need help in doing this don't hesitate to contact me.
My email is chukxy2004@yahoo.com or +234 08035484239
ProgrammingRe: Can Not Run My Applet In A Web Browser by chukxy(op): 7:49am On Jun 25, 2008
Thank you very much for the suggestions so far.
The truth is that I can not run the programmer after implementing the suggestions.
Please is there anything i can do to the browser in terms of configurationb to enable me
run the applet. thanks.
ProgrammingCan Not Run My Applet In A Web Browser by chukxy(op): 7:59am On Jun 23, 2008
Please c an somebody in the house help me? I'm having problem running my applet in a browser.
Can only run it with appletviewer. Suggestions will be welcomed.
Thank you.
ProgrammingRe: Java Prog That Converts Binary To Decimal by chukxy: 5:24pm On Jan 24, 2008
If you had compiled this program before now, it must have displayed error during compilation due to mistake in line 7; but i have just corrected th error. So you can go on compile and run the program.

Thanks.

pally, just like i promised yesterday, here is the solution to the problem:

class BinaryDec
{
public static void main(String arg[])
{
String binaryno = arg[0];
int decno;
decno= Integer.parseInt(binaryno,2);
System.out.println(''The Decimal equivalent =''+decno);
}
}

compile, javac BinaryDec.com
run java BinaryDec 1101

the ans will be 13.

Thanks and stay connected.
[/color][color=#990000][/color][color=#990000]
ProgrammingRe: Programmer Mentor by chukxy: 5:15pm On Jan 18, 2008
Pally, I will be at your disposal for all you need to be a guru.As a matter of fact, I have a working knowledge of javascript,
html,and java. I'm sun certified java programmer. So you can contact me with this no:+234 08035484239 or my email chukxy2004@yahoo.com
Looking forward hearing from you.
ProgrammingRe: Java Prog That Converts Binary To Decimal by chukxy: 5:00pm On Jan 18, 2008
pally, just like i promised yesterday, here is the solution to the problem:

class BinaryDec
{
public static void main(String arg[])
{
String binaryno = arg[0];
int decno;
decno= Integer.parseInt(binary,2);
System.out.println(''The Decimal equivalent =''+decno);
}
}

compile, javac BinaryDec.com
run java BinaryDec 1101

the ans will be 13.

Thanks and stay connected.
ProgrammingRe: Java Prog That Converts Binary To Decimal by chukxy: 6:03pm On Jan 17, 2008
hi guy, I just read your post.
I promise to give you the solution morrow.
Stay connected.
Tnx.

1 2 3 4 5 (of 5 pages)